@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.
- package/LICENSE +41 -0
- package/actions/add-emoji-reaction/add-emoji-reaction.mjs +48 -0
- package/actions/approve-workflow/approve-workflow.mjs +92 -0
- package/actions/archive-channel/archive-channel.mjs +38 -0
- package/actions/common/build-blocks.mjs +182 -0
- package/actions/common/send-message.mjs +264 -0
- package/actions/create-channel/create-channel.mjs +40 -0
- package/actions/create-reminder/create-reminder.mjs +52 -0
- package/actions/delete-file/delete-file.mjs +39 -0
- package/actions/delete-message/delete-message.mjs +45 -0
- package/actions/find-message/find-message.mjs +83 -0
- package/actions/find-user-by-email/find-user-by-email.mjs +32 -0
- package/actions/get-current-user/get-current-user.mjs +68 -0
- package/actions/get-file/get-file.mjs +59 -0
- package/actions/invite-user-to-channel/invite-user-to-channel.mjs +45 -0
- package/actions/kick-user/kick-user.mjs +56 -0
- package/actions/list-channels/list-channels.mjs +52 -0
- package/actions/list-files/list-files.mjs +93 -0
- package/actions/list-group-members/list-group-members.mjs +68 -0
- package/actions/list-members-in-channel/list-members-in-channel.mjs +71 -0
- package/actions/list-replies/list-replies.mjs +74 -0
- package/actions/list-users/list-users.mjs +60 -0
- package/actions/reply-to-a-message/reply-to-a-message.mjs +54 -0
- package/actions/send-block-kit-message/send-block-kit-message.mjs +48 -0
- package/actions/send-large-message/send-large-message.mjs +95 -0
- package/actions/send-message/send-message.mjs +56 -0
- package/actions/send-message-advanced/send-message-advanced.mjs +75 -0
- package/actions/send-message-to-channel/send-message-to-channel.mjs +45 -0
- package/actions/send-message-to-user-or-group/send-message-to-user-or-group.mjs +93 -0
- package/actions/set-channel-description/set-channel-description.mjs +37 -0
- package/actions/set-channel-topic/set-channel-topic.mjs +37 -0
- package/actions/set-status/set-status.mjs +49 -0
- package/actions/update-group-members/update-group-members.mjs +72 -0
- package/actions/update-message/update-message.mjs +59 -0
- package/actions/update-profile/update-profile.mjs +94 -0
- package/actions/upload-file/upload-file.mjs +104 -0
- package/common/constants.mjs +31 -0
- package/package.json +22 -0
- package/slack_v2.app.mjs +1112 -0
- package/sources/common/base.mjs +184 -0
- package/sources/common/constants.mjs +58 -0
- package/sources/new-channel-created/new-channel-created.mjs +32 -0
- package/sources/new-channel-created/test-event.mjs +44 -0
- package/sources/new-interaction-event-received/README.md +85 -0
- package/sources/new-interaction-event-received/new-interaction-event-received.mjs +105 -0
- package/sources/new-interaction-event-received/test-event.mjs +86 -0
- package/sources/new-keyword-mention/new-keyword-mention.mjs +99 -0
- package/sources/new-keyword-mention/test-event.mjs +28 -0
- package/sources/new-message-in-channels/new-message-in-channels.mjs +106 -0
- package/sources/new-message-in-channels/test-event.mjs +45 -0
- package/sources/new-reaction-added/new-reaction-added.mjs +119 -0
- package/sources/new-reaction-added/test-event.mjs +193 -0
- package/sources/new-saved-message/new-saved-message.mjs +32 -0
- package/sources/new-saved-message/test-event.mjs +37 -0
- package/sources/new-user-added/new-user-added.mjs +32 -0
- package/sources/new-user-added/test-event.mjs +48 -0
- package/sources/new-user-mention/new-user-mention.mjs +124 -0
- package/sources/new-user-mention/test-event.mjs +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Pipedream Source Available License Version 1.0
|
|
2
|
+
|
|
3
|
+
This Pipedream Source Available License Agreement Version 1.0 (this “Agreement”) sets forth the terms on which Pipedream, Inc., a Delaware corporation (“Pipedream”) makes available certain software (the “Software”). By installing, downloading, accessing, using or distributing the Software, you agree to the terms of this Agreement. If you do not agree to such terms, you must not use the Software. If you are receiving the Software on behalf of a legal entity, you represent and warrant that you have the actual authority to agree to the terms and conditions of this Agreement on behalf of such entity. “Licensee” means you, an individual, or the entity on whose behalf you are receiving the Software.
|
|
4
|
+
|
|
5
|
+
LICENSE GRANT AND CONDITIONS.
|
|
6
|
+
|
|
7
|
+
1.1 License. Subject to the terms and conditions of this Agreement, Pipedream hereby grants to Licensee a non-exclusive, royalty-free, worldwide, non-transferable, non-sublicenseable license during the term of this Agreement to use, prepare modifications and derivative works, distribute (including without limitation in source code or object code form) and reproduce copies of the Software (the “License”). Licensee is not granted the right to, and Licensee shall not, exercise the License for an Excluded Purpose. For purposes of this Agreement, “Excluded Purpose” means any commercial use of the software including, but not limited to, making available any software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other online service that competes with the Software or any other Pipedream products or services.
|
|
8
|
+
|
|
9
|
+
1.2 Conditions. In consideration of the License, Licensee’s distribution of the Software is subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
a. Licensee must cause any Software modified by Licensee to carry prominent notices stating that Licensee modified the Software.
|
|
12
|
+
|
|
13
|
+
b. On each Software copy, Licensee shall reproduce and not remove or alter all Pipedream or third party copyright or other proprietary notices contained in the Software, and Licensee must provide this with each copy: “This software is made available by Pipedream, Inc., under the terms of the Pipedream Source Available License, Version 1.0 located at https://github.com/PipedreamHQ/pipedream/blob/master/LICENSE. By installing, downloading, accessing, using or distributing the Software, you agree to the terms of such License Agreement.”
|
|
14
|
+
|
|
15
|
+
1.3 Modifications. Licensee may add its own copyright notices to modifications made by Licensee and may provide additional or different license terms and conditions for use, reproduction, or distribution of Licensee’s modifications. While redistributing the Software or modifications thereof, Licensee may choose to offer, for a fee or free of charge, support, warranty, indemnity, or other obligations. Licensee, and not Pipedream, will be responsible for any such obligations.
|
|
16
|
+
|
|
17
|
+
1.4 No Sublicensing. The License does not include the right to sublicense the Software; provided, however, that any recipient to which Licensee provides the Software may exercise the License so long as such recipient agrees to the terms and conditions of this Agreement.
|
|
18
|
+
|
|
19
|
+
TERM AND TERMINATION.
|
|
20
|
+
|
|
21
|
+
This Agreement will continue unless and until earlier terminated as set forth herein. If Licensee breaches any of its conditions or obligations under this Agreement, this Agreement will terminate automatically and the License will terminate automatically and permanently.
|
|
22
|
+
|
|
23
|
+
INTELLECTUAL PROPERTY.
|
|
24
|
+
|
|
25
|
+
As between the parties, Pipedream retains all right, title, and interest in the Software, and all intellectual property rights therein. Pipedream hereby reserves all rights not expressly granted to Licensee in this Agreement. Pipedream reserves all rights in its trademarks and service marks, and no licenses thereto are granted by this Agreement.
|
|
26
|
+
|
|
27
|
+
DISCLAIMER.
|
|
28
|
+
|
|
29
|
+
PIPEDREAM HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE.
|
|
30
|
+
|
|
31
|
+
LIMITATION OF LIABILITY.
|
|
32
|
+
|
|
33
|
+
PIPEDREAM WILL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW.
|
|
34
|
+
|
|
35
|
+
GENERAL.
|
|
36
|
+
|
|
37
|
+
6.1 Governing Law. This Agreement will be governed by and interpreted in accordance with the laws of the state of California, without reference to its conflict of laws principles. If Licensee is located outside of the United States, any dispute, controversy or claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in accordance with the JAMS International Arbitration Rules. The tribunal will consist of one arbitrator. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction thereof. All disputes including arbitrations shall take place in Santa Clara County, California. The language to be used in any such proceedings shall be English.
|
|
38
|
+
|
|
39
|
+
6.2. Assignment. Licensee is not authorized to assign its rights under this Agreement to any third party. Pipedream may freely assign its rights under this Agreement to any third party.
|
|
40
|
+
|
|
41
|
+
6.3. Other. This Agreement is the entire agreement between the parties regarding the subject matter hereof. No amendment or modification of this Agreement will be valid or binding upon the parties unless made in writing and signed by the duly authorized representatives of both parties. In the event that any provision, including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and all licenses and rights granted hereunder will immediately terminate. Waiver by Pipedream of a breach of any provision of this Agreement or the failure by Pipedream to exercise any right hereunder will not be construed as a waiver of any subsequent breach of that right or as a waiver of any other right.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import slack from "../../slack_v2.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "slack_v2-add-emoji-reaction",
|
|
5
|
+
name: "Add Emoji Reaction",
|
|
6
|
+
description: "Add an emoji reaction to a message. [See the documentation](https://api.slack.com/methods/reactions.add)",
|
|
7
|
+
version: "0.0.17",
|
|
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
|
+
description: "Channel where the message to add reaction to was posted.",
|
|
22
|
+
},
|
|
23
|
+
timestamp: {
|
|
24
|
+
propDefinition: [
|
|
25
|
+
slack,
|
|
26
|
+
"messageTs",
|
|
27
|
+
],
|
|
28
|
+
description: "Timestamp of the message to add reaction to. e.g. `1403051575.000407`.",
|
|
29
|
+
},
|
|
30
|
+
icon_emoji: {
|
|
31
|
+
propDefinition: [
|
|
32
|
+
slack,
|
|
33
|
+
"icon_emoji",
|
|
34
|
+
],
|
|
35
|
+
description: "Provide an emoji to use as the icon for this reaction. E.g. `fire`",
|
|
36
|
+
optional: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
async run({ $ }) {
|
|
40
|
+
const response = await this.slack.addReactions({
|
|
41
|
+
channel: this.conversation,
|
|
42
|
+
timestamp: this.timestamp,
|
|
43
|
+
name: this.icon_emoji,
|
|
44
|
+
});
|
|
45
|
+
$.export("$summary", `Successfully added ${this.icon_emoji} emoji reaction.`);
|
|
46
|
+
return response;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import slack from "../../slack_v2.app.mjs";
|
|
2
|
+
import constants from "../../common/constants.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "slack_v2-approve-workflow",
|
|
6
|
+
name: "Approve Workflow",
|
|
7
|
+
description: "Suspend the workflow until approved by a Slack message. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun#flowsuspend)",
|
|
8
|
+
version: "0.0.6",
|
|
9
|
+
annotations: {
|
|
10
|
+
destructiveHint: false,
|
|
11
|
+
openWorldHint: true,
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
},
|
|
14
|
+
type: "action",
|
|
15
|
+
props: {
|
|
16
|
+
slack,
|
|
17
|
+
channelType: {
|
|
18
|
+
type: "string",
|
|
19
|
+
label: "Channel Type",
|
|
20
|
+
description: "The type of channel to send to. User/Direct Message (im), Group (mpim), Private Channel or Public Channel",
|
|
21
|
+
async options() {
|
|
22
|
+
return constants.CHANNEL_TYPE_OPTIONS;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
conversation: {
|
|
26
|
+
propDefinition: [
|
|
27
|
+
slack,
|
|
28
|
+
"conversation",
|
|
29
|
+
(c) => ({
|
|
30
|
+
types: c.channelType === "Channels"
|
|
31
|
+
? [
|
|
32
|
+
constants.CHANNEL_TYPE.PUBLIC,
|
|
33
|
+
constants.CHANNEL_TYPE.PRIVATE,
|
|
34
|
+
]
|
|
35
|
+
: [
|
|
36
|
+
c.channelType,
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
message: {
|
|
42
|
+
type: "string",
|
|
43
|
+
label: "Message",
|
|
44
|
+
description: "Text to include with the Approve and Cancel Buttons",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
async run({ $ }) {
|
|
48
|
+
const {
|
|
49
|
+
resume_url, cancel_url,
|
|
50
|
+
} = $.flow.suspend();
|
|
51
|
+
|
|
52
|
+
const response = await this.slack.postChatMessage({
|
|
53
|
+
text: "Click here to approve or cancel workflow",
|
|
54
|
+
blocks: [
|
|
55
|
+
{
|
|
56
|
+
type: "section",
|
|
57
|
+
text: {
|
|
58
|
+
type: "mrkdwn",
|
|
59
|
+
text: this.message,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "actions",
|
|
64
|
+
elements: [
|
|
65
|
+
{
|
|
66
|
+
type: "button",
|
|
67
|
+
text: {
|
|
68
|
+
type: "plain_text",
|
|
69
|
+
text: "Approve",
|
|
70
|
+
},
|
|
71
|
+
style: "primary",
|
|
72
|
+
url: resume_url,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "button",
|
|
76
|
+
text: {
|
|
77
|
+
type: "plain_text",
|
|
78
|
+
text: "Cancel",
|
|
79
|
+
},
|
|
80
|
+
style: "danger",
|
|
81
|
+
url: cancel_url,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
channel: this.conversation,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
$.export("$summary", "Successfully sent message");
|
|
90
|
+
return response;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import slack from "../../slack_v2.app.mjs";
|
|
2
|
+
import constants from "../../common/constants.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "slack_v2-archive-channel",
|
|
6
|
+
name: "Archive Channel",
|
|
7
|
+
description: "Archive a channel. [See the documentation](https://api.slack.com/methods/conversations.archive)",
|
|
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
|
+
conversation: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
slack,
|
|
20
|
+
"conversation",
|
|
21
|
+
() => ({
|
|
22
|
+
types: [
|
|
23
|
+
constants.CHANNEL_TYPE.PUBLIC,
|
|
24
|
+
constants.CHANNEL_TYPE.PRIVATE,
|
|
25
|
+
constants.CHANNEL_TYPE.MPIM,
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
async run({ $ }) {
|
|
32
|
+
const response = await this.slack.archiveConversations({
|
|
33
|
+
channel: this.conversation,
|
|
34
|
+
});
|
|
35
|
+
$.export("$summary", "Successfully archived channel.");
|
|
36
|
+
return response;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import common from "./send-message.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
props: {
|
|
5
|
+
passArrayOrConfigure: {
|
|
6
|
+
type: "string",
|
|
7
|
+
label: "Add Blocks - Reference Existing Blocks Array or Configure Manually?",
|
|
8
|
+
description: "Would you like to reference an array of blocks from a previous step (for example, `{{steps.blocks.$return_value}}`), or configure them in this action?",
|
|
9
|
+
options: [
|
|
10
|
+
{
|
|
11
|
+
label: "Reference an array of blocks",
|
|
12
|
+
value: "array",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: "Configure blocks individually (maximum 5 blocks)",
|
|
16
|
+
value: "configure",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
optional: true,
|
|
20
|
+
reloadProps: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
methods: {
|
|
24
|
+
// This adds a visual separator in the props form between each block
|
|
25
|
+
separator() {
|
|
26
|
+
return `
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
`;
|
|
31
|
+
},
|
|
32
|
+
createBlockProp(type, label, description) {
|
|
33
|
+
return {
|
|
34
|
+
type,
|
|
35
|
+
label,
|
|
36
|
+
description: `${description} ${this.separator()}`,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
createBlock(type, text) {
|
|
40
|
+
if (type === "section") {
|
|
41
|
+
return {
|
|
42
|
+
type: "section",
|
|
43
|
+
text: {
|
|
44
|
+
type: "mrkdwn",
|
|
45
|
+
text,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
} else if (type === "context") {
|
|
49
|
+
const elements = Array.isArray(text)
|
|
50
|
+
? text.map((t) => ({
|
|
51
|
+
type: "mrkdwn",
|
|
52
|
+
text: t,
|
|
53
|
+
}))
|
|
54
|
+
: [
|
|
55
|
+
{
|
|
56
|
+
type: "mrkdwn",
|
|
57
|
+
text,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
return {
|
|
61
|
+
type: "context",
|
|
62
|
+
elements,
|
|
63
|
+
};
|
|
64
|
+
} else if (type === "link_button") {
|
|
65
|
+
const buttons = Object.keys(text).map((buttonText) => ({
|
|
66
|
+
type: "button",
|
|
67
|
+
text: {
|
|
68
|
+
type: "plain_text",
|
|
69
|
+
text: buttonText,
|
|
70
|
+
emoji: true,
|
|
71
|
+
},
|
|
72
|
+
url: text[buttonText], // Access the URL using buttonText as the key
|
|
73
|
+
action_id: `actionId-${Math.random().toString(36)
|
|
74
|
+
.substr(2, 9)}`, // Generates a random action_id
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
type: "actions",
|
|
79
|
+
elements: buttons,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
async additionalProps(existingProps) {
|
|
85
|
+
await common.additionalProps.call(this, existingProps);
|
|
86
|
+
const props = {};
|
|
87
|
+
const sectionDescription = "Add a **section** block to your message and configure with plain text or mrkdwn. See [Slack's docs](https://api.slack.com/reference/block-kit/blocks?ref=bk#section) for more info.";
|
|
88
|
+
const contextDescription = "Add a **context** block to your message and configure with plain text or mrkdwn. Define multiple items if you'd like multiple elements in the context block. See [Slack's docs](https://api.slack.com/reference/block-kit/blocks?ref=bk#context) for more info.";
|
|
89
|
+
const linkButtonDescription = "Add a **link button** to your message. Enter the button text as the key and the link URL as the value. Configure multiple buttons in the array to render them inline, or add additional Button Link blocks to render them vertically. See [Slack's docs](https://api.slack.com/reference/block-kit/blocks?ref=bk#actions) for more info.";
|
|
90
|
+
const propsSection = this.createBlockProp("string", "Section Block Text", sectionDescription);
|
|
91
|
+
const propsContext = this.createBlockProp("string[]", "Context Block Text", contextDescription);
|
|
92
|
+
const propsLinkButton = this.createBlockProp("object", "Link Button", linkButtonDescription);
|
|
93
|
+
|
|
94
|
+
if (!this.passArrayOrConfigure) {
|
|
95
|
+
return props;
|
|
96
|
+
}
|
|
97
|
+
if (this.passArrayOrConfigure === "array") {
|
|
98
|
+
props.blocks = {
|
|
99
|
+
type: common.props.slack.propDefinitions.blocks.type,
|
|
100
|
+
label: common.props.slack.propDefinitions.blocks.label,
|
|
101
|
+
description: common.props.slack.propDefinitions.blocks.description,
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
props.blockType = {
|
|
105
|
+
type: "string",
|
|
106
|
+
label: "Block Type",
|
|
107
|
+
description: "Select the type of block to add. Refer to [Slack's docs](https://api.slack.com/reference/block-kit/blocks) for more info.",
|
|
108
|
+
options: [
|
|
109
|
+
{
|
|
110
|
+
label: "Section",
|
|
111
|
+
value: "section",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
label: "Context",
|
|
115
|
+
value: "context",
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
label: "Link Button",
|
|
119
|
+
value: "link_button",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
reloadProps: true,
|
|
123
|
+
};}
|
|
124
|
+
let currentBlockType = this.blockType;
|
|
125
|
+
for (let i = 1; i <= 5; i++) {
|
|
126
|
+
if (currentBlockType === "section") {
|
|
127
|
+
props[`section${i}`] = propsSection;
|
|
128
|
+
} else if (currentBlockType === "context") {
|
|
129
|
+
props[`context${i}`] = propsContext;
|
|
130
|
+
} else if (currentBlockType === "link_button") {
|
|
131
|
+
props[`linkButton${i}`] = propsLinkButton;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (i < 5 && currentBlockType) { // Check if currentBlockType is set before adding nextBlockType
|
|
135
|
+
props[`nextBlockType${i}`] = {
|
|
136
|
+
type: "string",
|
|
137
|
+
label: "Next Block Type",
|
|
138
|
+
options: [
|
|
139
|
+
{
|
|
140
|
+
label: "Section",
|
|
141
|
+
value: "section",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
label: "Context",
|
|
145
|
+
value: "context",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
label: "Link Button",
|
|
149
|
+
value: "link_button",
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
optional: true,
|
|
153
|
+
reloadProps: true,
|
|
154
|
+
};
|
|
155
|
+
currentBlockType = this[`nextBlockType${i}`];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return props;
|
|
159
|
+
},
|
|
160
|
+
async run() {
|
|
161
|
+
let blocks = [];
|
|
162
|
+
if (this.passArrayOrConfigure === "array") {
|
|
163
|
+
blocks = this.blocks;
|
|
164
|
+
} else {
|
|
165
|
+
for (let i = 1; i <= 5; i++) {
|
|
166
|
+
if (this[`section${i}`]) {
|
|
167
|
+
blocks.push(this.createBlock("section", this[`section${i}`]));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (this[`context${i}`]) {
|
|
171
|
+
blocks.push(this.createBlock("context", this[`context${i}`]));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this[`linkButton${i}`]) {
|
|
175
|
+
blocks.push(this.createBlock("link_button", this[`linkButton${i}`]));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return blocks;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import slack from "../../slack_v2.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
props: {
|
|
5
|
+
slack,
|
|
6
|
+
as_user: {
|
|
7
|
+
propDefinition: [
|
|
8
|
+
slack,
|
|
9
|
+
"as_user",
|
|
10
|
+
],
|
|
11
|
+
},
|
|
12
|
+
addToChannel: {
|
|
13
|
+
propDefinition: [
|
|
14
|
+
slack,
|
|
15
|
+
"addToChannel",
|
|
16
|
+
],
|
|
17
|
+
description: "If `true`, the app will be added to the specified non-DM channel(s) automatically. If `false`, you must add the app to the channel manually to post to a private channel as a bot. Defaults to `false`.",
|
|
18
|
+
default: false,
|
|
19
|
+
},
|
|
20
|
+
post_at: {
|
|
21
|
+
propDefinition: [
|
|
22
|
+
slack,
|
|
23
|
+
"post_at",
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
include_sent_via_pipedream_flag: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
optional: true,
|
|
29
|
+
default: true,
|
|
30
|
+
label: "Include link to Pipedream",
|
|
31
|
+
description: "Defaults to `true`, includes a link to Pipedream at the end of your Slack message.",
|
|
32
|
+
},
|
|
33
|
+
customizeBotSettings: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
label: "Customize Bot Settings",
|
|
36
|
+
description: "Customize the username and/or icon of the Bot",
|
|
37
|
+
optional: true,
|
|
38
|
+
reloadProps: true,
|
|
39
|
+
},
|
|
40
|
+
username: {
|
|
41
|
+
propDefinition: [
|
|
42
|
+
slack,
|
|
43
|
+
"username",
|
|
44
|
+
],
|
|
45
|
+
hidden: true,
|
|
46
|
+
},
|
|
47
|
+
icon_emoji: {
|
|
48
|
+
propDefinition: [
|
|
49
|
+
slack,
|
|
50
|
+
"icon_emoji",
|
|
51
|
+
],
|
|
52
|
+
hidden: true,
|
|
53
|
+
},
|
|
54
|
+
icon_url: {
|
|
55
|
+
propDefinition: [
|
|
56
|
+
slack,
|
|
57
|
+
"icon_url",
|
|
58
|
+
],
|
|
59
|
+
hidden: true,
|
|
60
|
+
},
|
|
61
|
+
replyToThread: {
|
|
62
|
+
type: "boolean",
|
|
63
|
+
label: "Reply to Thread",
|
|
64
|
+
description: "Reply to an existing thread",
|
|
65
|
+
optional: true,
|
|
66
|
+
reloadProps: true,
|
|
67
|
+
},
|
|
68
|
+
thread_ts: {
|
|
69
|
+
propDefinition: [
|
|
70
|
+
slack,
|
|
71
|
+
"messageTs",
|
|
72
|
+
],
|
|
73
|
+
description: "Provide another message's `ts` value to make this message a reply (e.g., if triggering on new Slack messages, enter `{{event.ts}}`). Avoid using a reply's `ts` value; use its parent instead. e.g. `1403051575.000407`.",
|
|
74
|
+
optional: true,
|
|
75
|
+
hidden: true,
|
|
76
|
+
},
|
|
77
|
+
thread_broadcast: {
|
|
78
|
+
propDefinition: [
|
|
79
|
+
slack,
|
|
80
|
+
"thread_broadcast",
|
|
81
|
+
],
|
|
82
|
+
hidden: true,
|
|
83
|
+
},
|
|
84
|
+
addMessageMetadata: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
label: "Add Message Metadata",
|
|
87
|
+
description: "Set the metadata event type and payload",
|
|
88
|
+
optional: true,
|
|
89
|
+
reloadProps: true,
|
|
90
|
+
},
|
|
91
|
+
metadata_event_type: {
|
|
92
|
+
propDefinition: [
|
|
93
|
+
slack,
|
|
94
|
+
"metadata_event_type",
|
|
95
|
+
],
|
|
96
|
+
hidden: true,
|
|
97
|
+
},
|
|
98
|
+
metadata_event_payload: {
|
|
99
|
+
propDefinition: [
|
|
100
|
+
slack,
|
|
101
|
+
"metadata_event_payload",
|
|
102
|
+
],
|
|
103
|
+
hidden: true,
|
|
104
|
+
},
|
|
105
|
+
configureUnfurlSettings: {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
label: "Configure Unfurl Settings",
|
|
108
|
+
description: "Configure settings for unfurling links and media",
|
|
109
|
+
optional: true,
|
|
110
|
+
reloadProps: true,
|
|
111
|
+
},
|
|
112
|
+
unfurl_links: {
|
|
113
|
+
propDefinition: [
|
|
114
|
+
slack,
|
|
115
|
+
"unfurl_links",
|
|
116
|
+
],
|
|
117
|
+
hidden: true,
|
|
118
|
+
},
|
|
119
|
+
unfurl_media: {
|
|
120
|
+
propDefinition: [
|
|
121
|
+
slack,
|
|
122
|
+
"unfurl_media",
|
|
123
|
+
],
|
|
124
|
+
hidden: true,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
async additionalProps(props) {
|
|
128
|
+
if (this.conversation && this.replyToThread) {
|
|
129
|
+
props.thread_ts.hidden = false;
|
|
130
|
+
props.thread_broadcast.hidden = false;
|
|
131
|
+
}
|
|
132
|
+
if (this.customizeBotSettings) {
|
|
133
|
+
props.username.hidden = false;
|
|
134
|
+
props.icon_emoji.hidden = false;
|
|
135
|
+
props.icon_url.hidden = false;
|
|
136
|
+
}
|
|
137
|
+
if (this.addMessageMetadata) {
|
|
138
|
+
props.metadata_event_type.hidden = false;
|
|
139
|
+
props.metadata_event_payload.hidden = false;
|
|
140
|
+
}
|
|
141
|
+
if (this.configureUnfurlSettings) {
|
|
142
|
+
props.unfurl_links.hidden = false;
|
|
143
|
+
props.unfurl_media.hidden = false;
|
|
144
|
+
}
|
|
145
|
+
return {};
|
|
146
|
+
},
|
|
147
|
+
methods: {
|
|
148
|
+
_makeSentViaPipedreamBlock() {
|
|
149
|
+
const workflowId = process.env.PIPEDREAM_WORKFLOW_ID;
|
|
150
|
+
const baseLink = "https://pipedream.com";
|
|
151
|
+
const linkText = !workflowId
|
|
152
|
+
? "Pipedream Connect"
|
|
153
|
+
: "Pipedream";
|
|
154
|
+
|
|
155
|
+
const link = !workflowId
|
|
156
|
+
? `${baseLink}/connect`
|
|
157
|
+
: `${baseLink}/@/${workflowId}?o=a&a=slack`;
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
"type": "context",
|
|
161
|
+
"elements": [
|
|
162
|
+
{
|
|
163
|
+
"type": "mrkdwn",
|
|
164
|
+
"text": `Sent via <${link}|${linkText}>`,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
_makeTextBlock(mrkdwn = true) {
|
|
170
|
+
const { text } = this;
|
|
171
|
+
let serializedText = text;
|
|
172
|
+
// The Slack SDK expects the value of text's "text" property to be a string. If this.text is
|
|
173
|
+
// anything other than string, number, or boolean, then encode it as a JSON string.
|
|
174
|
+
if (typeof text !== "string" && typeof text !== "number" && typeof text !== "boolean") {
|
|
175
|
+
serializedText = JSON.stringify(text);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
"type": "section",
|
|
179
|
+
"text": {
|
|
180
|
+
"type": mrkdwn
|
|
181
|
+
? "mrkdwn"
|
|
182
|
+
: "plain_text",
|
|
183
|
+
"text": serializedText,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
getChannelId() {
|
|
188
|
+
return this.conversation ?? this.reply_channel;
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
async run({ $ }) {
|
|
192
|
+
const channelId = await this.getChannelId();
|
|
193
|
+
|
|
194
|
+
if (this.addToChannel) {
|
|
195
|
+
await this.slack.maybeAddAppToChannels([
|
|
196
|
+
channelId,
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let blocks = this.blocks;
|
|
201
|
+
|
|
202
|
+
if (!blocks) {
|
|
203
|
+
blocks = [
|
|
204
|
+
this._makeTextBlock(this.mrkdwn),
|
|
205
|
+
];
|
|
206
|
+
} else if (typeof blocks === "string") {
|
|
207
|
+
blocks = JSON.parse(blocks);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (this.include_sent_via_pipedream_flag) {
|
|
211
|
+
const sentViaPipedreamText = this._makeSentViaPipedreamBlock();
|
|
212
|
+
blocks.push(sentViaPipedreamText);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let metadataEventPayload;
|
|
216
|
+
|
|
217
|
+
if (this.metadata_event_type) {
|
|
218
|
+
|
|
219
|
+
if (typeof this.metadata_event_payload === "string") {
|
|
220
|
+
try {
|
|
221
|
+
metadataEventPayload = JSON.parse(this.metadata_event_payload);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
throw new Error(`Invalid JSON in metadata_event_payload: ${error.message}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
this.metadata = {
|
|
228
|
+
event_type: this.metadata_event_type,
|
|
229
|
+
event_payload: metadataEventPayload,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const obj = {
|
|
234
|
+
text: this.text,
|
|
235
|
+
channel: channelId,
|
|
236
|
+
attachments: this.attachments,
|
|
237
|
+
unfurl_links: this.unfurl_links,
|
|
238
|
+
unfurl_media: this.unfurl_media,
|
|
239
|
+
parse: this.parse,
|
|
240
|
+
as_user: this.as_user,
|
|
241
|
+
username: this.username,
|
|
242
|
+
icon_emoji: this.icon_emoji,
|
|
243
|
+
icon_url: this.icon_url,
|
|
244
|
+
mrkdwn: this.mrkdwn,
|
|
245
|
+
blocks,
|
|
246
|
+
link_names: this.link_names,
|
|
247
|
+
reply_broadcast: this.thread_broadcast,
|
|
248
|
+
thread_ts: this.thread_ts,
|
|
249
|
+
metadata: this.metadata || null,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
if (this.post_at) {
|
|
253
|
+
obj.post_at = Math.floor(new Date(this.post_at).getTime() / 1000);
|
|
254
|
+
return await this.slack.scheduleMessage(obj);
|
|
255
|
+
}
|
|
256
|
+
const resp = await this.slack.postChatMessage(obj);
|
|
257
|
+
const { channel } = await this.slack.conversationsInfo({
|
|
258
|
+
channel: resp.channel,
|
|
259
|
+
});
|
|
260
|
+
const channelName = await this.slack.getChannelDisplayName(channel);
|
|
261
|
+
$.export("$summary", `Successfully sent a message to ${channelName}`);
|
|
262
|
+
return resp;
|
|
263
|
+
},
|
|
264
|
+
};
|