Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(slack): add optional Blocks input to Request Action (#16418)

Olivier Sambourg44d53590c59f
diff --git a/packages/pieces/community/slack/package.json b/packages/pieces/community/slack/package.json
index a7a4e8b0195..f6858e64db8 100644
--- a/packages/pieces/community/slack/package.json
+++ b/packages/pieces/community/slack/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-slack",
- "version": "0.22.1",
+ "version": "0.23.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/slack/src/i18n/translation.json b/packages/pieces/community/slack/src/i18n/translation.json
index fa3edbdd879..644f89e0f2d 100644
--- a/packages/pieces/community/slack/src/i18n/translation.json
+++ b/packages/pieces/community/slack/src/i18n/translation.json
@@ -146,6 +146,7 @@
"Icon Emoji": "Icon Emoji",
"Mention Origin Flow": "Mention Origin Flow",
"Block Kit Blocks": "Block Kit Blocks",
+ "Blocks": "Blocks",
"Unfurl Links": "Unfurl Links",
"Message Mode": "Message Mode",
"Recipients": "Recipients",
@@ -273,6 +274,8 @@
"Post as the authenticated user instead of the bot (requires a user token).": "Post as the authenticated user instead of the bot (requires a user token).",
"Enable link unfurling for this message.": "Enable link unfurling for this message.",
"Optional Block Kit blocks array. See https://api.slack.com/block-kit": "Optional Block Kit blocks array. See https://api.slack.com/block-kit",
+ "Optional Block Kit blocks rendered above the action buttons, e.g. dropdowns. Give each interactive element a block_id and action_id so its selection appears under payload.state.values when an action is clicked. Do not use the block_id \"actions\", it is reserved for the action buttons. See https://api.slack.com/block-kit": "Optional Block Kit blocks rendered above the action buttons, e.g. dropdowns. Give each interactive element a block_id and action_id so its selection appears under payload.state.values when an action is clicked. Do not use the block_id \"actions\", it is reserved for the action buttons. See https://api.slack.com/block-kit",
+ "Blocks must be a JSON array": "Blocks must be a JSON array",
"The Slack user ID to DM (e.g. U0123ABCD). Resolve a handle/email to an ID first with Find User by Handle / Find User by Email.": "The Slack user ID to DM (e.g. U0123ABCD). Resolve a handle/email to an ID first with Find User by Handle / Find User by Email.",
"The text of the direct message. Renders as a section above any blocks, and is used as the notification fallback. Leave empty to send blocks only.": "The text of the direct message. Renders as a section above any blocks, and is used as the notification fallback. Leave empty to send blocks only.",
"Channel ID to post to (e.g. C0123ABCD). Resolve a #name with Find Channel.": "Channel ID to post to (e.g. C0123ABCD). Resolve a #name with Find Channel.",
diff --git a/packages/pieces/community/slack/src/lib/actions/request-action-direct-message.ts b/packages/pieces/community/slack/src/lib/actions/request-action-direct-message.ts
index 64bc0856e7f..23d7c569b79 100644
--- a/packages/pieces/community/slack/src/lib/actions/request-action-direct-message.ts
+++ b/packages/pieces/community/slack/src/lib/actions/request-action-direct-message.ts
@@ -8,6 +8,7 @@ import {
username,
actions,
mentionOriginFlow,
+ customBlocks,
} from '../common/props';
import { requestAction } from '../common/request-action';
import { requestActionActionOutputSchema } from '../output-schemas';
@@ -42,6 +43,7 @@ export const requestActionDirectMessageAction = createAction({
userId: userId(true),
text,
actions,
+ blocks: customBlocks,
username,
profilePicture,
mentionOriginFlow,
diff --git a/packages/pieces/community/slack/src/lib/actions/request-action-message.ts b/packages/pieces/community/slack/src/lib/actions/request-action-message.ts
index ad6da16ec69..2e36f532599 100644
--- a/packages/pieces/community/slack/src/lib/actions/request-action-message.ts
+++ b/packages/pieces/community/slack/src/lib/actions/request-action-message.ts
@@ -1,7 +1,7 @@
import { createAction } from '@activepieces/pieces-framework';
import { slackAuth } from '../auth';
import { assertNotNullOrUndefined } from '@activepieces/pieces-framework';
-import { profilePicture, text, slackChannel, onlyBotChannels, username, actions, singleSelectChannelInfo, threadTs, mentionOriginFlow, replyBroadcast } from '../common/props';
+import { profilePicture, text, slackChannel, onlyBotChannels, username, actions, singleSelectChannelInfo, threadTs, mentionOriginFlow, replyBroadcast, customBlocks } from '../common/props';
import { requestAction } from '../common/request-action';
import { requestActionActionOutputSchema } from '../output-schemas';
@@ -41,6 +41,7 @@ export const requestActionMessageAction = createAction({
channel: slackChannel(true),
text,
actions,
+ blocks: customBlocks,
threadTs,
username,
profilePicture,
diff --git a/packages/pieces/community/slack/src/lib/common/props.ts b/packages/pieces/community/slack/src/lib/common/props.ts
index a0b4c9a2441..3af372fbebe 100644
--- a/packages/pieces/community/slack/src/lib/common/props.ts
+++ b/packages/pieces/community/slack/src/lib/common/props.ts
@@ -335,3 +335,11 @@ export const threadCursor = Property.ShortText({
required: false,
advanced: true,
});
+
+export const customBlocks = Property.Json({
+ displayName: 'Blocks',
+ description:
+ 'Optional Block Kit blocks rendered above the action buttons, e.g. dropdowns. Give each interactive element a block_id and action_id so its selection appears under payload.state.values when an action is clicked. Do not use the block_id "actions", it is reserved for the action buttons. See https://api.slack.com/block-kit',
+ required: false,
+ defaultValue: [],
+});
diff --git a/packages/pieces/community/slack/src/lib/common/request-action.ts b/packages/pieces/community/slack/src/lib/common/request-action.ts
index 7e04ea863d4..7cce162d411 100644
--- a/packages/pieces/community/slack/src/lib/common/request-action.ts
+++ b/packages/pieces/community/slack/src/lib/common/request-action.ts
@@ -5,7 +5,7 @@ import {
textToSectionBlocks,
} from './utils';
import { assertNotNullOrUndefined } from '@activepieces/pieces-framework';
-import { ExecutionType } from '@activepieces/pieces-framework';
+import { ExecutionType, isNil } from '@activepieces/pieces-framework';
import { ChatPostMessageResponse } from '@slack/web-api';
import { getBotToken, SlackAuthValue } from './auth-helpers';
@@ -59,6 +59,11 @@ export const requestAction = async (conversationId: string, context: any) => {
},
);
+ const customBlocks = context.propsValue.blocks;
+ if (!isNil(customBlocks) && !Array.isArray(customBlocks)) {
+ throw new Error('Blocks must be a JSON array');
+ }
+
const messageResponse: ChatPostMessageResponse = await slackSendMessage({
token,
text: `${context.propsValue.text}`,
@@ -70,6 +75,7 @@ export const requestAction = async (conversationId: string, context: any) => {
replyBroadcast,
blocks: [
...textToSectionBlocks(`${context.propsValue.text}`),
+ ...(Array.isArray(customBlocks) ? customBlocks : []),
{
type: 'actions',
block_id: 'actions',