@pipedream/slack 0.4.10 → 0.4.12

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 +1 -1
  2. package/actions/archive-channel/archive-channel.mjs +1 -1
  3. package/actions/complete-reminder/complete-reminder.mjs +1 -1
  4. package/actions/create-channel/create-channel.mjs +1 -1
  5. package/actions/create-reminder/create-reminder.mjs +1 -1
  6. package/actions/delete-file/delete-file.mjs +1 -1
  7. package/actions/delete-message/delete-message.mjs +1 -1
  8. package/actions/delete-reminder/delete-reminder.mjs +1 -1
  9. package/actions/find-message/find-message.mjs +4 -3
  10. package/actions/find-user-by-email/find-user-by-email.mjs +1 -1
  11. package/actions/get-channel/get-channel.mjs +1 -1
  12. package/actions/get-file/get-file.mjs +1 -1
  13. package/actions/get-reminder/get-reminder.mjs +1 -1
  14. package/actions/invite-user-to-channel/invite-user-to-channel.mjs +1 -2
  15. package/actions/join-channel/join-channel.mjs +1 -1
  16. package/actions/kick-user/kick-user.mjs +1 -1
  17. package/actions/leave-channel/leave-channel.mjs +1 -1
  18. package/actions/list-channels/list-channels.mjs +1 -1
  19. package/actions/list-files/list-files.mjs +1 -1
  20. package/actions/list-members-in-channel/list-members-in-channel.mjs +1 -1
  21. package/actions/list-reminders/list-reminders.mjs +1 -1
  22. package/actions/list-replies/list-replies.mjs +1 -1
  23. package/actions/list-user-groups-users/list-user-groups-users.mjs +1 -1
  24. package/actions/list-users/list-users.mjs +5 -3
  25. package/actions/remove-star/remove-star.mjs +1 -1
  26. package/actions/reply-to-a-message/reply-to-a-message.mjs +1 -1
  27. package/actions/send-block-kit-message/send-block-kit-message.mjs +1 -1
  28. package/actions/send-custom-message/send-custom-message.mjs +1 -1
  29. package/actions/send-direct-message/send-direct-message.mjs +1 -1
  30. package/actions/send-group-message/send-group-message.mjs +1 -1
  31. package/actions/send-large-message/send-large-message.mjs +1 -1
  32. package/actions/send-message-private-channel/send-message-private-channel.mjs +8 -2
  33. package/actions/send-message-public-channel/send-message-public-channel.mjs +8 -2
  34. package/actions/set-channel-purpose/set-channel-purpose.mjs +1 -1
  35. package/actions/set-channel-topic/set-channel-topic.mjs +1 -1
  36. package/actions/unarchive-channel/unarchive-channel.mjs +1 -1
  37. package/actions/update-message/update-message.mjs +1 -1
  38. package/actions/update-profile/update-profile.mjs +1 -1
  39. package/actions/update-user-groups-users/update-user-groups-users.mjs +1 -1
  40. package/actions/upload-file/upload-file.mjs +1 -1
  41. package/actions/verify-slack-signature/verify-slack-signature.mjs +60 -0
  42. package/common/constants.mjs +15 -0
  43. package/package.json +1 -1
  44. package/slack.app.mjs +326 -159
  45. package/sources/new-direct-message/new-direct-message.mjs +1 -1
  46. package/sources/new-interaction-event-received/new-interaction-event-received.mjs +1 -1
  47. package/sources/new-mention/new-mention.mjs +2 -2
  48. package/sources/new-message-in-channels/new-message-in-channels.mjs +1 -1
  49. package/sources/new-reaction-added/new-reaction-added.mjs +1 -1
  50. package/sources/new-star-added/new-star-added.mjs +1 -1
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-add-star",
5
5
  name: "Add Star",
6
6
  description: "Add a star to an item on behalf of the authenticated user. [See docs here](https://api.slack.com/methods/stars.add)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-archive-channel",
5
5
  name: "Archive Channel",
6
6
  description: "Archive a channel. [See docs here](https://api.slack.com/methods/conversations.archive)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-complete-reminder",
5
5
  name: "Complete Reminder",
6
6
  description: "Complete a reminder. [See docs here](https://api.slack.com/methods/reminders.complete)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-create-channel",
5
5
  name: "Create a Channel",
6
6
  description: "Create a new channel. [See docs here](https://api.slack.com/methods/conversations.create)",
7
- version: "0.0.9",
7
+ version: "0.0.10",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-create-reminder",
5
5
  name: "Create Reminder",
6
6
  description: "Create a reminder. [See docs here](https://api.slack.com/methods/reminders.add)",
7
- version: "0.0.9",
7
+ version: "0.0.10",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-delete-file",
5
5
  name: "Delete File",
6
6
  description: "Delete a file. [See docs here](https://api.slack.com/methods/files.delete)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-delete-message",
5
5
  name: "Delete Message",
6
6
  description: "Delete a message. [See docs here](https://api.slack.com/methods/chat.delete)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-delete-reminder",
5
5
  name: "Delete Reminder",
6
6
  description: "Delete a reminder. [See docs here](https://api.slack.com/methods/reminders.delete)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-find-message",
5
5
  name: "Find Message",
6
6
  description: "Find a Slack message. [See docs here](https://api.slack.com/methods/search.messages)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -21,7 +21,7 @@ export default {
21
21
  ],
22
22
  optional: true,
23
23
  },
24
- team_id: {
24
+ teamId: {
25
25
  propDefinition: [
26
26
  slack,
27
27
  "team",
@@ -30,9 +30,10 @@ export default {
30
30
  },
31
31
  },
32
32
  async run() {
33
- return await this.slack.sdk().search.messages({
33
+ return this.slack.searchMessages({
34
34
  query: this.query,
35
35
  count: this.count,
36
+ team_id: this.teamId,
36
37
  });
37
38
  },
38
39
  };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-find-user-by-email",
5
5
  name: "Find User by Email",
6
6
  description: "Find a user by matching against their email. [See docs here](https://api.slack.com/methods/users.lookupByEmail)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-get-channel",
5
5
  name: "Get Channel",
6
6
  description: "Return information about a workspace channel. [See docs here](https://api.slack.com/methods/conversations.info)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-get-file",
5
5
  name: "Get File",
6
6
  description: "Return information about a file. [See docs here](https://api.slack.com/methods/files.info)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-get-reminder",
5
5
  name: "Get Reminder",
6
6
  description: "Return information about a reminder. [See docs here](https://api.slack.com/methods/reminders.info)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-invite-user-to-channel",
5
5
  name: "Invite User to Channel",
6
6
  description: "Invite a user to an existing channel. [See docs here](https://api.slack.com/methods/conversations.invite)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -20,7 +20,6 @@ export default {
20
20
  "user",
21
21
  ],
22
22
  },
23
-
24
23
  },
25
24
  async run() {
26
25
  return await this.slack.sdk().conversations.invite({
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-join-channel",
5
5
  name: "Join Channel",
6
6
  description: "Join an existing channel. [See docs here](https://api.slack.com/methods/conversations.join)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-kick-user",
5
5
  name: "Kick User",
6
6
  description: "Remove a user from a conversation. [See docs here](https://api.slack.com/methods/conversations.kick)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-leave-channel",
5
5
  name: "Leave Channel",
6
6
  description: "Leave an existing channel. [See docs here](https://api.slack.com/methods/conversations.leave)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-channels",
5
5
  name: "List Channels",
6
6
  description: "Return a list of all channels in a workspace. [See docs here](https://api.slack.com/methods/conversations.list)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-files",
5
5
  name: "List Files",
6
6
  description: "Return a list of files within a team. [See docs here](https://api.slack.com/methods/files.list)",
7
- version: "0.0.36",
7
+ version: "0.0.37",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-members-in-channel",
5
5
  name: "List Members in Channel",
6
6
  description: "Retrieve members of a channel. [See docs here](https://api.slack.com/methods/conversations.members)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-reminders",
5
5
  name: "List Reminders",
6
6
  description: "List all reminders for a given user. [See docs here](https://api.slack.com/methods/reminders.list)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-replies",
5
5
  name: "List Replies",
6
6
  description: "Retrieve a thread of messages posted to a conversation. [See docs here](https://api.slack.com/methods/conversations.replies)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-list-user-groups-users",
5
5
  name: "List User Groups Users",
6
6
  description: "List all users in a User Group. [See docs here](https://api.slack.com/methods/usergroups.users.list)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,11 +4,11 @@ export default {
4
4
  key: "slack-list-users",
5
5
  name: "List Users",
6
6
  description: "Return a list of all users in a workspace. [See docs here](https://api.slack.com/methods/users.list)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
11
- team_id: {
11
+ teamId: {
12
12
  propDefinition: [
13
13
  slack,
14
14
  "team",
@@ -17,6 +17,8 @@ export default {
17
17
  },
18
18
  },
19
19
  async run() {
20
- return await this.slack.sdk().users.list();
20
+ return this.slack.usersList({
21
+ team_id: this.teamId,
22
+ });
21
23
  },
22
24
  };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-remove-star",
5
5
  name: "Remove Star",
6
6
  description: "Remove a star from an item on behalf of the authenticated user. [See docs here](https://api.slack.com/methods/stars.remove)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -6,7 +6,7 @@ export default {
6
6
  key: "slack-reply-to-a-message",
7
7
  name: "Reply to a Message Thread",
8
8
  description: "Send a message as a threaded reply. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
9
- version: "0.1.11",
9
+ version: "0.1.12",
10
10
  type: "action",
11
11
  props: {
12
12
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "slack-send-block-kit-message",
6
6
  name: "Send Message Using Block Kit",
7
7
  description: "Send a message using Slack's Block Kit UI framework to a channel, group or user. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.10",
8
+ version: "0.2.11",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "slack-send-custom-message",
6
6
  name: "Send a Custom Message",
7
7
  description: "Customize advanced setttings and send a message to a channel, group or user. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.10",
8
+ version: "0.2.11",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "slack-send-direct-message",
6
6
  name: "Send a Direct Message",
7
7
  description: "Send a direct message to a single user. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.11",
8
+ version: "0.2.12",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "slack-send-group-message",
6
6
  name: "Send Group Message",
7
7
  description: "Send a direct message to a group of users. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.11",
8
+ version: "0.2.12",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "slack-send-large-message",
6
6
  name: "Send a Large Message (3000+ characters)",
7
7
  description: "Send a large message (more than 3000 characters) to a channel, group or user. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.0.6",
8
+ version: "0.0.7",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -1,18 +1,24 @@
1
1
  import common from "../common/send-message.mjs";
2
+ import constants from "../../common/constants.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "slack-send-message-private-channel",
6
7
  name: "Send Message to a Private Channel",
7
8
  description: "Send a message to a private channel and customize the name and avatar of the bot that posts the message. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.11",
9
+ version: "0.2.12",
9
10
  type: "action",
10
11
  props: {
11
12
  ...common.props,
12
13
  conversation: {
13
14
  propDefinition: [
14
15
  common.props.slack,
15
- "privateChannel",
16
+ "channelId",
17
+ () => ({
18
+ types: [
19
+ constants.CHANNEL_TYPE.PRIVATE,
20
+ ],
21
+ }),
16
22
  ],
17
23
  },
18
24
  text: {
@@ -1,18 +1,24 @@
1
1
  import common from "../common/send-message.mjs";
2
+ import constants from "../../common/constants.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "slack-send-message-public-channel",
6
7
  name: "Send Message to a Public Channel",
7
8
  description: "Send a message to a public channel and customize the name and avatar of the bot that posts the message. See [postMessage](https://api.slack.com/methods/chat.postMessage) or [scheduleMessage](https://api.slack.com/methods/chat.scheduleMessage) docs here",
8
- version: "0.2.10",
9
+ version: "0.2.11",
9
10
  type: "action",
10
11
  props: {
11
12
  ...common.props,
12
13
  conversation: {
13
14
  propDefinition: [
14
15
  common.props.slack,
15
- "publicChannel",
16
+ "channelId",
17
+ () => ({
18
+ types: [
19
+ constants.CHANNEL_TYPE.PUBLIC,
20
+ ],
21
+ }),
16
22
  ],
17
23
  },
18
24
  text: {
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-set-channel-purpose",
5
5
  name: "Set Channel Purpose",
6
6
  description: "Change the purpose of a channel. [See docs here](https://api.slack.com/methods/conversations.setPurpose)",
7
- version: "0.0.9",
7
+ version: "0.0.10",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-set-channel-topic",
5
5
  name: "Set Channel Topic",
6
6
  description: "Set the topic on a selected channel. [See docs here](https://api.slack.com/methods/conversations.setTopic)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-unarchive-channel",
5
5
  name: "Unarchive Channel",
6
6
  description: "Unarchive a channel. [See docs here](https://api.slack.com/methods/conversations.unarchive)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-update-message",
5
5
  name: "Update Message",
6
6
  description: "Update a message. [See docs here](https://api.slack.com/methods/chat.update)",
7
- version: "0.1.8",
7
+ version: "0.1.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-update-profile",
5
5
  name: "Update Profile",
6
6
  description: "Update basic profile field such as name or title. [See docs here](https://api.slack.com/methods/users.profile.set)",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "slack-update-user-groups-users",
5
5
  name: "Update User Groups Users",
6
6
  description: "Update the list of users for a User Group. [See docs here](https://api.slack.com/methods/usergroups.users.update)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  slack,
@@ -6,7 +6,7 @@ export default {
6
6
  key: "slack-upload-file",
7
7
  name: "Upload File",
8
8
  description: "Upload a file. [See docs here](https://api.slack.com/methods/files.upload)",
9
- version: "0.0.11",
9
+ version: "0.0.12",
10
10
  type: "action",
11
11
  props: {
12
12
  slack,
@@ -0,0 +1,60 @@
1
+ import slack from "../../slack.app.mjs";
2
+ import crypto from "crypto";
3
+
4
+ export default {
5
+ key: "slack-verify-slack-signature",
6
+ name: "Verify Slack Signature",
7
+ description: "Verifying requests from Slack, slack signs its requests using a secret that's unique to your app. [See docs here](https://api.slack.com/authentication/verifying-requests-from-slack)",
8
+ version: "0.0.2",
9
+ type: "action",
10
+ props: {
11
+ slack,
12
+ slackSigningSecret: {
13
+ type: "string",
14
+ label: "Signing Secret",
15
+ description: "Slack [Signing Secret](https://api.slack.com/authentication/verifying-requests-from-slack#:~:text=Slack%20Signing%20Secret%2C%20available%20in%20the%20app%20admin%20panel%20under%20Basic%20Info.), available in the app admin panel under Basic Info.",
16
+ secret: true,
17
+ },
18
+ slackSignature: {
19
+ type: "string",
20
+ label: "X-Slack-Signature",
21
+ description: "Slack signature (from X-Slack-Signature header).",
22
+ },
23
+ slackRequestTimestamp: {
24
+ type: "string",
25
+ label: "X-Slack-Request-Timestamp",
26
+ description: "Slack request timestamp (from X-Slack-Request-Timestamp header).",
27
+ },
28
+ requestBody: {
29
+ type: "any",
30
+ label: "Request Body",
31
+ description: "The body of the request to be verified.",
32
+ },
33
+ },
34
+ async run({ $ }) {
35
+ const {
36
+ slackSignature,
37
+ slackRequestTimestamp,
38
+ requestBody,
39
+ slackSigningSecret,
40
+ } = this;
41
+ const requestBodyStr = typeof (requestBody) === "string" ?
42
+ requestBody :
43
+ JSON.stringify(requestBody);
44
+ const sigBaseString = `v0:${slackRequestTimestamp}:${requestBodyStr}`;
45
+ const sha256Hex = crypto.createHmac("sha256", slackSigningSecret)
46
+ .update(sigBaseString, "utf8")
47
+ .digest("hex");
48
+ const mySignature = `v0=${sha256Hex}`;
49
+ if (crypto.timingSafeEqual(Buffer.from(mySignature, "utf8"), Buffer.from(slackSignature, "utf8"))) {
50
+ $.export("$summary", `Successfully verified the request with "${slackSignature}" signature`);
51
+ return {
52
+ success: true,
53
+ };
54
+ }
55
+ $.export("$summary", "Slack signature mismatch with provided properties, it may be a configuration issue.");
56
+ return {
57
+ success: false,
58
+ };
59
+ },
60
+ };
@@ -0,0 +1,15 @@
1
+ const MAX_RESOURCES = 800;
2
+ const LIMIT = 200;
3
+
4
+ const CHANNEL_TYPE = {
5
+ PUBLIC: "public_channel",
6
+ PRIVATE: "private_channel",
7
+ MPIM: "mpim",
8
+ IM: "im",
9
+ };
10
+
11
+ export default {
12
+ MAX_RESOURCES,
13
+ LIMIT,
14
+ CHANNEL_TYPE,
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/slack",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "Pipedream Slack Components",
5
5
  "main": "slack.app.mjs",
6
6
  "keywords": [
package/slack.app.mjs CHANGED
@@ -1,51 +1,10 @@
1
1
  import { WebClient } from "@slack/web-api";
2
+ import constants from "./common/constants.mjs";
2
3
 
3
4
  export default {
4
5
  type: "app",
5
6
  app: "slack",
6
7
  propDefinitions: {
7
- publicChannel: {
8
- type: "string",
9
- label: "Channel",
10
- description: "Select a public channel",
11
- async options({ prevContext }) {
12
- const { cursor } = prevContext;
13
- const types = [
14
- "public_channel",
15
- ];
16
- const resp = await this.availableConversations(types.join(), cursor);
17
- return {
18
- options: resp.conversations.map((c) => ({
19
- label: `${c.name}`,
20
- value: c.id,
21
- })),
22
- context: {
23
- cursor: resp.cursor,
24
- },
25
- };
26
- },
27
- },
28
- privateChannel: {
29
- type: "string",
30
- label: "Channel",
31
- description: "Select a private channel",
32
- async options({ prevContext }) {
33
- const { cursor } = prevContext;
34
- const types = [
35
- "private_channel",
36
- ];
37
- const resp = await this.availableConversations(types.join(), cursor);
38
- return {
39
- options: resp.conversations.map((c) => ({
40
- label: `${c.name}`,
41
- value: c.id,
42
- })),
43
- context: {
44
- cursor: resp.cursor,
45
- },
46
- };
47
- },
48
- },
49
8
  user: {
50
9
  type: "string",
51
10
  label: "User",
@@ -64,7 +23,7 @@ export default {
64
23
  return {
65
24
  options: conversationsResp.conversations.map((c) => ({
66
25
  label: `@${userNames[c.user]}`,
67
- value: c.id,
26
+ value: c.user || c.id,
68
27
  })),
69
28
  context: {
70
29
  userNames,
@@ -117,8 +76,8 @@ export default {
117
76
  label: "User Group",
118
77
  description: "The encoded ID of the User Group.",
119
78
  async options() {
120
- const resp = await this.userGroups();
121
- return resp.map((c) => ({
79
+ const { usergroups } = await this.usergroupsList();
80
+ return usergroups.map((c) => ({
122
81
  label: c.name,
123
82
  value: c.id,
124
83
  }));
@@ -128,20 +87,12 @@ export default {
128
87
  type: "string",
129
88
  label: "Reminder",
130
89
  description: "Select a reminder",
131
- async options({ prevContext }) {
132
- let { cursor } = prevContext;
133
- let resp = await this.getRemindersForTeam();
134
- return {
135
- options: resp.reminders.map((c) => {
136
- return {
137
- label: c.text,
138
- value: c.id,
139
- };
140
- }),
141
- context: {
142
- cursor: cursor,
143
- },
144
- };
90
+ async options() {
91
+ const { reminders } = await this.remindersList();
92
+ return reminders.map((c) => ({
93
+ label: c.text,
94
+ value: c.id,
95
+ }));
145
96
  },
146
97
  },
147
98
  conversation: {
@@ -155,7 +106,7 @@ export default {
155
106
  userNames: userNamesOrPromise,
156
107
  } = prevContext;
157
108
  if (types == null) {
158
- const scopes = await this.scopes();
109
+ const { response_metadata: { scopes } } = await this.authTest();
159
110
  types = [
160
111
  "public_channel",
161
112
  ];
@@ -206,23 +157,78 @@ export default {
206
157
  };
207
158
  },
208
159
  },
160
+ channelId: {
161
+ type: "string",
162
+ label: "Channel ID",
163
+ description: "Select the channel's id.",
164
+ async options({
165
+ prevContext, types = [], channelsFilter = (channel) => channel, excludeArchived = true,
166
+ }) {
167
+ const {
168
+ channels,
169
+ response_metadata: { next_cursor: cursor },
170
+ } = await this.conversationsList({
171
+ types: types.join(),
172
+ cursor: prevContext.cursor,
173
+ limit: constants.LIMIT,
174
+ exclude_archived: excludeArchived,
175
+ });
176
+
177
+ const resourcesInfo = await Promise.all(
178
+ channels
179
+ .filter(channelsFilter)
180
+ .map(async ({
181
+ id: channelId,
182
+ is_im: isIm,
183
+ user,
184
+ }) => ({
185
+ channelId,
186
+ resource: isIm
187
+ ? await this.usersInfo({
188
+ user,
189
+ })
190
+ : await this.conversationsInfo({
191
+ channel: channelId,
192
+ }),
193
+ })),
194
+ );
195
+
196
+ const options =
197
+ resourcesInfo.map(({
198
+ channelId, resource,
199
+ }) => ({
200
+ value: channelId,
201
+ label: this.getChannelLabel(resource),
202
+ }));
203
+
204
+ return {
205
+ options,
206
+ context: {
207
+ cursor,
208
+ },
209
+ };
210
+ },
211
+ },
209
212
  team: {
210
213
  type: "string",
211
214
  label: "Team",
212
215
  description: "Select a team.",
213
216
  async options({ prevContext }) {
214
- let { cursor } = prevContext;
215
-
216
- const resp = await this.getTeams(cursor);
217
+ const {
218
+ teams,
219
+ response_metadata: { next_cursor: cursor },
220
+ } = await this.authTeamsList({
221
+ cursor: prevContext.cursor,
222
+ });
217
223
 
218
224
  return {
219
- options: resp.teams.map((team) => ({
225
+ options: teams.map((team) => ({
220
226
  label: team.name,
221
227
  value: team.id,
222
228
  })),
223
229
 
224
230
  context: {
225
- cursor: resp.cursor,
231
+ cursor,
226
232
  },
227
233
  };
228
234
  },
@@ -439,30 +445,51 @@ export default {
439
445
  },
440
446
  },
441
447
  methods: {
448
+ getChannelLabel(resource) {
449
+ if (resource.user) {
450
+ return `Direct Messaging with: @${resource.user.name}`;
451
+ }
452
+
453
+ const {
454
+ is_private: isPrivate,
455
+ name,
456
+ } = resource.channel;
457
+
458
+ return `${isPrivate && "Private" || "Public"} channel #${name}`;
459
+ },
442
460
  mySlackId() {
443
461
  return this.$auth.oauth_uid;
444
462
  },
463
+ getToken() {
464
+ return this.$auth.oauth_access_token;
465
+ },
445
466
  /**
446
467
  * Returns a Slack Web Client object authenticated with the user's access
447
468
  * token
448
469
  */
449
470
  sdk() {
450
- return new WebClient(this.$auth.oauth_access_token);
451
- },
452
- /**
453
- * This method returns the list of OAuth scopes the current authenticated
454
- * user has
455
- *
456
- * @returns the list of scopes
457
- */
458
- async scopes() {
459
- const resp = await this.sdk().auth.test();
460
- if (resp.ok) {
461
- return resp.response_metadata.scopes;
462
- } else {
463
- console.log("Error getting scopes", resp.error);
464
- throw (resp.error);
471
+ return new WebClient(this.getToken());
472
+ },
473
+ async makeRequest({
474
+ method = "", ...args
475
+ } = {}) {
476
+ let response;
477
+ const props = method.split(".");
478
+ const sdk = props.reduce((reduction, prop) =>
479
+ reduction[prop], this.sdk());
480
+
481
+ try {
482
+ response = await sdk(args);
483
+ } catch (error) {
484
+ console.log(`Error calling ${method}`, error);
485
+ throw error;
486
+ }
487
+
488
+ if (!response.ok) {
489
+ console.log(`Error in response with method ${method}`, response.error);
490
+ throw response.error;
465
491
  }
492
+ return response;
466
493
  },
467
494
  /**
468
495
  * Returns a list of channel-like conversations in a workspace. The
@@ -477,73 +504,19 @@ export default {
477
504
  * page of conversations
478
505
  */
479
506
  async availableConversations(types, cursor) {
480
- const params = {
507
+ const {
508
+ channels: conversations,
509
+ response_metadata: { next_cursor: nextCursor },
510
+ } = await this.usersConversations({
481
511
  types,
482
512
  cursor,
483
- limit: 200,
513
+ limit: constants.LIMIT,
484
514
  exclude_archived: true,
485
- user: this.$auth.oauth_uid,
486
- };
487
- const resp = await this.sdk().users.conversations(params);
488
- if (resp.ok) {
489
- return {
490
- cursor: resp.response_metadata.next_cursor,
491
- conversations: resp.channels,
492
- };
493
- } else {
494
- console.log("Error getting conversations", resp.error);
495
- throw (resp.error);
496
- }
497
- },
498
- /**
499
- * This method lists reminders created by or for a given user
500
- *
501
- * @returns an object containing a list of reminders
502
- */
503
- async getRemindersForTeam() {
504
- const resp = await this.sdk().reminders.list();
505
- if (resp.ok) {
506
- return {
507
- reminders: resp.reminders,
508
- };
509
- } else {
510
- throw (resp.error);
511
- }
512
- },
513
- /**
514
- * Returns a list of all users in the workspace. This includes
515
- * deleted/deactivated users.
516
- *
517
- * @param {string} [cursor] - a cursor returned by the previous API call,
518
- * used to paginate through collections of data
519
- * @returns an object containing a list of users and the cursor for the next
520
- * page of users
521
- */
522
- async users(cursor) {
523
- const resp = await this.sdk().users.list({
524
- cursor,
525
515
  });
526
- if (resp.ok) {
527
- return {
528
- users: resp.members,
529
- cursor: resp.response_metadata.next_cursor,
530
- };
531
- } else {
532
- console.log("Error getting users", resp.error);
533
- throw (resp.error);
534
- }
535
- },
536
- /**
537
- * Returns a list of all users groups in the workspace.
538
- */
539
- async userGroups() {
540
- const resp = await this.sdk().usergroups.list();
541
- if (resp.ok) {
542
- return resp.usergroups;
543
- } else {
544
- console.log("Error getting user groups", resp.error);
545
- throw (resp.error);
546
- }
516
+ return {
517
+ cursor: nextCursor,
518
+ conversations,
519
+ };
547
520
  },
548
521
  /**
549
522
  * Returns a mapping from user ID to user name for all users in the workspace
@@ -555,30 +528,224 @@ export default {
555
528
  const userNames = {};
556
529
  do {
557
530
  const {
558
- users,
559
- cursor: nextCursor,
560
- } = await this.users(cursor);
531
+ members: users,
532
+ response_metadata: { next_cursor: nextCursor },
533
+ } = await this.usersList({
534
+ cursor,
535
+ });
536
+
561
537
  for (const user of users) {
562
538
  userNames[user.id] = user.name;
563
539
  }
540
+
564
541
  cursor = nextCursor;
565
542
  } while (cursor);
566
543
  return userNames;
567
544
  },
568
- async getTeams(cursor) {
569
- const resp = await this.sdk().auth.teams.list({
570
- cursor,
545
+ /**
546
+ * Checks authentication & identity.
547
+ * @param {*} args Arguments object
548
+ * @returns Promise
549
+ */
550
+ authTest(args = {}) {
551
+ return this.makeRequest({
552
+ method: "auth.test",
553
+ ...args,
554
+ });
555
+ },
556
+ /**
557
+ * Lists all reminders created by or for a given user.
558
+ * @param {*} args Arguments object
559
+ * @param {string} [args.team_id] Encoded team id, required if org token is passed.
560
+ * E.g. `T1234567890`
561
+ * @returns Promise
562
+ */
563
+ remindersList(args = {}) {
564
+ return this.makeRequest({
565
+ method: "reminders.list",
566
+ ...args,
567
+ });
568
+ },
569
+ /**
570
+ * List all User Groups for a team
571
+ * @param {*} args
572
+ * @returns Promise
573
+ */
574
+ usergroupsList(args = {}) {
575
+ return this.makeRequest({
576
+ method: "usergroups.list",
577
+ ...args,
578
+ });
579
+ },
580
+ authTeamsList(args = {}) {
581
+ return this.makeRequest({
582
+ method: "auth.teams.list",
583
+ ...args,
584
+ });
585
+ },
586
+ /**
587
+ * List conversations the calling user may access.
588
+ * Bot Scopes: `channels:read` `groups:read` `im:read` `mpim:read`
589
+ * @param {UsersConversationsArguments} args Arguments object
590
+ * @param {string} [args.cursor] Pagination value e.g. (`dXNlcjpVMDYxTkZUVDI=`)
591
+ * @param {boolean} [args.exclude_archived] Set to `true` to exclude archived channels
592
+ * from the list. Defaults to `false`
593
+ * @param {number} [args.limit] Pagination value. Defaults to `0`
594
+ * @param {string} [args.team_id] Encoded team id to list users in,
595
+ * required if org token is used
596
+ * @param {string} [args.types] Mix and match channel types by providing a
597
+ * comma-separated list of any combination of `public_channel`, `private_channel`, `mpim`, `im`
598
+ * Defaults to `public_channel`. E.g. `im,mpim`
599
+ * @param {string} [args.user] Browse conversations by a specific
600
+ * user ID's membership. Non-public channels are restricted to those where the calling user
601
+ * shares membership. E.g `W0B2345D`
602
+ * @returns Promise
603
+ */
604
+ usersConversations(args = {}) {
605
+ return this.makeRequest({
606
+ method: "users.conversations",
607
+ user: this.$auth.oauth_uid,
608
+ ...args,
609
+ });
610
+ },
611
+ /**
612
+ * Lists all users in a Slack team.
613
+ * Bot Scopes: `users:read`
614
+ * @param {UsersListArguments} args Arguments object
615
+ * @param {string} [args.cursor] Pagination value e.g. (`dXNlcjpVMDYxTkZUVDI=`)
616
+ * @param {boolean} [args.include_locale] Set this to `true` to receive the locale
617
+ * for users. Defaults to `false`
618
+ * @param {number} [args.limit] Pagination value. Defaults to `0`
619
+ * @param {string} [args.team_id] Encoded team id to list users in,
620
+ * required if org token is used
621
+ * @returns Promise
622
+ */
623
+ usersList(args = {}) {
624
+ return this.makeRequest({
625
+ method: "users.list",
626
+ ...args,
627
+ });
628
+ },
629
+ /**
630
+ * Lists all channels in a Slack team.
631
+ * Bot Scopes: `channels:read` `groups:read` `im:read` `mpim:read`
632
+ * @param {ConversationsListArguments} args Arguments object
633
+ * @param {string} [args.cursor] Pagination value e.g. (`dXNlcjpVMDYxTkZUVDI=`)
634
+ * @param {boolean} [args.exclude_archived] Set to `true` to exclude archived channels
635
+ * from the list. Defaults to `false`
636
+ * @param {number} [args.limit] pagination value. Defaults to `0`
637
+ * @param {string} [args.team_id] encoded team id to list users in,
638
+ * required if org token is used
639
+ * @param {string} [args.types] Mix and match channel types by providing a
640
+ * comma-separated list of any combination of `public_channel`, `private_channel`, `mpim`, `im`
641
+ * Defaults to `public_channel`. E.g. `im,mpim`
642
+ * @returns Promise
643
+ */
644
+ conversationsList(args = {}) {
645
+ return this.makeRequest({
646
+ method: "conversations.list",
647
+ ...args,
648
+ });
649
+ },
650
+ /**
651
+ * Fetches a conversation's history of messages and events.
652
+ * Bot Scopes: `channels:history` `groups:history` `im:history` `mpim:history`
653
+ * @param {ConversationsHistoryArguments} args Arguments object
654
+ * @param {string} args.channel Conversation ID to fetch history for. E.g. `C1234567890`
655
+ * @param {string} [args.cursor] Pagination value e.g. (`dXNlcjpVMDYxTkZUVDI=`)
656
+ * @param {boolean} [args.include_all_metadata]
657
+ * @param {boolean} [args.inclusive]
658
+ * @param {string} [args.latest]
659
+ * @param {number} [args.limit]
660
+ * @param {string} [args.oldest]
661
+ * @returns Promise
662
+ */
663
+ conversationsHistory(args = {}) {
664
+ return this.makeRequest({
665
+ method: "conversations.history",
666
+ ...args,
667
+ });
668
+ },
669
+ /**
670
+ * Retrieve information about a conversation.
671
+ * Bot Scopes: `channels:read` `groups:read` `im:read` `mpim:read`
672
+ * @param {ConversationsInfoArguments} args Arguments object
673
+ * @param {string} args.channel Conversation ID to learn more about. E.g. `C1234567890`
674
+ * @param {boolean} [args.include_locale] Set this to `true` to receive the locale
675
+ * for users. Defaults to `false`
676
+ * @param {boolean} [args.include_num_members] Set to true to include the
677
+ * member count for the specified conversation. Defaults to `false`
678
+ * @returns Promise
679
+ */
680
+ conversationsInfo(args = {}) {
681
+ return this.makeRequest({
682
+ method: "conversations.info",
683
+ ...args,
684
+ });
685
+ },
686
+ /**
687
+ * Retrieve information about a conversation.
688
+ * Bot Scopes: `users:read`
689
+ * @param {UsersInfoArguments} args arguments object
690
+ * @param {string} args.user User to get info on. E.g. `W1234567890`
691
+ * @param {boolean} [args.include_locale] Set this to true to receive the locale
692
+ * for this user. Defaults to `false`
693
+ * @returns Promise
694
+ */
695
+ usersInfo(args = {}) {
696
+ return this.makeRequest({
697
+ method: "users.info",
698
+ ...args,
699
+ });
700
+ },
701
+ /**
702
+ * Searches for messages matching a query.
703
+ * User Scopes: `search:read`
704
+ * @param {SearchMessagesArguments} args Arguments object
705
+ * @param {string} args.query Search query
706
+ * @param {number} [args.count] Number of items to return per page. Default `20`
707
+ * @param {string} [args.cursor] Use this when getting results with cursormark
708
+ * pagination. For first call send `*` for subsequent calls, send the value of
709
+ * `next_cursor` returned in the previous call's results
710
+ * @param {boolean} [args.highlight]
711
+ * @param {number} [args.page]
712
+ * @param {string} [args.sort]
713
+ * @param {string} [args.sort_dir]
714
+ * @param {string} [args.team_id] Encoded team id to search in,
715
+ * required if org token is used. E.g. `T1234567890`
716
+ * @returns Promise
717
+ */
718
+ searchMessages(args = {}) {
719
+ return this.makeRequest({
720
+ method: "search.messages",
721
+ ...args,
722
+ });
723
+ },
724
+ /**
725
+ * Lists reactions made by a user.
726
+ * User Scopes: `reactions:read`
727
+ * Bot Scopes: `reactions:read`
728
+ * @param {ReactionsListArguments} args Arguments object
729
+ * @param {number} [args.count] Number of items to return per page. Default `100`
730
+ * @param {string} [args.cursor] Parameter for pagination. Set cursor equal to the
731
+ * `next_cursor` attribute returned by the previous request's response_metadata.
732
+ * This parameter is optional, but pagination is mandatory: the default value simply
733
+ * fetches the first "page" of the collection.
734
+ * @param {boolean} [args.full] If true always return the complete reaction list.
735
+ * @param {number} [args.limit] The maximum number of items to return.
736
+ * Fewer than the requested number of items may be returned, even if the end of the
737
+ * list hasn't been reached.
738
+ * @param {number} [args.page] Page number of results to return. Defaults to `1`.
739
+ * @param {string} [args.team_id] Encoded team id to list reactions in,
740
+ * required if org token is used
741
+ * @param {string} [args.user] Show reactions made by this user. Defaults to the authed user.
742
+ * @returns Promise
743
+ */
744
+ reactionsList(args = {}) {
745
+ return this.makeRequest({
746
+ method: "reactions.list",
747
+ ...args,
571
748
  });
572
-
573
- if (resp.ok) {
574
- return {
575
- cursor: resp.response_metadata.next_cursor,
576
- teams: resp.teams,
577
- };
578
- } else {
579
- console.log("Error getting teams", resp.error);
580
- throw (resp.error);
581
- }
582
749
  },
583
750
  },
584
751
  };
@@ -4,7 +4,7 @@ export default {
4
4
  ...common,
5
5
  key: "slack-new-direct-message",
6
6
  name: "New Direct Message (Instant)",
7
- version: "1.0.5",
7
+ version: "1.0.6",
8
8
  description: "Emit new event when a message was posted in a direct message channel",
9
9
  type: "source",
10
10
  dedupe: "unique",
@@ -2,7 +2,7 @@ import common from "../common/base.mjs";
2
2
 
3
3
  export default {
4
4
  name: "New Interaction Events",
5
- version: "0.0.2",
5
+ version: "0.0.3",
6
6
  key: "slack-new-interaction-event-received",
7
7
  description:
8
8
  "Emit new events on new Slack [interactivity events](https://api.slack.com/interactivity) sourced from [Block Kit interactive elements](https://api.slack.com/interactivity/components), [Slash commands](https://api.slack.com/interactivity/slash-commands), or [Shortcuts](https://api.slack.com/interactivity/shortcuts).",
@@ -4,7 +4,7 @@ export default {
4
4
  ...common,
5
5
  key: "slack-new-mention",
6
6
  name: "New Mention (Instant)",
7
- version: "1.0.6",
7
+ version: "1.0.7",
8
8
  description: "Emit new event when a username or specific keyword is mentioned in a channel",
9
9
  type: "source",
10
10
  dedupe: "unique",
@@ -66,7 +66,7 @@ export default {
66
66
  methods: {
67
67
  ...common.methods,
68
68
  async getMatches(params) {
69
- return (await this.slack.sdk().search.messages(params)).messages.matches || [];
69
+ return (await this.slack.searchMessages(params)).messages.matches || [];
70
70
  },
71
71
  async emitHistoricalEvents(messages) {
72
72
  for (const message of messages) {
@@ -4,7 +4,7 @@ export default {
4
4
  ...common,
5
5
  key: "slack-new-message-in-channels",
6
6
  name: "New Message In Channels (Instant)",
7
- version: "1.0.5",
7
+ version: "1.0.6",
8
8
  description: "Emit new event when a new message is posted to one or more channels",
9
9
  type: "source",
10
10
  dedupe: "unique",
@@ -4,7 +4,7 @@ export default {
4
4
  ...common,
5
5
  key: "slack-new-reaction-added",
6
6
  name: "New Reaction Added (Instant)",
7
- version: "1.1.6",
7
+ version: "1.1.7",
8
8
  description: "Emit new event when a member has added an emoji reaction to an item",
9
9
  type: "source",
10
10
  dedupe: "unique",
@@ -8,7 +8,7 @@ export default {
8
8
  ...common,
9
9
  key: "slack-new-star-added",
10
10
  name: "New Star Added (Instant)",
11
- version: "0.0.9",
11
+ version: "0.0.10",
12
12
  description: "Emit new event when a star is added to an item",
13
13
  type: "source",
14
14
  dedupe: "unique",