@pipedream/slack_v2 0.0.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 (58) hide show
  1. package/LICENSE +41 -0
  2. package/actions/add-emoji-reaction/add-emoji-reaction.mjs +48 -0
  3. package/actions/approve-workflow/approve-workflow.mjs +92 -0
  4. package/actions/archive-channel/archive-channel.mjs +38 -0
  5. package/actions/common/build-blocks.mjs +182 -0
  6. package/actions/common/send-message.mjs +264 -0
  7. package/actions/create-channel/create-channel.mjs +40 -0
  8. package/actions/create-reminder/create-reminder.mjs +52 -0
  9. package/actions/delete-file/delete-file.mjs +39 -0
  10. package/actions/delete-message/delete-message.mjs +45 -0
  11. package/actions/find-message/find-message.mjs +83 -0
  12. package/actions/find-user-by-email/find-user-by-email.mjs +32 -0
  13. package/actions/get-current-user/get-current-user.mjs +68 -0
  14. package/actions/get-file/get-file.mjs +59 -0
  15. package/actions/invite-user-to-channel/invite-user-to-channel.mjs +45 -0
  16. package/actions/kick-user/kick-user.mjs +56 -0
  17. package/actions/list-channels/list-channels.mjs +52 -0
  18. package/actions/list-files/list-files.mjs +93 -0
  19. package/actions/list-group-members/list-group-members.mjs +68 -0
  20. package/actions/list-members-in-channel/list-members-in-channel.mjs +71 -0
  21. package/actions/list-replies/list-replies.mjs +74 -0
  22. package/actions/list-users/list-users.mjs +60 -0
  23. package/actions/reply-to-a-message/reply-to-a-message.mjs +54 -0
  24. package/actions/send-block-kit-message/send-block-kit-message.mjs +48 -0
  25. package/actions/send-large-message/send-large-message.mjs +95 -0
  26. package/actions/send-message/send-message.mjs +56 -0
  27. package/actions/send-message-advanced/send-message-advanced.mjs +75 -0
  28. package/actions/send-message-to-channel/send-message-to-channel.mjs +45 -0
  29. package/actions/send-message-to-user-or-group/send-message-to-user-or-group.mjs +93 -0
  30. package/actions/set-channel-description/set-channel-description.mjs +37 -0
  31. package/actions/set-channel-topic/set-channel-topic.mjs +37 -0
  32. package/actions/set-status/set-status.mjs +49 -0
  33. package/actions/update-group-members/update-group-members.mjs +72 -0
  34. package/actions/update-message/update-message.mjs +59 -0
  35. package/actions/update-profile/update-profile.mjs +94 -0
  36. package/actions/upload-file/upload-file.mjs +104 -0
  37. package/common/constants.mjs +31 -0
  38. package/package.json +22 -0
  39. package/slack_v2.app.mjs +1112 -0
  40. package/sources/common/base.mjs +184 -0
  41. package/sources/common/constants.mjs +58 -0
  42. package/sources/new-channel-created/new-channel-created.mjs +32 -0
  43. package/sources/new-channel-created/test-event.mjs +44 -0
  44. package/sources/new-interaction-event-received/README.md +85 -0
  45. package/sources/new-interaction-event-received/new-interaction-event-received.mjs +105 -0
  46. package/sources/new-interaction-event-received/test-event.mjs +86 -0
  47. package/sources/new-keyword-mention/new-keyword-mention.mjs +99 -0
  48. package/sources/new-keyword-mention/test-event.mjs +28 -0
  49. package/sources/new-message-in-channels/new-message-in-channels.mjs +106 -0
  50. package/sources/new-message-in-channels/test-event.mjs +45 -0
  51. package/sources/new-reaction-added/new-reaction-added.mjs +119 -0
  52. package/sources/new-reaction-added/test-event.mjs +193 -0
  53. package/sources/new-saved-message/new-saved-message.mjs +32 -0
  54. package/sources/new-saved-message/test-event.mjs +37 -0
  55. package/sources/new-user-added/new-user-added.mjs +32 -0
  56. package/sources/new-user-added/test-event.mjs +48 -0
  57. package/sources/new-user-mention/new-user-mention.mjs +124 -0
  58. package/sources/new-user-mention/test-event.mjs +28 -0
@@ -0,0 +1,93 @@
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_v2-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.1.0",
11
+ annotations: {
12
+ destructiveHint: false,
13
+ openWorldHint: true,
14
+ readOnlyHint: false,
15
+ },
16
+ type: "action",
17
+ props: {
18
+ slack: common.props.slack,
19
+ users: {
20
+ propDefinition: [
21
+ common.props.slack,
22
+ "user",
23
+ ],
24
+ type: "string[]",
25
+ label: "Users",
26
+ description: "Select the user(s) to message",
27
+ optional: true,
28
+ },
29
+ conversation: {
30
+ propDefinition: [
31
+ common.props.slack,
32
+ "conversation",
33
+ () => ({
34
+ types: [
35
+ constants.CHANNEL_TYPE.MPIM,
36
+ ],
37
+ }),
38
+ ],
39
+ description: "Select the group to message",
40
+ optional: true,
41
+ },
42
+ text: {
43
+ propDefinition: [
44
+ common.props.slack,
45
+ "text",
46
+ ],
47
+ },
48
+ mrkdwn: {
49
+ propDefinition: [
50
+ common.props.slack,
51
+ "mrkdwn",
52
+ ],
53
+ },
54
+ ...common.props,
55
+ // eslint-disable-next-line pipedream/props-label
56
+ as_user: {
57
+ ...common.props.as_user,
58
+ description: "Optionally pass `true` to post the message as the authenticated user, instead of as a bot. Defaults to `true`.",
59
+ // Default to true since bots can't message users unless the "Messages"
60
+ // tab is enabled, and can't message groups unless the bot is a member.
61
+ default: true,
62
+ },
63
+ // eslint-disable-next-line pipedream/props-label, pipedream/props-description
64
+ addToChannel: {
65
+ type: "boolean",
66
+ ...common.props.addToChannel,
67
+ disabled: true,
68
+ hidden: true,
69
+ },
70
+ },
71
+ methods: {
72
+ ...common.methods,
73
+ openConversation(args = {}) {
74
+ return this.slack.makeRequest({
75
+ method: "conversations.open",
76
+ ...args,
77
+ });
78
+ },
79
+ async getChannelId() {
80
+ if (!this.conversation && !this.users?.length) {
81
+ throw new ConfigurationError("Must select a group or user(s) to message");
82
+ }
83
+
84
+ if (this.conversation) {
85
+ return this.conversation;
86
+ }
87
+ const { channel: { id } } = await this.openConversation({
88
+ users: this.users.join(),
89
+ });
90
+ return id;
91
+ },
92
+ },
93
+ };
@@ -0,0 +1,37 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+
3
+ export default {
4
+ key: "slack_v2-set-channel-description",
5
+ name: "Set Channel Description",
6
+ description: "Change the description or purpose of a channel. [See the documentation](https://api.slack.com/methods/conversations.setPurpose)",
7
+ version: "0.0.10",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ slack,
16
+ conversation: {
17
+ propDefinition: [
18
+ slack,
19
+ "conversation",
20
+ ],
21
+ },
22
+ purpose: {
23
+ propDefinition: [
24
+ slack,
25
+ "purpose",
26
+ ],
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const response = await this.slack.setChannelDescription({
31
+ channel: this.conversation,
32
+ purpose: this.purpose,
33
+ });
34
+ $.export("$summary", `Successfully set description for channel with ID ${this.conversation}`);
35
+ return response;
36
+ },
37
+ };
@@ -0,0 +1,37 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+
3
+ export default {
4
+ key: "slack_v2-set-channel-topic",
5
+ name: "Set Channel Topic",
6
+ description: "Set the topic on a selected channel. [See the documentation](https://api.slack.com/methods/conversations.setTopic)",
7
+ version: "0.0.25",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ slack,
16
+ conversation: {
17
+ propDefinition: [
18
+ slack,
19
+ "conversation",
20
+ ],
21
+ },
22
+ topic: {
23
+ propDefinition: [
24
+ slack,
25
+ "topic",
26
+ ],
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const response = await this.slack.setChannelTopic({
31
+ channel: this.conversation,
32
+ topic: this.topic,
33
+ });
34
+ $.export("$summary", `Successfully set topic for channel with ID ${this.conversation}`);
35
+ return response;
36
+ },
37
+ };
@@ -0,0 +1,49 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+
3
+ export default {
4
+ key: "slack_v2-set-status",
5
+ name: "Set Status",
6
+ description: "Set the current status for a user. [See the documentation](https://api.slack.com/methods/users.profile.set)",
7
+ version: "0.0.10",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ slack,
16
+ statusText: {
17
+ type: "string",
18
+ label: "Status Text",
19
+ description: "The displayed text",
20
+ },
21
+ statusEmoji: {
22
+ propDefinition: [
23
+ slack,
24
+ "icon_emoji",
25
+ ],
26
+ label: "Status Emoji",
27
+ description: "The emoji to display with the status",
28
+ optional: true,
29
+ },
30
+ statusExpiration: {
31
+ type: "string",
32
+ label: "Status Expiration",
33
+ description: "The datetime of when the status will expire in ISO 8601 format. (Example: `2014-01-01T00:00:00Z`)",
34
+ optional: true,
35
+ },
36
+ },
37
+ async run({ $ }) {
38
+ const response = await this.slack.updateProfile({
39
+ profile: {
40
+ status_text: this.statusText,
41
+ status_emoji: this.statusEmoji && `:${this.statusEmoji}:`,
42
+ status_expiration: this.statusExpiration
43
+ && Math.floor(new Date(this.statusExpiration).getTime() / 1000),
44
+ },
45
+ });
46
+ $.export("$summary", "Successfully updated status.");
47
+ return response;
48
+ },
49
+ };
@@ -0,0 +1,72 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+
3
+ export default {
4
+ key: "slack_v2-update-group-members",
5
+ name: "Update Group Members",
6
+ description: "Update the list of users for a User Group. [See the documentation](https://api.slack.com/methods/usergroups.users.update)",
7
+ version: "0.0.10",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ slack,
16
+ userGroup: {
17
+ propDefinition: [
18
+ slack,
19
+ "userGroup",
20
+ ],
21
+ },
22
+ usersToAdd: {
23
+ propDefinition: [
24
+ slack,
25
+ "user",
26
+ ],
27
+ type: "string[]",
28
+ label: "Users to Add",
29
+ description: "A list of encoded user IDs that represent the users to add to the group.",
30
+ optional: true,
31
+ },
32
+ usersToRemove: {
33
+ propDefinition: [
34
+ slack,
35
+ "user",
36
+ ],
37
+ type: "string[]",
38
+ label: "Users to Remove",
39
+ description: "A list of encoded user IDs that represent the users to remove from the group.",
40
+ optional: true,
41
+ },
42
+ team: {
43
+ propDefinition: [
44
+ slack,
45
+ "team",
46
+ ],
47
+ optional: true,
48
+ description: "Encoded team id where the user group exists, required if org token is used.",
49
+ },
50
+ },
51
+ async run({ $ }) {
52
+ const {
53
+ userGroup,
54
+ usersToAdd = [],
55
+ usersToRemove = [],
56
+ team,
57
+ } = this;
58
+ let { users } = await this.slack.listGroupMembers({
59
+ usergroup: userGroup,
60
+ team_id: team,
61
+ });
62
+ users = users.filter((user) => !usersToRemove.includes(user));
63
+ users.push(...usersToAdd);
64
+ const response = await this.slack.updateGroupMembers({
65
+ usergroup: userGroup,
66
+ users,
67
+ team_id: team,
68
+ });
69
+ $.export("$summary", `Successfully updated members of group with ID ${this.userGroup}`);
70
+ return response;
71
+ },
72
+ };
@@ -0,0 +1,59 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+
3
+ export default {
4
+ key: "slack_v2-update-message",
5
+ name: "Update Message",
6
+ description: "Update a message. [See the documentation](https://api.slack.com/methods/chat.update)",
7
+ version: "0.2.0",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ slack,
16
+ conversation: {
17
+ propDefinition: [
18
+ slack,
19
+ "conversation",
20
+ ],
21
+ },
22
+ timestamp: {
23
+ propDefinition: [
24
+ slack,
25
+ "messageTs",
26
+ ],
27
+ },
28
+ text: {
29
+ propDefinition: [
30
+ slack,
31
+ "text",
32
+ ],
33
+ },
34
+ as_user: {
35
+ propDefinition: [
36
+ slack,
37
+ "as_user",
38
+ ],
39
+ description: "Pass true to update the message as the authed user. Bot users in this context are considered authed users.",
40
+ },
41
+ attachments: {
42
+ propDefinition: [
43
+ slack,
44
+ "attachments",
45
+ ],
46
+ },
47
+ },
48
+ async run({ $ }) {
49
+ const response = await this.slack.updateMessage({
50
+ ts: this.timestamp,
51
+ text: this.text,
52
+ channel: this.conversation,
53
+ as_user: this.as_user,
54
+ attachments: this.attachments,
55
+ });
56
+ $.export("$summary", "Successfully updated message");
57
+ return response;
58
+ },
59
+ };
@@ -0,0 +1,94 @@
1
+ import slack from "../../slack_v2.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "slack_v2-update-profile",
6
+ name: "Update Profile",
7
+ description: "Update basic profile field such as name or title. [See the documentation](https://api.slack.com/methods/users.profile.set)",
8
+ version: "0.0.25",
9
+ annotations: {
10
+ destructiveHint: true,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ type: "action",
15
+ props: {
16
+ slack,
17
+ displayName: {
18
+ type: "string",
19
+ label: "Display Name",
20
+ description: "The display name the user has chosen to identify themselves by in their workspace profile",
21
+ optional: true,
22
+ },
23
+ firstName: {
24
+ type: "string",
25
+ label: "First Name",
26
+ description: "The user's first name",
27
+ optional: true,
28
+ },
29
+ lastName: {
30
+ type: "string",
31
+ label: "Last Name",
32
+ description: "The user's last name",
33
+ optional: true,
34
+ },
35
+ phone: {
36
+ type: "string",
37
+ label: "Phone",
38
+ description: "The user's phone number, in any format",
39
+ optional: true,
40
+ },
41
+ pronouns: {
42
+ type: "string",
43
+ label: "Pronouns",
44
+ description: "The user's pronouns",
45
+ optional: true,
46
+ },
47
+ title: {
48
+ type: "string",
49
+ label: "Title",
50
+ description: "The user's title",
51
+ optional: true,
52
+ },
53
+ email: {
54
+ type: "string",
55
+ label: "Email",
56
+ description: "The user's email address. You cannot update your own email using this method. This field can only be changed by admins for users on paid teams.",
57
+ optional: true,
58
+ },
59
+ user: {
60
+ propDefinition: [
61
+ slack,
62
+ "user",
63
+ ],
64
+ description: "ID of user to change. This argument may only be specified by admins on paid teams.",
65
+ optional: true,
66
+ },
67
+ },
68
+ async run({ $ }) {
69
+ if (!this.displayName
70
+ && !this.firstName
71
+ && !this.lastName
72
+ && !this.phone
73
+ && !this.pronouns
74
+ && !this.title
75
+ && !this.email
76
+ ) {
77
+ throw new ConfigurationError("Please provide at least one value to update");
78
+ }
79
+ const response = await this.slack.updateProfile({
80
+ profile: {
81
+ display_name: this.displayName,
82
+ first_name: this.firstName,
83
+ last_name: this.lastName,
84
+ phone: this.phone,
85
+ pronouns: this.pronouns,
86
+ title: this.title,
87
+ email: this.email,
88
+ },
89
+ user: this.user,
90
+ });
91
+ $.export("$summary", "Successfully updated profile");
92
+ return response;
93
+ },
94
+ };
@@ -0,0 +1,104 @@
1
+ import {
2
+ ConfigurationError, axios, getFileStreamAndMetadata,
3
+ } from "@pipedream/platform";
4
+ import FormData from "form-data";
5
+ import slack from "../../slack_v2.app.mjs";
6
+
7
+ export default {
8
+ key: "slack_v2-upload-file",
9
+ name: "Upload File",
10
+ description: "Upload a file. [See the documentation](https://api.slack.com/messaging/files#uploading_files)",
11
+ version: "0.1.3",
12
+ annotations: {
13
+ destructiveHint: false,
14
+ openWorldHint: true,
15
+ readOnlyHint: false,
16
+ },
17
+ type: "action",
18
+ props: {
19
+ slack,
20
+ conversation: {
21
+ propDefinition: [
22
+ slack,
23
+ "conversation",
24
+ ],
25
+ },
26
+ content: {
27
+ propDefinition: [
28
+ slack,
29
+ "content",
30
+ ],
31
+ },
32
+ initialComment: {
33
+ description: "Will be added as an initial comment before the image",
34
+ propDefinition: [
35
+ slack,
36
+ "initial_comment",
37
+ ],
38
+ optional: true,
39
+ },
40
+ syncDir: {
41
+ type: "dir",
42
+ accessMode: "read",
43
+ sync: true,
44
+ optional: true,
45
+ },
46
+ },
47
+ async run({ $ }) {
48
+ const {
49
+ stream, metadata,
50
+ } = await getFileStreamAndMetadata(this.content);
51
+
52
+ const filename = this.content.split("/").pop();
53
+
54
+ // Get an upload URL from Slack
55
+ const getUploadUrlResponse = await this.slack.getUploadUrl({
56
+ filename,
57
+ length: metadata.size,
58
+ });
59
+
60
+ if (!getUploadUrlResponse.ok) {
61
+ throw new ConfigurationError(`Error getting upload URL: ${JSON.stringify(getUploadUrlResponse)}`);
62
+ }
63
+
64
+ const {
65
+ upload_url: uploadUrl, file_id: fileId,
66
+ } = getUploadUrlResponse;
67
+
68
+ // Upload the file to the provided URL
69
+ const formData = new FormData();
70
+ formData.append("file", stream, {
71
+ contentType: metadata.contentType,
72
+ knownLength: metadata.size,
73
+ filename: metadata.name,
74
+ });
75
+ formData.append("filename", filename);
76
+
77
+ await axios($, {
78
+ url: uploadUrl,
79
+ data: formData,
80
+ method: "POST",
81
+ headers: {
82
+ ...formData.getHeaders(),
83
+ },
84
+ });
85
+
86
+ // Complete the file upload process in Slack
87
+ const completeUploadResponse = await this.slack.completeUpload({
88
+ channel_id: this.conversation,
89
+ initial_comment: this.initialComment,
90
+ files: [
91
+ {
92
+ id: fileId,
93
+ },
94
+ ],
95
+ });
96
+
97
+ if (!completeUploadResponse.ok) {
98
+ throw new Error(`Error completing upload: ${JSON.stringify(completeUploadResponse)}`);
99
+ }
100
+
101
+ $.export("$summary", "Successfully uploaded file");
102
+ return completeUploadResponse;
103
+ },
104
+ };
@@ -0,0 +1,31 @@
1
+ const MAX_RESOURCES = 800;
2
+ const LIMIT = 250;
3
+
4
+ const CHANNEL_TYPE = {
5
+ PUBLIC: "public_channel",
6
+ PRIVATE: "private_channel",
7
+ MPIM: "mpim",
8
+ IM: "im",
9
+ };
10
+
11
+ const CHANNEL_TYPE_OPTIONS = [
12
+ {
13
+ label: "Channels",
14
+ value: "Channels",
15
+ },
16
+ {
17
+ label: "Group",
18
+ value: CHANNEL_TYPE.MPIM,
19
+ },
20
+ {
21
+ label: "User / Direct Message",
22
+ value: CHANNEL_TYPE.IM,
23
+ },
24
+ ];
25
+
26
+ export default {
27
+ MAX_RESOURCES,
28
+ LIMIT,
29
+ CHANNEL_TYPE,
30
+ CHANNEL_TYPE_OPTIONS,
31
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@pipedream/slack_v2",
3
+ "version": "0.0.1",
4
+ "description": "Pipedream Slack_v2 Components",
5
+ "main": "slack_v2.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "slack_v2",
9
+ "slack"
10
+ ],
11
+ "homepage": "https://pipedream.com/apps/slack_v2",
12
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "@pipedream/platform": "^3.1.0",
18
+ "@slack/web-api": "^7.9.0",
19
+ "async-retry": "^1.3.3",
20
+ "lodash": "^4.17.21"
21
+ }
22
+ }