Skip to content

Commit 42e6bb2

Browse files
committed
create Slack v2 app and components from Slack v1
1 parent 2df5de6 commit 42e6bb2

File tree

56 files changed

+5169
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5169
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import slack from "../../slack_v2.app.mjs";
2+
3+
export default {
4+
key: "slack-add-emoji-reaction",
5+
name: "Add Emoji Reaction",
6+
description: "Add an emoji reaction to a message. [See 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+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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-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+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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-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+
};
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)