-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Slack v2 components #18744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Slack v2 components #18744
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e68de1f
Update Slack actions to support Slack v2 OAuth
js07 2f2719a
pass through as_user unless false and a bot token is available
js07 e5597ae
refactor: simplify special case handling of API error
js07 3aa0773
make addToChannel required for Send Message actions
js07 2126d8e
don't throw error when adding app to channels fails
js07 8eb39ec
delete New Direct Message trigger
js07 ce6dba8
delete the Verify Slack Signature action
js07 8b99a4e
Use assistant search API in Find Message action
js07 2476e2c
Support configuring base URL for Slack API requests
js07 074b23e
update pnpm-lock.yaml
js07 ccc2353
minor refactor of bot token usage
js07 8717ff3
Bump version numbers for Slack components to reflect recent updates
js07 325a164
bump Slack app minor version
js07 18a1e8f
Merge branch 'master' into slack-v2-support
js07 2df5de6
address review feedback
js07 42e6bb2
create Slack v2 app and components from Slack v1
js07 2ae0dcb
Merge branch 'master' into slack-v2-support
js07 fc32b4b
revert changes to the Slack app and components
js07 5dbafa7
revert formatting changes to unrelated app files
js07 135030d
update slack v2 component keys from slack- to slack_v2-
js07 cfeb6ed
add Get Current User action
js07 97ed7f6
revert fallback and message normalization in Find Message action
js07 f417859
update pnpm-lock.yaml
js07 68c8930
apply suggestion to improve performance of realNameLookup method
js07 e9699aa
fix app file imports in add-emoji-reaction.mjs and get-current-user.mjs
js07 8d72c9d
update components to address review comments
js07 ff4b476
revert change to slack update profile action
js07 a49bc76
set "add app to channel" default to false for send message actions
js07 1f27d2b
set default value for as_user prop to true in send-message-to-user-or…
js07 a17e69c
Merge branch 'master' into slack-v2-support
js07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
components/slack_v2/actions/add-emoji-reaction/add-emoji-reaction.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import slack from "../../slack_v2.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "slack_v2-add-emoji-reaction", | ||
| name: "Add Emoji Reaction", | ||
| description: "Add an emoji reaction to a message. [See the documentation](https://api.slack.com/methods/reactions.add)", | ||
| version: "0.0.17", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| slack, | ||
| conversation: { | ||
| propDefinition: [ | ||
| slack, | ||
| "conversation", | ||
| ], | ||
| description: "Channel where the message to add reaction to was posted.", | ||
| }, | ||
| timestamp: { | ||
| propDefinition: [ | ||
| slack, | ||
| "messageTs", | ||
| ], | ||
| description: "Timestamp of the message to add reaction to. e.g. `1403051575.000407`.", | ||
| }, | ||
| icon_emoji: { | ||
| propDefinition: [ | ||
| slack, | ||
| "icon_emoji", | ||
| ], | ||
| description: "Provide an emoji to use as the icon for this reaction. E.g. `fire`", | ||
| optional: false, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.slack.addReactions({ | ||
| channel: this.conversation, | ||
| timestamp: this.timestamp, | ||
| name: this.icon_emoji, | ||
| }); | ||
| $.export("$summary", `Successfully added ${this.icon_emoji} emoji reaction.`); | ||
| return response; | ||
| }, | ||
| }; |
92 changes: 92 additions & 0 deletions
92
components/slack_v2/actions/approve-workflow/approve-workflow.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import slack from "../../slack_v2.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "slack_v2-approve-workflow", | ||
| name: "Approve Workflow", | ||
| description: "Suspend the workflow until approved by a Slack message. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun#flowsuspend)", | ||
| version: "0.0.6", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| slack, | ||
| channelType: { | ||
| type: "string", | ||
| label: "Channel Type", | ||
| description: "The type of channel to send to. User/Direct Message (im), Group (mpim), Private Channel or Public Channel", | ||
| async options() { | ||
| return constants.CHANNEL_TYPE_OPTIONS; | ||
| }, | ||
| }, | ||
| conversation: { | ||
| propDefinition: [ | ||
| slack, | ||
| "conversation", | ||
| (c) => ({ | ||
| types: c.channelType === "Channels" | ||
| ? [ | ||
| constants.CHANNEL_TYPE.PUBLIC, | ||
| constants.CHANNEL_TYPE.PRIVATE, | ||
| ] | ||
| : [ | ||
| c.channelType, | ||
| ], | ||
| }), | ||
| ], | ||
| }, | ||
| message: { | ||
| type: "string", | ||
| label: "Message", | ||
| description: "Text to include with the Approve and Cancel Buttons", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| resume_url, cancel_url, | ||
| } = $.flow.suspend(); | ||
|
|
||
| const response = await this.slack.postChatMessage({ | ||
| text: "Click here to approve or cancel workflow", | ||
| blocks: [ | ||
| { | ||
| type: "section", | ||
| text: { | ||
| type: "mrkdwn", | ||
| text: this.message, | ||
| }, | ||
| }, | ||
| { | ||
| type: "actions", | ||
| elements: [ | ||
| { | ||
| type: "button", | ||
| text: { | ||
| type: "plain_text", | ||
| text: "Approve", | ||
| }, | ||
| style: "primary", | ||
| url: resume_url, | ||
| }, | ||
| { | ||
| type: "button", | ||
| text: { | ||
| type: "plain_text", | ||
| text: "Cancel", | ||
| }, | ||
| style: "danger", | ||
| url: cancel_url, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| channel: this.conversation, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully sent message"); | ||
| return response; | ||
| }, | ||
| }; |
38 changes: 38 additions & 0 deletions
38
components/slack_v2/actions/archive-channel/archive-channel.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import slack from "../../slack_v2.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "slack_v2-archive-channel", | ||
| name: "Archive Channel", | ||
| description: "Archive a channel. [See the documentation](https://api.slack.com/methods/conversations.archive)", | ||
| version: "0.0.25", | ||
| annotations: { | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| slack, | ||
| conversation: { | ||
| propDefinition: [ | ||
| slack, | ||
| "conversation", | ||
| () => ({ | ||
| types: [ | ||
| constants.CHANNEL_TYPE.PUBLIC, | ||
| constants.CHANNEL_TYPE.PRIVATE, | ||
| constants.CHANNEL_TYPE.MPIM, | ||
| ], | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.slack.archiveConversations({ | ||
| channel: this.conversation, | ||
| }); | ||
| $.export("$summary", "Successfully archived channel."); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| import common from "./send-message.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| passArrayOrConfigure: { | ||
| type: "string", | ||
| label: "Add Blocks - Reference Existing Blocks Array or Configure Manually?", | ||
| 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?", | ||
| options: [ | ||
| { | ||
| label: "Reference an array of blocks", | ||
| value: "array", | ||
| }, | ||
| { | ||
| label: "Configure blocks individually (maximum 5 blocks)", | ||
| value: "configure", | ||
| }, | ||
| ], | ||
| optional: true, | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // This adds a visual separator in the props form between each block | ||
| separator() { | ||
| return ` | ||
|
|
||
| --- | ||
|
|
||
| `; | ||
| }, | ||
| createBlockProp(type, label, description) { | ||
| return { | ||
| type, | ||
| label, | ||
| description: `${description} ${this.separator()}`, | ||
| }; | ||
| }, | ||
| createBlock(type, text) { | ||
| if (type === "section") { | ||
| return { | ||
| type: "section", | ||
| text: { | ||
| type: "mrkdwn", | ||
| text, | ||
| }, | ||
| }; | ||
| } else if (type === "context") { | ||
| const elements = Array.isArray(text) | ||
| ? text.map((t) => ({ | ||
| type: "mrkdwn", | ||
| text: t, | ||
| })) | ||
| : [ | ||
| { | ||
| type: "mrkdwn", | ||
| text, | ||
| }, | ||
| ]; | ||
| return { | ||
| type: "context", | ||
| elements, | ||
| }; | ||
| } else if (type === "link_button") { | ||
| const buttons = Object.keys(text).map((buttonText) => ({ | ||
| type: "button", | ||
| text: { | ||
| type: "plain_text", | ||
| text: buttonText, | ||
| emoji: true, | ||
| }, | ||
| url: text[buttonText], // Access the URL using buttonText as the key | ||
| action_id: `actionId-${Math.random().toString(36) | ||
| .substr(2, 9)}`, // Generates a random action_id | ||
| })); | ||
|
|
||
| return { | ||
| type: "actions", | ||
| elements: buttons, | ||
| }; | ||
| } | ||
| }, | ||
| }, | ||
| async additionalProps(existingProps) { | ||
| await common.additionalProps.call(this, existingProps); | ||
| const props = {}; | ||
| 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."; | ||
| 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."; | ||
| 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."; | ||
| const propsSection = this.createBlockProp("string", "Section Block Text", sectionDescription); | ||
| const propsContext = this.createBlockProp("string[]", "Context Block Text", contextDescription); | ||
| const propsLinkButton = this.createBlockProp("object", "Link Button", linkButtonDescription); | ||
|
|
||
| if (!this.passArrayOrConfigure) { | ||
| return props; | ||
| } | ||
| if (this.passArrayOrConfigure === "array") { | ||
| props.blocks = { | ||
| type: common.props.slack.propDefinitions.blocks.type, | ||
| label: common.props.slack.propDefinitions.blocks.label, | ||
| description: common.props.slack.propDefinitions.blocks.description, | ||
| }; | ||
| } else { | ||
| props.blockType = { | ||
| type: "string", | ||
| label: "Block Type", | ||
| description: "Select the type of block to add. Refer to [Slack's docs](https://api.slack.com/reference/block-kit/blocks) for more info.", | ||
| options: [ | ||
| { | ||
| label: "Section", | ||
| value: "section", | ||
| }, | ||
| { | ||
| label: "Context", | ||
| value: "context", | ||
| }, | ||
| { | ||
| label: "Link Button", | ||
| value: "link_button", | ||
| }, | ||
| ], | ||
| reloadProps: true, | ||
| };} | ||
js07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let currentBlockType = this.blockType; | ||
| for (let i = 1; i <= 5; i++) { | ||
| if (currentBlockType === "section") { | ||
| props[`section${i}`] = propsSection; | ||
| } else if (currentBlockType === "context") { | ||
| props[`context${i}`] = propsContext; | ||
| } else if (currentBlockType === "link_button") { | ||
| props[`linkButton${i}`] = propsLinkButton; | ||
| } | ||
|
|
||
| if (i < 5 && currentBlockType) { // Check if currentBlockType is set before adding nextBlockType | ||
| props[`nextBlockType${i}`] = { | ||
| type: "string", | ||
| label: "Next Block Type", | ||
| options: [ | ||
| { | ||
| label: "Section", | ||
| value: "section", | ||
| }, | ||
| { | ||
| label: "Context", | ||
| value: "context", | ||
| }, | ||
| { | ||
| label: "Link Button", | ||
| value: "link_button", | ||
| }, | ||
| ], | ||
| optional: true, | ||
| reloadProps: true, | ||
| }; | ||
| currentBlockType = this[`nextBlockType${i}`]; | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run() { | ||
| let blocks = []; | ||
| if (this.passArrayOrConfigure === "array") { | ||
| blocks = this.blocks; | ||
| } else { | ||
| for (let i = 1; i <= 5; i++) { | ||
| if (this[`section${i}`]) { | ||
| blocks.push(this.createBlock("section", this[`section${i}`])); | ||
| } | ||
|
|
||
| if (this[`context${i}`]) { | ||
| blocks.push(this.createBlock("context", this[`context${i}`])); | ||
| } | ||
|
|
||
| if (this[`linkButton${i}`]) { | ||
| blocks.push(this.createBlock("link_button", this[`linkButton${i}`])); | ||
| } | ||
| } | ||
| } | ||
| return blocks; | ||
| }, | ||
| }; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate
link_buttoninput shape and guard keys.Object.keys(text)will throw iftextisn’t a plain object; also clarify error early.📝 Committable suggestion
🤖 Prompt for AI Agents