Skip to content

Commit e33e304

Browse files
Exports messages that were not delivered (#2394)
* exports messages that were not delivered * export non-modified user prop values * add common append pipedream text method * refactor only include attributes in params passed to methods Co-authored-by: js07
1 parent 0d25363 commit e33e304

File tree

4 files changed

+70
-56
lines changed

4 files changed

+70
-56
lines changed

components/discord_webhook/actions/send-message-advanced/send-message-advanced.mjs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "discord_webhook-send-message-advanced",
66
name: "Send Message (Advanced)",
77
description: "Send a simple or structured message (using embeds) to a Discord channel",
8-
version: "0.2.1",
8+
version: "0.3.0",
99
type: "action",
1010
props: {
1111
...common.props,
@@ -23,7 +23,7 @@ export default {
2323
],
2424
},
2525
},
26-
async run() {
26+
async run({ $ }) {
2727
const {
2828
message,
2929
avatarURL,
@@ -37,22 +37,22 @@ export default {
3737
throw new Error("This action requires at least 1 message OR embeds object. Please enter one or the other above.");
3838
}
3939

40-
let content = message ?? "";
41-
42-
if (includeSentViaPipedream) {
43-
if (typeof content !== "string") {
44-
content = JSON.stringify(content);
45-
}
46-
content += `\n\n${this.getSentViaPipedreamText()}`;
40+
try {
41+
// No interesting data is returned from Discord
42+
await this.discordWebhook.sendMessage({
43+
avatarURL,
44+
threadID,
45+
username,
46+
embeds,
47+
content: includeSentViaPipedream
48+
? this.appendPipedreamText(message ?? "")
49+
: message,
50+
});
51+
$.export("$summary", "Message sent successfully");
52+
} catch (err) {
53+
const unsentMessage = this.getUserInputProps();
54+
$.export("unsent", unsentMessage);
55+
throw err;
4756
}
48-
49-
// No interesting data is returned from Discord
50-
await this.discordWebhook.sendMessage({
51-
avatarURL,
52-
embeds,
53-
content,
54-
threadID,
55-
username,
56-
});
5757
},
5858
};

components/discord_webhook/actions/send-message-common.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ export default {
3939
},
4040
},
4141
methods: {
42+
getUserInputProps(omit = [
43+
"discordWebhook",
44+
]) {
45+
return Object.keys(this)
46+
.filter((k) => typeof this[k] !== "function" && !omit.includes(k))
47+
.reduce((props, key) => {
48+
props[key] = this[key];
49+
return props;
50+
}, {});
51+
},
52+
appendPipedreamText(message) {
53+
let content = message;
54+
if (typeof content !== "string") {
55+
content = JSON.stringify(content);
56+
}
57+
content += `\n\n${this.getSentViaPipedreamText()}`;
58+
return content;
59+
},
4260
getSentViaPipedreamText() {
4361
const workflowId = process.env.PIPEDREAM_WORKFLOW_ID;
4462
// The link text is a URL without a protocol for consistency with the "Send via link" text in

components/discord_webhook/actions/send-message-with-file/send-message-with-file.mjs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "discord_webhook-send-message-with-file",
88
name: "Send Message With File",
99
description: "Post a message with an attached file",
10-
version: "0.1.1",
10+
version: "0.2.0",
1111
type: "action",
1212
props: {
1313
...common.props,
@@ -48,8 +48,6 @@ export default {
4848
throw new Error("This action requires either File URL or File Path. Please enter one or the other above.");
4949
}
5050

51-
let content = message ?? "";
52-
5351
const file = fileUrl
5452
? (await axios({
5553
method: "get",
@@ -58,24 +56,22 @@ export default {
5856
})).data
5957
: fs.createReadStream(filePath);
6058

61-
if (includeSentViaPipedream) {
62-
if (typeof content !== "string") {
63-
content = JSON.stringify(content);
64-
}
65-
content += `\n\n${this.getSentViaPipedreamText()}`;
59+
try {
60+
// No interesting data is returned from Discord
61+
await this.discordWebhook.sendMessageWithFile({
62+
avatarURL,
63+
threadID,
64+
username,
65+
file,
66+
content: includeSentViaPipedream
67+
? this.appendPipedreamText(message ?? "")
68+
: message,
69+
});
70+
$.export("$summary", "Message sent successfully");
71+
} catch (err) {
72+
const unsentMessage = this.getUserInputProps();
73+
$.export("unsent", unsentMessage);
74+
throw err;
6675
}
67-
68-
// No interesting data is returned from Discord
69-
const resp = await this.discordWebhook.sendMessageWithFile({
70-
content,
71-
avatarURL,
72-
threadID,
73-
username,
74-
file,
75-
});
76-
77-
$.export("$summary", "Message sent successfully");
78-
79-
return resp;
8076
},
8177
};

components/discord_webhook/actions/send-message/send-message.mjs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export default {
55
key: "discord_webhook-send-message",
66
name: "Send Message",
77
description: "Send a simple message to a Discord channel",
8-
version: "0.2.1",
8+
version: "0.3.0",
99
type: "action",
1010
props: {
1111
...common.props,
1212
},
13-
async run() {
13+
async run({ $ }) {
1414
const {
1515
message,
1616
avatarURL,
@@ -19,21 +19,21 @@ export default {
1919
includeSentViaPipedream,
2020
} = this;
2121

22-
let content = message;
23-
24-
if (includeSentViaPipedream) {
25-
if (typeof content !== "string") {
26-
content = JSON.stringify(content);
27-
}
28-
content += `\n\n${this.getSentViaPipedreamText()}`;
22+
try {
23+
// No interesting data is returned from Discord
24+
await this.discordWebhook.sendMessage({
25+
avatarURL,
26+
threadID,
27+
username,
28+
content: includeSentViaPipedream
29+
? this.appendPipedreamText(message)
30+
: message,
31+
});
32+
$.export("$summary", "Message sent successfully");
33+
} catch (err) {
34+
const unsentMessage = this.getUserInputProps();
35+
$.export("unsent", unsentMessage);
36+
throw err;
2937
}
30-
31-
// No interesting data is returned from Discord
32-
await this.discordWebhook.sendMessage({
33-
avatarURL,
34-
content,
35-
threadID,
36-
username,
37-
});
3838
},
3939
};

0 commit comments

Comments
 (0)