@pipedream/slack 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/actions/add-star/add-star.mjs +43 -0
  2. package/actions/archive-channel/archive-channel.mjs +23 -0
  3. package/actions/common/send-message.mjs +170 -0
  4. package/actions/complete-reminder/complete-reminder.mjs +23 -0
  5. package/actions/create-channel/create-channel.mjs +30 -0
  6. package/actions/create-reminder/create-reminder.mjs +47 -0
  7. package/actions/delete-file/delete-file.mjs +23 -0
  8. package/actions/delete-message/delete-message.mjs +38 -0
  9. package/actions/delete_reminder/delete-reminder.mjs +23 -0
  10. package/actions/find-message/find-message.mjs +38 -0
  11. package/actions/find-user-by-email/find-user-by-email.mjs +23 -0
  12. package/actions/get-channel/get-channel.mjs +23 -0
  13. package/actions/get-file/get-file.mjs +30 -0
  14. package/actions/get-reminder/get-reminder.mjs +23 -0
  15. package/actions/invite-user-to-channel/invite-user-to-channel.mjs +31 -0
  16. package/actions/join-channel/join-channel.mjs +23 -0
  17. package/actions/kick-user/kick-user.mjs +30 -0
  18. package/actions/leave-channel/leave-channel.mjs +23 -0
  19. package/actions/list-channels/list-channels.mjs +15 -0
  20. package/actions/list-files/list-files.mjs +47 -0
  21. package/actions/list-members-in-channel/list-members-in-channel.mjs +23 -0
  22. package/actions/list-reminders/list-reminders.mjs +24 -0
  23. package/actions/list-replies/list-replies.mjs +30 -0
  24. package/actions/list-users/list-users.mjs +22 -0
  25. package/actions/remove-star/remove-star.mjs +40 -0
  26. package/actions/reply-to-a-message-thread/reply-to-a-message-thread.mjs +41 -0
  27. package/actions/send-block-kit-message/send-block-kit-message.mjs +33 -0
  28. package/actions/send-custom-message/send-custom-message.mjs +79 -0
  29. package/actions/send-direct-message/send-direct-message.mjs +52 -0
  30. package/actions/send-group-message/send-group-message.mjs +52 -0
  31. package/actions/send-large-message/send-large-message.mjs +91 -0
  32. package/actions/send-message-private-channel/send-message-private-channel.mjs +52 -0
  33. package/actions/send-message-public-channel/send-message-public-channel.mjs +52 -0
  34. package/actions/set-channel-topic/set-channel-topic.mjs +30 -0
  35. package/actions/set-purpose-of-channel/set-purpose-of-channel.mjs +30 -0
  36. package/actions/unarchive-channel/unarchive-channel.mjs +23 -0
  37. package/actions/update-message/update-message.mjs +52 -0
  38. package/actions/update-profile/update-profile.mjs +30 -0
  39. package/actions/upload-file/upload-file.mjs +38 -0
  40. package/package.json +19 -16
  41. package/slack.app.mjs +544 -0
  42. package/sources/common/base.mjs +97 -0
  43. package/sources/common/constants.mjs +30 -0
  44. package/sources/new-direct-message/new-direct-message.mjs +51 -0
  45. package/sources/new-mention/new-mention.mjs +95 -0
  46. package/sources/new-message-in-channels/new-message-in-channels.mjs +84 -0
  47. package/sources/new-reaction-added/new-reaction-added.mjs +65 -0
  48. package/sources/new-star-added/new-star-added.mjs +46 -0
  49. package/slack.app.js +0 -48
  50. package/sources/new-message-in-channels/new-message-in-channels.js +0 -151
@@ -0,0 +1,51 @@
1
+ import common from "../common/base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "slack-new-direct-message",
6
+ name: "New Direct Message (Instant)",
7
+ version: "1.0.1",
8
+ description: "Emit new event when a message was posted in a direct message channel",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ // eslint-disable-next-line pipedream/props-description,pipedream/props-label
14
+ slackApphook: {
15
+ type: "$.interface.apphook",
16
+ appProp: "slack",
17
+ async eventNames() {
18
+ return [
19
+ "message.im",
20
+ ];
21
+ },
22
+ },
23
+ ignoreMyself: {
24
+ propDefinition: [
25
+ common.props.slack,
26
+ "ignoreMyself",
27
+ ],
28
+ },
29
+ ignoreBot: {
30
+ propDefinition: [
31
+ common.props.slack,
32
+ "ignoreBot",
33
+ ],
34
+ },
35
+ },
36
+ methods: {
37
+ ...common.methods,
38
+ getSummary() {
39
+ return "New direct message received";
40
+ },
41
+ processEvent(event) {
42
+ if (this.ignoreMyself && event.user == this.slack.mySlackId()) {
43
+ return;
44
+ }
45
+ if ((this.ignoreBot) && (event.subtype == "bot_message" || event.bot_id)) {
46
+ return;
47
+ }
48
+ return event;
49
+ },
50
+ },
51
+ };
@@ -0,0 +1,95 @@
1
+ import common from "../common/base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "slack-new-mention",
6
+ name: "New Mention (Instant)",
7
+ version: "1.0.1",
8
+ description: "Emit new event when a username or specific keyword is mentioned in a channel",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ conversations: {
14
+ propDefinition: [
15
+ common.props.slack,
16
+ "conversation",
17
+ ],
18
+ type: "string[]",
19
+ label: "Channels",
20
+ description: "Select one or more channels to monitor for new messages.",
21
+ optional: true,
22
+ },
23
+ // eslint-disable-next-line pipedream/props-description,pipedream/props-label
24
+ slackApphook: {
25
+ type: "$.interface.apphook",
26
+ appProp: "slack",
27
+ async eventNames() {
28
+ return this.conversations || [
29
+ "message",
30
+ ];
31
+ },
32
+ },
33
+ keyword: {
34
+ propDefinition: [
35
+ common.props.slack,
36
+ "keyword",
37
+ ],
38
+ },
39
+ isUsername: {
40
+ propDefinition: [
41
+ common.props.slack,
42
+ "isUsername",
43
+ ],
44
+ },
45
+ ignoreBot: {
46
+ propDefinition: [
47
+ common.props.slack,
48
+ "ignoreBot",
49
+ ],
50
+ },
51
+ },
52
+ methods: {
53
+ ...common.methods,
54
+ getSummary() {
55
+ return "New mention received";
56
+ },
57
+ async processEvent(event) {
58
+ if (event.type !== "message") {
59
+ console.log(`Ignoring event with unexpected type "${event.type}"`);
60
+ return;
61
+ }
62
+ if (event.subtype != null && event.subtype != "bot_message" && event.subtype != "file_share") {
63
+ // This source is designed to just emit an event for each new message received.
64
+ // Due to inconsistencies with the shape of message_changed and message_deleted
65
+ // events, we are ignoring them for now. If you want to handle these types of
66
+ // events, feel free to change this code!!
67
+ console.log("Ignoring message with subtype.");
68
+ return;
69
+ }
70
+ if ((this.ignoreBot) && (event.subtype == "bot_message" || event.bot_id)) {
71
+ return;
72
+ }
73
+ let emitEvent = false;
74
+ const elements = event.blocks[0]?.elements[0]?.elements;
75
+
76
+ if (this.isUsername && elements) {
77
+ for (const item of elements) {
78
+ if (item.user_id) {
79
+ const username = await this.getUserName(item.user_id);
80
+ if (username === this.word) {
81
+ emitEvent = true;
82
+ break;
83
+ }
84
+ }
85
+ }
86
+
87
+ } else if (event.text.indexOf(this.word) !== -1) {
88
+ emitEvent = true;
89
+ }
90
+ if (emitEvent) {
91
+ return event;
92
+ }
93
+ },
94
+ },
95
+ };
@@ -0,0 +1,84 @@
1
+ import common from "../common/base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "slack-new-message-in-channels",
6
+ name: "New Message In Channels (Instant)",
7
+ version: "1.0.1",
8
+ description: "Emit new event when a new message is posted to one or more channels",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ conversations: {
14
+ propDefinition: [
15
+ common.props.slack,
16
+ "conversation",
17
+ ],
18
+ type: "string[]",
19
+ label: "Channels",
20
+ description: "Select one or more channels to monitor for new messages.",
21
+ optional: true,
22
+ },
23
+ // eslint-disable-next-line pipedream/props-description,pipedream/props-label
24
+ slackApphook: {
25
+ type: "$.interface.apphook",
26
+ appProp: "slack",
27
+ async eventNames() {
28
+ return this.conversations || [
29
+ "message",
30
+ ];
31
+ },
32
+ },
33
+ resolveNames: {
34
+ propDefinition: [
35
+ common.props.slack,
36
+ "resolveNames",
37
+ ],
38
+ },
39
+ ignoreBot: {
40
+ propDefinition: [
41
+ common.props.slack,
42
+ "ignoreBot",
43
+ ],
44
+ },
45
+ },
46
+ methods: {
47
+ ...common.methods,
48
+ getSummary() {
49
+ return "New message in channel";
50
+ },
51
+ async processEvent(event) {
52
+ if (event.type !== "message") {
53
+ console.log(`Ignoring event with unexpected type "${event.type}"`);
54
+ return;
55
+ }
56
+ if (event.subtype != null && event.subtype != "bot_message" && event.subtype != "file_share") {
57
+ // This source is designed to just emit an event for each new message received.
58
+ // Due to inconsistencies with the shape of message_changed and message_deleted
59
+ // events, we are ignoring them for now. If you want to handle these types of
60
+ // events, feel free to change this code!!
61
+ console.log("Ignoring message with subtype.");
62
+ return;
63
+ }
64
+ if ((this.ignoreBot) && (event.subtype == "bot_message" || event.bot_id)) {
65
+ return;
66
+ }
67
+ if (this.resolveNames) {
68
+ if (event.user) {
69
+ event.user_id = event.user;
70
+ event.user = await this.getUserName(event.user);
71
+ } else if (event.bot_id) {
72
+ event.bot = await this.getBotName(event.bot_id);
73
+ }
74
+ event.channel_id = event.channel;
75
+ event.channel = await this.getConversationName(event.channel);
76
+ if (event.team) {
77
+ event.team_id = event.team;
78
+ event.team = await this.getTeamName(event.team);
79
+ }
80
+ }
81
+ return event;
82
+ },
83
+ },
84
+ };
@@ -0,0 +1,65 @@
1
+ import common from "../common/base.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "slack-new-reaction-added",
6
+ name: "New Reaction Added (Instant)",
7
+ version: "1.1.1",
8
+ description: "Emit new event when a member has added an emoji reaction to an item",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ conversations: {
14
+ propDefinition: [
15
+ common.props.slack,
16
+ "conversation",
17
+ ],
18
+ type: "string[]",
19
+ label: "Channels",
20
+ description: "Select one or more channels to monitor for new messages.",
21
+ optional: true,
22
+ },
23
+ // eslint-disable-next-line pipedream/props-description,pipedream/props-label
24
+ slackApphook: {
25
+ type: "$.interface.apphook",
26
+ appProp: "slack",
27
+ async eventNames() {
28
+ if (this.conversations.length) {
29
+ const conversations = [];
30
+ for (const conversation of this.conversations) {
31
+ conversations.push(`reaction_added:${conversation}`);
32
+ }
33
+ return conversations;
34
+ }
35
+
36
+ return [
37
+ "reaction_added",
38
+ ];
39
+ },
40
+ },
41
+ ignoreBot: {
42
+ propDefinition: [
43
+ common.props.slack,
44
+ "ignoreBot",
45
+ ],
46
+ },
47
+ },
48
+ methods: {
49
+ ...common.methods,
50
+ getSummary() {
51
+ return "New reaction added";
52
+ },
53
+ async processEvent(event) {
54
+ if ((this.ignoreBot) && (event.subtype == "bot_message" || event.bot_id)) {
55
+ return;
56
+ }
57
+ event.message = await this.getLastMessage({
58
+ channel: event.item.channel,
59
+ event_ts: event.item.ts,
60
+ });
61
+
62
+ return event;
63
+ },
64
+ },
65
+ };
@@ -0,0 +1,46 @@
1
+ import common from "../common/base.mjs";
2
+ import {
3
+ events,
4
+ eventsOptions,
5
+ } from "../common/constants.mjs";
6
+
7
+ export default {
8
+ ...common,
9
+ key: "slack-new-star-added",
10
+ name: "New Star Added (Instant)",
11
+ version: "0.0.4",
12
+ description: "Emit new event when a star is added to an item",
13
+ type: "source",
14
+ dedupe: "unique",
15
+ props: {
16
+ ...common.props,
17
+ // eslint-disable-next-line pipedream/props-description,pipedream/props-label
18
+ slackApphook: {
19
+ type: "$.interface.apphook",
20
+ appProp: "slack",
21
+ async eventNames() {
22
+ return [
23
+ "star_added",
24
+ ];
25
+ },
26
+ },
27
+ eventTypes: {
28
+ type: "string[]",
29
+ label: "Event Types",
30
+ description: "The types of event to emit. If not specified, all events will be emitted.",
31
+ options: eventsOptions,
32
+ optional: true,
33
+ },
34
+ },
35
+ methods: {
36
+ ...common.methods,
37
+ getSummary({ item: { type } }) {
38
+ return `New star added - ${events[type] ?? type}`;
39
+ },
40
+ async processEvent(event) {
41
+ if (this.eventTypes?.length === 0 || this.eventTypes.includes(event.item.type)) {
42
+ return event;
43
+ }
44
+ },
45
+ },
46
+ };
package/slack.app.js DELETED
@@ -1,48 +0,0 @@
1
- const { WebClient } = require('@slack/web-api')
2
-
3
- module.exports = {
4
- type: "app",
5
- app: "slack",
6
- methods: {
7
- mySlackId() {
8
- return this.$auth.oauth_uid
9
- },
10
- sdk() {
11
- return new WebClient(this.$auth.oauth_access_token)
12
- },
13
- async scopes() {
14
- const resp = await this.sdk().auth.test()
15
- if (resp.ok) {
16
- return resp.response_metadata.scopes
17
- } else {
18
- console.log("Error getting scopes", resp.error)
19
- throw(resp.error)
20
- }
21
- },
22
- async availableConversations(types, cursor) {
23
- const params = {
24
- types,
25
- cursor,
26
- limit: 10,
27
- exclude_archived: true,
28
- user: this.$auth.oauth_uid,
29
- }
30
- const resp = await this.sdk().users.conversations(params)
31
- if (resp.ok) {
32
- return { cursor: resp.response_metadata.next_cursor, conversations: resp.channels }
33
- } else {
34
- console.log("Error getting conversations", resp.error)
35
- throw(resp.error)
36
- }
37
- },
38
- async users(cursor) {
39
- const resp = await this.sdk().users.list({ cursor })
40
- if (resp.ok) {
41
- return { users: resp.members, cursor: resp.response_metadata.next_cursor }
42
- } else {
43
- console.log("Error getting users", resp.error)
44
- throw(resp.error)
45
- }
46
- },
47
- },
48
- }
@@ -1,151 +0,0 @@
1
- const slack = require('../../slack.app.js')
2
-
3
- module.exports = {
4
- key: "slack-new-message-in-channels",
5
- name: "New Message In Channels",
6
- version: "0.0.1",
7
- description: "Emit an event when a new message is posted to a one or more channels",
8
- dedupe: "unique",
9
- props: {
10
- slack,
11
- conversations: {
12
- type: "string[]",
13
- label: "Channels",
14
- description: "Select one or more channels to monitor for new messages.",
15
- optional: true,
16
- async options({ prevContext }) {
17
- let { types, cursor, userNames } = prevContext
18
- if (types == null) {
19
- const scopes = await this.slack.scopes()
20
- types = ["public_channel"]
21
- if (scopes.includes("groups:read")) {
22
- types.push("private_channel")
23
- }
24
- if (scopes.includes("mpim:read")) {
25
- types.push("mpim")
26
- }
27
- if (scopes.includes("im:read")) {
28
- types.push("im")
29
- // TODO use paging
30
- userNames = {}
31
- for (const user of (await this.slack.users()).users) {
32
- userNames[user.id] = user.name
33
- }
34
- }
35
- }
36
- const resp = await this.slack.availableConversations(types.join(), cursor)
37
- return {
38
- options: resp.conversations.map((c) => {
39
- if (c.is_im) {
40
- return { label: `Direct messaging with: @${userNames[c.user]}`, value: c.id }
41
- } else if (c.is_mpim) {
42
- return { label: c.purpose.value, value: c.id }
43
- } else {
44
- return { label: `${c.is_private ? "Private" : "Public"} channel: ${c.name}`, value: c.id }
45
- }
46
- }),
47
- context: { types, cursor: resp.cursor, userNames },
48
- }
49
- },
50
- },
51
- slackApphook: {
52
- type: "$.interface.apphook",
53
- appProp: "slack",
54
- async eventNames() {
55
- return this.conversations || []
56
- },
57
- },
58
- ignoreMyself: {
59
- type: "boolean",
60
- label: "Ignore myself",
61
- description: "Ignore messages from me",
62
- default: true,
63
- },
64
- resolveNames: {
65
- type: "boolean",
66
- label: "Resolve names",
67
- description: "Resolve user and channel names (incurs extra API calls)",
68
- default: false,
69
- },
70
- nameCache: "$.service.db",
71
- },
72
- methods: {
73
- async maybeCached(key, refreshVal, timeoutMs = 3600000) {
74
- let record = this.nameCache.get(key)
75
- const time = Date.now()
76
- if (!record || time - record.ts > timeoutMs) {
77
- record = { ts: time, val: await refreshVal() }
78
- this.nameCache.set(key, record)
79
- }
80
- return record.val
81
- },
82
- async getBotName(id) {
83
- return this.maybeCached(`bots:${id}`, async () => {
84
- const info = await this.slack.sdk().bots.info({ bot: id })
85
- if (!info.ok) throw new Error(info.error)
86
- return info.bot.name
87
- })
88
- },
89
- async getUserName(id) {
90
- return this.maybeCached(`users:${id}`, async () => {
91
- const info = await this.slack.sdk().users.info({ user: id })
92
- if (!info.ok) throw new Error(info.error)
93
- return info.user.name
94
- })
95
- },
96
- async getConversationName(id) {
97
- return this.maybeCached(`conversations:${id}`, async () => {
98
- const info = await this.slack.sdk().conversations.info({ channel: id })
99
- if (!info.ok) throw new Error(info.error)
100
- if (info.channel.is_im) {
101
- return `DM with ${await this.getUserName(info.channel.user)}`
102
- } else {
103
- return info.channel.name
104
- }
105
- })
106
- },
107
- async getTeamName(id) {
108
- return this.maybeCached(`team:${id}`, async (info) => {
109
- try {
110
- const info = await this.slack.sdk().team.info({ team: id })
111
- return info.team.name
112
- } catch (err) {
113
- console.log("Error getting team name, probably need to re-connect the account at pipedream.com/apps", err)
114
- return id
115
- }
116
- })
117
- },
118
- },
119
- async run(event) {
120
- if (event.subtype != null && event.subtype != "bot_message") {
121
- // This source is designed to just emit an event for each new message received.
122
- // Due to inconsistencies with the shape of message_changed and message_deleted
123
- // events, we are ignoring them for now. If you want to handle these types of
124
- // events, feel free to change this code!!
125
- console.log("Ignoring message with subtype.")
126
- return
127
- }
128
- if (this.ignoreMyself && event.user == this.slack.mySlackId()) {
129
- return
130
- }
131
- if (this.resolveNames) {
132
- if (event.user) {
133
- event.user_id = event.user
134
- event.user = await this.getUserName(event.user)
135
- } else if (event.bot_id) {
136
- event.bot = await this.getBotName(event.bot_id)
137
- }
138
- event.channel_id = event.channel
139
- event.channel = await this.getConversationName(event.channel)
140
- if (event.team) {
141
- event.team_id = event.team
142
- event.team = await this.getTeamName(event.team)
143
- }
144
- }
145
- if (!event.client_msg_id) {
146
- event.pipedream_msg_id = `pd_${Date.now()}_${Math.random().toString(36).substr(2, 10)}`
147
- }
148
-
149
- this.$emit(event, { id: event.client_msg_id || event.pipedream_msg_id })
150
- },
151
- }