Skip to content

Commit a325396

Browse files
committed
new send-message actions
1 parent 867f268 commit a325396

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export default {
170170
},
171171
};
172172
},
173+
getChannelId() {
174+
return this.conversation ?? this.reply_channel;
175+
},
173176
},
174177
async run({ $ }) {
175178
let blocks = this.blocks;
@@ -207,7 +210,7 @@ export default {
207210

208211
const obj = {
209212
text: this.text,
210-
channel: this.conversation ?? this.reply_channel,
213+
channel: await this.getChannelId(),
211214
attachments: this.attachments,
212215
unfurl_links: this.unfurl_links,
213216
unfurl_media: this.unfurl_media,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import common from "../common/send-message.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
...common,
6+
key: "slack-send-message-to-channel",
7+
name: "Send Message to Channel",
8+
description: "Send a message to a public or private channel. [See the documentation](https://api.slack.com/methods/chat.postMessage)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
slack: common.props.slack,
13+
conversation: {
14+
propDefinition: [
15+
common.props.slack,
16+
"conversation",
17+
() => ({
18+
types: [
19+
constants.CHANNEL_TYPE.PUBLIC,
20+
constants.CHANNEL_TYPE.PRIVATE,
21+
],
22+
}),
23+
],
24+
description: "Select a public or private channel",
25+
},
26+
text: {
27+
propDefinition: [
28+
common.props.slack,
29+
"text",
30+
],
31+
},
32+
mrkdwn: {
33+
propDefinition: [
34+
common.props.slack,
35+
"mrkdwn",
36+
],
37+
},
38+
...common.props,
39+
},
40+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import common from "../common/send-message.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
4+
5+
export default {
6+
...common,
7+
key: "slack-send-message-to-user-or-group",
8+
name: "Send Message to User or Group",
9+
description: "Send a message to a user or group. [See the documentation](https://api.slack.com/methods/chat.postMessage)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
slack: common.props.slack,
14+
users: {
15+
propDefinition: [
16+
common.props.slack,
17+
"user",
18+
],
19+
type: "string[]",
20+
label: "Users",
21+
description: "Select the user(s) to message",
22+
optional: true,
23+
},
24+
conversation: {
25+
propDefinition: [
26+
common.props.slack,
27+
"conversation",
28+
() => ({
29+
types: [
30+
constants.CHANNEL_TYPE.MPIM,
31+
],
32+
}),
33+
],
34+
description: "Select the group to message",
35+
optional: true,
36+
},
37+
text: {
38+
propDefinition: [
39+
common.props.slack,
40+
"text",
41+
],
42+
},
43+
mrkdwn: {
44+
propDefinition: [
45+
common.props.slack,
46+
"mrkdwn",
47+
],
48+
},
49+
...common.props,
50+
},
51+
methods: {
52+
...common.methods,
53+
openConversation(args = {}) {
54+
return this.slack.makeRequest({
55+
method: "conversations.open",
56+
...args,
57+
});
58+
},
59+
async getChannelId() {
60+
if (!this.conversation && !this.users?.length) {
61+
throw new ConfigurationError("Must select a group or user(s) to message");
62+
}
63+
64+
if (this.conversation) {
65+
return this.conversation;
66+
}
67+
const { channel: { id } } = await this.openConversation({
68+
users: this.users.join(),
69+
});
70+
return id;
71+
},
72+
},
73+
};

components/slack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/slack",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Pipedream Slack Components",
55
"main": "slack.app.mjs",
66
"keywords": [

components/slack/slack.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default {
119119
}
120120
}
121121
const [
122-
userNames,
122+
userNames = await this.userNames(),
123123
conversationsResp,
124124
] = await Promise.all([
125125
userNamesOrPromise,

0 commit comments

Comments
 (0)