@pipedream/slack 0.4.12 → 0.4.14

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.
@@ -0,0 +1,43 @@
1
+ import slack from "../../slack.app.mjs";
2
+
3
+ export default {
4
+ key: "slack-add-emoji-reaction",
5
+ name: "Add Emoji Reaction",
6
+ description: "Add an emoji reaction to a message. [See docs here](https://api.slack.com/methods/reactions.add)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ slack,
11
+ conversation: {
12
+ propDefinition: [
13
+ slack,
14
+ "conversation",
15
+ ],
16
+ optional: false,
17
+ description: "Channel to add reaction to, or channel where the message to add reaction to was posted (used with timestamp).",
18
+ },
19
+ timestamp: {
20
+ propDefinition: [
21
+ slack,
22
+ "timestamp",
23
+ ],
24
+ optional: false,
25
+ description: "Timestamp of the message to add reaction to.",
26
+ },
27
+ icon_emoji: {
28
+ propDefinition: [
29
+ slack,
30
+ "icon_emoji",
31
+ ],
32
+ description: "Provide an emoji to use as the icon for this reaction. E.g. `fire`",
33
+ optional: false,
34
+ },
35
+ },
36
+ async run() {
37
+ return await this.slack.sdk().reactions.add({
38
+ channel: this.conversation,
39
+ timestamp: this.timestamp,
40
+ name: this.icon_emoji,
41
+ });
42
+ },
43
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/slack",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "Pipedream Slack Components",
5
5
  "main": "slack.app.mjs",
6
6
  "keywords": [
package/slack.app.mjs CHANGED
@@ -340,6 +340,9 @@ export default {
340
340
  label: "Icon (emoji)",
341
341
  description: "Optionally provide an emoji to use as the icon for this message. E.g., `:fire:` Overrides `icon_url`. Must be used in conjunction with `as_user` set to `false`, otherwise ignored.",
342
342
  optional: true,
343
+ async options() {
344
+ return await this.getCustomEmojis()
345
+ }
343
346
  },
344
347
  content: {
345
348
  label: "File Path",
@@ -747,5 +750,10 @@ export default {
747
750
  ...args,
748
751
  });
749
752
  },
753
+ async getCustomEmojis(cursor) {
754
+ const resp = await this.sdk().emoji.list();
755
+
756
+ return Object.keys(resp.emoji)
757
+ },
750
758
  },
751
759
  };
@@ -24,7 +24,18 @@ const eventsOptions = [
24
24
  },
25
25
  ];
26
26
 
27
- export {
27
+ const SUBTYPE = {
28
+ NULL: null,
29
+ BOT_MESSAGE: "bot_message",
30
+ FILE_SHARE: "file_share",
31
+ PD_HISTORY_MESSAGE: "pd_history_message",
32
+ };
33
+
34
+ const ALLOWED_SUBTYPES = Object.values(SUBTYPE);
35
+
36
+ export default {
28
37
  events,
29
38
  eventsOptions,
39
+ SUBTYPE,
40
+ ALLOWED_SUBTYPES,
30
41
  };
@@ -1,10 +1,11 @@
1
1
  import common from "../common/base.mjs";
2
+ import constants from "../common/constants.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "slack-new-mention",
6
7
  name: "New Mention (Instant)",
7
- version: "1.0.7",
8
+ version: "1.0.9",
8
9
  description: "Emit new event when a username or specific keyword is mentioned in a channel",
9
10
  type: "source",
10
11
  dedupe: "unique",
@@ -70,7 +71,10 @@ export default {
70
71
  },
71
72
  async emitHistoricalEvents(messages) {
72
73
  for (const message of messages) {
73
- const event = await this.processEvent(message);
74
+ const event = await this.processEvent({
75
+ ...message,
76
+ subtype: message.subtype || constants.SUBTYPE.PD_HISTORY_MESSAGE,
77
+ });
74
78
  if (event) {
75
79
  if (!event.client_msg_id) {
76
80
  event.pipedream_msg_id = `pd_${Date.now()}_${Math.random().toString(36)
@@ -89,24 +93,40 @@ export default {
89
93
  return "New mention received";
90
94
  },
91
95
  async processEvent(event) {
92
- if (event.type !== "message") {
93
- console.log(`Ignoring event with unexpected type "${event.type}"`);
96
+ const {
97
+ type: msgType,
98
+ subtype,
99
+ bot_id: botId,
100
+ text,
101
+ blocks = [],
102
+ } = event;
103
+ const [
104
+ {
105
+ elements: [
106
+ { elements = [] } = {},
107
+ ] = [],
108
+ } = {},
109
+ ] = blocks;
110
+
111
+ if (msgType !== "message") {
112
+ console.log(`Ignoring event with unexpected type "${msgType}"`);
94
113
  return;
95
114
  }
96
- if (event.subtype != null && event.subtype != "bot_message" && event.subtype != "file_share") {
115
+
97
116
  // This source is designed to just emit an event for each new message received.
98
117
  // Due to inconsistencies with the shape of message_changed and message_deleted
99
118
  // events, we are ignoring them for now. If you want to handle these types of
100
119
  // events, feel free to change this code!!
101
- console.log("Ignoring message with subtype.");
120
+ if (subtype && !constants.ALLOWED_SUBTYPES.includes(subtype)) {
121
+ console.log(`Ignoring message with subtype. "${subtype}"`);
102
122
  return;
103
123
  }
104
- if ((this.ignoreBot) && (event.subtype == "bot_message" || event.bot_id)) {
124
+
125
+ if ((this.ignoreBot) && (subtype === constants.SUBTYPE.BOT_MESSAGE || botId)) {
105
126
  return;
106
127
  }
107
- let emitEvent = false;
108
- const elements = event.blocks[0]?.elements[0]?.elements;
109
128
 
129
+ let emitEvent = false;
110
130
  if (this.isUsername && elements) {
111
131
  for (const item of elements) {
112
132
  if (item.user_id) {
@@ -117,10 +137,12 @@ export default {
117
137
  }
118
138
  }
119
139
  }
120
-
121
- } else if (event.text.indexOf(this.keyword) !== -1) {
140
+ } else if (text.indexOf(this.keyword) !== -1) {
141
+ emitEvent = true;
142
+ } else if (subtype === constants.SUBTYPE.PD_HISTORY_MESSAGE) {
122
143
  emitEvent = true;
123
144
  }
145
+
124
146
  if (emitEvent) {
125
147
  return event;
126
148
  }
@@ -1,14 +1,11 @@
1
1
  import common from "../common/base.mjs";
2
- import {
3
- events,
4
- eventsOptions,
5
- } from "../common/constants.mjs";
2
+ import constants from "../common/constants.mjs";
6
3
 
7
4
  export default {
8
5
  ...common,
9
6
  key: "slack-new-star-added",
10
7
  name: "New Star Added (Instant)",
11
- version: "0.0.10",
8
+ version: "0.0.11",
12
9
  description: "Emit new event when a star is added to an item",
13
10
  type: "source",
14
11
  dedupe: "unique",
@@ -28,14 +25,14 @@ export default {
28
25
  type: "string[]",
29
26
  label: "Event Types",
30
27
  description: "The types of event to emit. If not specified, all events will be emitted.",
31
- options: eventsOptions,
28
+ options: constants.eventsOptions,
32
29
  optional: true,
33
30
  },
34
31
  },
35
32
  methods: {
36
33
  ...common.methods,
37
34
  getSummary({ item: { type } }) {
38
- return `New star added - ${events[type] ?? type}`;
35
+ return `New star added - ${constants.events[type] ?? type}`;
39
36
  },
40
37
  async processEvent(event) {
41
38
  if (this.eventTypes == null