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
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(slack): list only the bot's channels in channel dropdowns (#15907)
Kishan Parmar216541ea95cc
diff --git a/packages/pieces/community/slack/package.json b/packages/pieces/community/slack/package.jsonindex 1576d00a7f0..64c6b3bb81a 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.20.0",+ "version": "0.21.0","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","dependencies": {diff --git a/packages/pieces/community/slack/src/lib/actions/add-reaction-to-message.ts b/packages/pieces/community/slack/src/lib/actions/add-reaction-to-message.tsindex 5eef2f050da..cb0e7f6532f 100644--- a/packages/pieces/community/slack/src/lib/actions/add-reaction-to-message.ts+++ b/packages/pieces/community/slack/src/lib/actions/add-reaction-to-message.ts@@ -1,6 +1,6 @@import { slackAuth } from '../auth';import { createAction, Property } from '@activepieces/pieces-framework';-import { singleSelectChannelInfo, slackChannel, messageTs } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels, messageTs } from '../common/props';import { WebClient } from '@slack/web-api';import { processMessageTimestamp } from '../common/utils';@@ -22,6 +22,7 @@ export const addRectionToMessageAction = createAction({props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),ts: messageTs,reaction: Property.ShortText({diff --git a/packages/pieces/community/slack/src/lib/actions/delete-message.ts b/packages/pieces/community/slack/src/lib/actions/delete-message.tsindex a82d1b04390..379e944021b 100644--- a/packages/pieces/community/slack/src/lib/actions/delete-message.ts+++ b/packages/pieces/community/slack/src/lib/actions/delete-message.ts@@ -1,6 +1,6 @@import { createAction } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { singleSelectChannelInfo, slackChannel, messageTs } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels, messageTs } from '../common/props';import { processMessageTimestamp } from '../common/utils';import { WebClient } from '@slack/web-api';import { requireUserToken, SlackAuthValue } from '../common/auth-helpers';@@ -19,6 +19,7 @@ export const deleteMessageAction = createAction({auth: slackAuth,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),ts: messageTs,},diff --git a/packages/pieces/community/slack/src/lib/actions/get-channel-history.ts b/packages/pieces/community/slack/src/lib/actions/get-channel-history.tsindex 77461b4c681..da4946dcf8c 100644--- a/packages/pieces/community/slack/src/lib/actions/get-channel-history.ts+++ b/packages/pieces/community/slack/src/lib/actions/get-channel-history.ts@@ -1,7 +1,7 @@import { ConversationsHistoryResponse, WebClient } from '@slack/web-api';import { createAction, Property } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { singleSelectChannelInfo, slackChannel } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels } from '../common/props';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';import { channelHistoryActionOutputSchema } from '../output-schemas';@@ -16,6 +16,7 @@ export const getChannelHistory = createAction({outputSchema: channelHistoryActionOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),oldest: Property.Number({displayName: 'Oldest',diff --git a/packages/pieces/community/slack/src/lib/actions/get-message.ts b/packages/pieces/community/slack/src/lib/actions/get-message.tsindex 91c1a508e7d..3ac64559f5a 100644--- a/packages/pieces/community/slack/src/lib/actions/get-message.ts+++ b/packages/pieces/community/slack/src/lib/actions/get-message.ts@@ -1,6 +1,6 @@import { createAction } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { singleSelectChannelInfo, slackChannel, messageTs } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels, messageTs } from '../common/props';import { processMessageTimestamp } from '../common/utils';import { WebClient } from '@slack/web-api';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';@@ -17,6 +17,7 @@ export const getMessageAction = createAction({outputSchema: getMessageActionOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),ts: messageTs,},diff --git a/packages/pieces/community/slack/src/lib/actions/invite-user-to-channel.ts b/packages/pieces/community/slack/src/lib/actions/invite-user-to-channel.tsindex 5d4f553c33b..ec75b68e776 100644--- a/packages/pieces/community/slack/src/lib/actions/invite-user-to-channel.ts+++ b/packages/pieces/community/slack/src/lib/actions/invite-user-to-channel.ts@@ -1,6 +1,6 @@import { slackAuth } from '../auth';import { createAction } from '@activepieces/pieces-framework';-import { singleSelectChannelInfo, slackChannel, userId } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels, userId } from '../common/props';import { WebClient } from '@slack/web-api';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';import { channelResponseOutputSchema } from '../output-schemas';@@ -16,6 +16,7 @@ export const inviteUserToChannelAction = createAction({outputSchema: channelResponseOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),userId: userId(true),},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.tsindex 96233b5cb17..5ccca5f2889 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, username, actions, singleSelectChannelInfo, threadTs, mentionOriginFlow, replyBroadcast } from '../common/props';+import { profilePicture, text, slackChannel, onlyBotChannels, username, actions, singleSelectChannelInfo, threadTs, mentionOriginFlow, replyBroadcast } from '../common/props';import { requestAction } from '../common/request-action';import { requestActionActionOutputSchema } from '../output-schemas';@@ -21,6 +21,7 @@ export const requestActionMessageAction = createAction({outputSchema: requestActionActionOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),text,actions,diff --git a/packages/pieces/community/slack/src/lib/actions/request-approval-message.ts b/packages/pieces/community/slack/src/lib/actions/request-approval-message.tsindex d34dadaf17b..017f0f64688 100644--- a/packages/pieces/community/slack/src/lib/actions/request-approval-message.ts+++ b/packages/pieces/community/slack/src/lib/actions/request-approval-message.ts@@ -6,7 +6,7 @@ import { ExecutionType } from '@activepieces/pieces-framework';import {profilePicture,singleSelectChannelInfo,- slackChannel,+ slackChannel, onlyBotChannels,text,username,mentionOriginFlow,@@ -27,6 +27,7 @@ export const requestSendApprovalMessageAction = createAction({outputSchema: approvalActionOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),text,username,diff --git a/packages/pieces/community/slack/src/lib/actions/retrieve-thread-messages.ts b/packages/pieces/community/slack/src/lib/actions/retrieve-thread-messages.tsindex 34688f8c0e2..6930f90b836 100644--- a/packages/pieces/community/slack/src/lib/actions/retrieve-thread-messages.ts+++ b/packages/pieces/community/slack/src/lib/actions/retrieve-thread-messages.ts@@ -1,7 +1,7 @@import { createAction, Property } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';import { WebClient } from '@slack/web-api';-import { singleSelectChannelInfo, slackChannel, threadCursor } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels, threadCursor } from '../common/props';import { fetchAllThreadReplies, processMessageTimestamp } from '../common/utils';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';import { threadRepliesActionOutputSchema } from '../output-schemas';@@ -17,6 +17,7 @@ export const retrieveThreadMessages = createAction({outputSchema: threadRepliesActionOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),threadTs: Property.ShortText({displayName: 'Thread Timestamp',diff --git a/packages/pieces/community/slack/src/lib/actions/send-message-action.ts b/packages/pieces/community/slack/src/lib/actions/send-message-action.tsindex 349049e51c7..bc21356e0a2 100644--- a/packages/pieces/community/slack/src/lib/actions/send-message-action.ts+++ b/packages/pieces/community/slack/src/lib/actions/send-message-action.ts@@ -1,5 +1,5 @@import { createAction, Property } from '@activepieces/pieces-framework';-import { profilePicture, slackChannel, username, blocks, threadTs, singleSelectChannelInfo, mentionOriginFlow, iconEmoji, replyBroadcast, unfurlLinks } from '../common/props';+import { profilePicture, slackChannel, onlyBotChannels, username, blocks, threadTs, singleSelectChannelInfo, mentionOriginFlow, iconEmoji, replyBroadcast, unfurlLinks } from '../common/props';import { buildFlowOriginContextBlock, processMessageTimestamp, slackSendMessage, textToSectionBlocks } from '../common/utils';import { slackAuth } from '../auth';import { Block,KnownBlock } from '@slack/web-api';@@ -18,6 +18,7 @@ export const slackSendMessageAction = createAction({outputSchema: chatPostMessageOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),text: Property.LongText({displayName: 'Message',diff --git a/packages/pieces/community/slack/src/lib/actions/set-channel-topic.ts b/packages/pieces/community/slack/src/lib/actions/set-channel-topic.tsindex 108fe6c17b9..c75e55a6b69 100644--- a/packages/pieces/community/slack/src/lib/actions/set-channel-topic.ts+++ b/packages/pieces/community/slack/src/lib/actions/set-channel-topic.ts@@ -1,6 +1,6 @@import { slackAuth } from '../auth';import { createAction, Property } from '@activepieces/pieces-framework';-import { singleSelectChannelInfo, slackChannel } from '../common/props';+import { singleSelectChannelInfo, slackChannel, onlyBotChannels } from '../common/props';import { WebClient } from '@slack/web-api';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';import { channelResponseOutputSchema } from '../output-schemas';@@ -16,6 +16,7 @@ export const setChannelTopicAction = createAction({outputSchema: channelResponseOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),topic: Property.LongText({displayName: 'Topic',diff --git a/packages/pieces/community/slack/src/lib/actions/update-message.ts b/packages/pieces/community/slack/src/lib/actions/update-message.tsindex f4219c57c46..818ea6914e3 100644--- a/packages/pieces/community/slack/src/lib/actions/update-message.ts+++ b/packages/pieces/community/slack/src/lib/actions/update-message.ts@@ -1,6 +1,6 @@import { createAction, Property } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { blocks, singleSelectChannelInfo, slackChannel, mentionOriginFlow, messageTs } from '../common/props';+import { blocks, singleSelectChannelInfo, slackChannel, onlyBotChannels, mentionOriginFlow, messageTs } from '../common/props';import { buildFlowOriginContextBlock, processMessageTimestamp, textToSectionBlocks } from '../common/utils';import { Block,KnownBlock, WebClient } from '@slack/web-api';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';@@ -21,6 +21,7 @@ export const updateMessage = createAction({outputSchema: chatUpdateOutputSchema,props: {info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),ts: messageTs,text: Property.LongText({diff --git a/packages/pieces/community/slack/src/lib/actions/upload-file.ts b/packages/pieces/community/slack/src/lib/actions/upload-file.tsindex 7573919a11c..bc45f72b838 100644--- a/packages/pieces/community/slack/src/lib/actions/upload-file.ts+++ b/packages/pieces/community/slack/src/lib/actions/upload-file.ts@@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework';import { slackAuth } from '../auth';import { WebClient } from '@slack/web-api';import {- slackChannel,+ slackChannel, onlyBotChannels,} from '../common/props';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';import { uploadFileActionOutputSchema } from '../output-schemas';@@ -33,6 +33,7 @@ export const uploadFile = createAction({placeholder: 'report.pdf',required: false,}),+ onlyBotChannels,channel: slackChannel(false),},async run(context) {diff --git a/packages/pieces/community/slack/src/lib/common/props.ts b/packages/pieces/community/slack/src/lib/common/props.tsindex 11459fc27b7..a0b4c9a2441 100644--- a/packages/pieces/community/slack/src/lib/common/props.ts+++ b/packages/pieces/community/slack/src/lib/common/props.ts@@ -1,5 +1,5 @@import { MarkdownVariant, Property } from '@activepieces/pieces-framework';-import { UsersListResponse, WebClient } from '@slack/web-api';+import { ConversationsListResponse, UsersConversationsResponse, UsersListResponse, WebClient } from '@slack/web-api';import { slackAuth } from '../auth';import { getBotToken, SlackAuthValue } from '../common/auth-helpers';export const multiSelectChannelInfo = Property.MarkDown({@@ -27,13 +27,13 @@ export const interactivitySetupInfo = Property.MarkDown({});export const slackChannel = <R extends boolean>(required: R) =>- Property.Dropdown<string, R,typeof slackAuth>({+ Property.Dropdown<string, R, typeof slackAuth>({auth: slackAuth,displayName: 'Channel',description: 'Private channels appear only after the bot is added to them.',required,- refreshers: [],- async options({ auth }) {+ refreshers: ['onlyBotChannels'],+ async options({ auth, onlyBotChannels }) {if (!auth) {return {disabled: true,@@ -43,7 +43,7 @@ export const slackChannel = <R extends boolean>(required: R) =>}const accessToken = getBotToken(auth as SlackAuthValue);- const channels = await getChannels(accessToken);+ const channels = await getChannels({ accessToken, onlyBotChannels: onlyBotChannels === true });return {disabled: false,@@ -53,6 +53,39 @@ export const slackChannel = <R extends boolean>(required: R) =>},});+export const onlyBotChannels = Property.Checkbox({+ displayName: 'Only Channels the Bot Is In',+ description: 'Show only channels the bot is a member of.',+ required: false,+ defaultValue: true,+});++export const slackChannels = Property.MultiSelectDropdown<string, false, typeof slackAuth>({+ auth: slackAuth,+ displayName: 'Channels',+ description: 'Empty means every channel the bot is in.',+ required: false,+ refreshers: ['onlyBotChannels'],+ async options({ auth, onlyBotChannels }) {+ if (!auth) {+ return {+ disabled: true,+ placeholder: 'connect slack account',+ options: [],+ };+ }+ const accessToken = getBotToken(auth as SlackAuthValue);++ const channels = await getChannels({ accessToken, onlyBotChannels: onlyBotChannels === true });++ return {+ disabled: false,+ placeholder: 'Select channels',+ options: channels,+ };+ },+});+export const username = Property.ShortText({displayName: 'Username',description: "Overrides the bot's display name for this message.",@@ -259,19 +292,28 @@ export async function getUsers(accessToken: string) {return users;}-export async function getChannels(accessToken: string) {+export async function getChannels({+ accessToken,+ onlyBotChannels,+}: {+ accessToken: string;+ onlyBotChannels?: boolean;+}) {const client = new WebClient(accessToken);const channels: { label: string; value: string }[] = [];const CHANNELS_LIMIT = 2000;- let cursor;+ let cursor: string | undefined;do {- const response = await client.conversations.list({+ const params = {types: 'public_channel,private_channel',exclude_archived: true,limit: 1000,cursor,- });+ };+ const response: ConversationsListResponse | UsersConversationsResponse = onlyBotChannels+ ? await client.users.conversations(params)+ : await client.conversations.list(params);if (response.channels) {channels.push(diff --git a/packages/pieces/community/slack/src/lib/triggers/new-command.ts b/packages/pieces/community/slack/src/lib/triggers/new-command.tsindex eed6668f63b..9ea1a328d89 100644--- a/packages/pieces/community/slack/src/lib/triggers/new-command.ts+++ b/packages/pieces/community/slack/src/lib/triggers/new-command.ts@@ -3,10 +3,10 @@ import {TriggerStrategy,createTrigger,} from '@activepieces/pieces-framework';-import { appWebhookSetupInfo, getChannels, multiSelectChannelInfo, userId } from '../common/props';+import { appWebhookSetupInfo, onlyBotChannels, slackChannels, multiSelectChannelInfo, userId } from '../common/props';import { slackAuth } from '../auth';import { parseCommand } from '../common/utils';-import { getBotToken, getTeamId, SlackAuthValue } from '../common/auth-helpers';+import { getTeamId, SlackAuthValue } from '../common/auth-helpers';import { newCommandTriggerOutputSchema } from '../output-schemas';export const newCommand = createTrigger({@@ -30,29 +30,8 @@ export const newCommand = createTrigger({required: true,defaultValue: ['help'],}),- channels: Property.MultiSelectDropdown({- auth: slackAuth,- displayName: 'Channels',- description: 'Empty means every channel the bot is in.',- required: false,- refreshers: [],- async options({ auth }) {- if (!auth) {- return {- disabled: true,- placeholder: 'connect slack account',- options: [],- };- }- const accessToken = getBotToken(auth as SlackAuthValue);- const channels = await getChannels(accessToken);- return {- disabled: false,- placeholder: 'Select channel',- options: channels,- };- },- }),+ onlyBotChannels,+ channels: slackChannels,ignoreBots: Property.Checkbox({displayName: 'Ignore Bot Messages',description: 'Skip messages posted by bots and apps.',diff --git a/packages/pieces/community/slack/src/lib/triggers/new-mention.ts b/packages/pieces/community/slack/src/lib/triggers/new-mention.tsindex 80b0982bc33..5d16496d4b5 100644--- a/packages/pieces/community/slack/src/lib/triggers/new-mention.ts+++ b/packages/pieces/community/slack/src/lib/triggers/new-mention.ts@@ -3,9 +3,9 @@ import {TriggerStrategy,createTrigger,} from '@activepieces/pieces-framework';-import { appWebhookSetupInfo, getChannels, multiSelectChannelInfo, userIds, usergroupIds } from '../common/props';+import { appWebhookSetupInfo, onlyBotChannels, slackChannels, multiSelectChannelInfo, userIds, usergroupIds } from '../common/props';import { slackAuth } from '../auth';-import { getBotToken, getTeamId, SlackAuthValue } from '../common/auth-helpers';+import { getTeamId, SlackAuthValue } from '../common/auth-helpers';import { newMentionTriggerOutputSchema } from '../output-schemas';export const newMention = createTrigger({@@ -23,29 +23,8 @@ export const newMention = createTrigger({info: multiSelectChannelInfo,users: userIds,usergroups: usergroupIds,- channels: Property.MultiSelectDropdown({- auth: slackAuth,- displayName: 'Channels',- description: 'Empty means every channel the bot is in.',- required: false,- refreshers: [],- async options({ auth }) {- if (!auth) {- return {- disabled: true,- placeholder: 'connect slack account',- options: [],- };- }- const accessToken = getBotToken(auth as SlackAuthValue);- const channels = await getChannels(accessToken);- return {- disabled: false,- placeholder: 'Select channel',- options: channels,- };- },- }),+ onlyBotChannels,+ channels: slackChannels,ignoreBots: Property.Checkbox({displayName: 'Ignore Bot Messages',description: 'Skip messages posted by bots and apps.',diff --git a/packages/pieces/community/slack/src/lib/triggers/new-message-in-channel.ts b/packages/pieces/community/slack/src/lib/triggers/new-message-in-channel.tsindex aa1fe1a1469..6fbc7163a6a 100644--- a/packages/pieces/community/slack/src/lib/triggers/new-message-in-channel.ts+++ b/packages/pieces/community/slack/src/lib/triggers/new-message-in-channel.ts@@ -1,5 +1,5 @@import { Property, TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';-import { appWebhookSetupInfo, singleSelectChannelInfo, slackChannel } from '../common/props';+import { appWebhookSetupInfo, singleSelectChannelInfo, slackChannel, onlyBotChannels } from '../common/props';import { slackAuth } from '../auth';import { getTeamId, SlackAuthValue } from '../common/auth-helpers';import { newMessageInChannelTriggerOutputSchema } from '../output-schemas';@@ -19,6 +19,7 @@ export const newMessageInChannelTrigger = createTrigger({props: {webhookInfo: appWebhookSetupInfo,info: singleSelectChannelInfo,+ onlyBotChannels,channel: slackChannel(true),ignoreBots: Property.Checkbox({displayName: 'Ignore Bot Messages',diff --git a/packages/pieces/community/slack/src/lib/triggers/new-reaction-added.ts b/packages/pieces/community/slack/src/lib/triggers/new-reaction-added.tsindex 47d36e5e516..a4569610a13 100644--- a/packages/pieces/community/slack/src/lib/triggers/new-reaction-added.ts+++ b/packages/pieces/community/slack/src/lib/triggers/new-reaction-added.ts@@ -4,8 +4,8 @@ import {createTrigger,} from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { appWebhookSetupInfo, getChannels, multiSelectChannelInfo, userId } from '../common/props';-import { getBotToken, getTeamId, SlackAuthValue } from '../common/auth-helpers';+import { appWebhookSetupInfo, onlyBotChannels, slackChannels, multiSelectChannelInfo, userId } from '../common/props';+import { getTeamId, SlackAuthValue } from '../common/auth-helpers';import { newReactionAddedTriggerOutputSchema } from '../output-schemas';@@ -28,29 +28,8 @@ export const newReactionAdded = createTrigger({required: false,}),user: userId(false),- channels: Property.MultiSelectDropdown({- auth: slackAuth,- displayName: 'Channels',- description: 'Empty means every channel the bot is in.',- required: false,- refreshers: [],- async options({ auth }) {- if (!auth) {- return {- disabled: true,- placeholder: 'connect slack account',- options: [],- };- }- const accessToken = getBotToken(auth as SlackAuthValue);- const channels = await getChannels(accessToken);- return {- disabled: false,- placeholder: 'Select channels',- options: channels,- };- },- }),+ onlyBotChannels,+ channels: slackChannels,},type: TriggerStrategy.APP_WEBHOOK,sampleData: undefined,diff --git a/packages/pieces/community/slack/src/lib/triggers/new-reaction-removed.ts b/packages/pieces/community/slack/src/lib/triggers/new-reaction-removed.tsindex df011627ce6..88328bb7814 100644--- a/packages/pieces/community/slack/src/lib/triggers/new-reaction-removed.ts+++ b/packages/pieces/community/slack/src/lib/triggers/new-reaction-removed.ts@@ -4,8 +4,8 @@ import {createTrigger,} from '@activepieces/pieces-framework';import { slackAuth } from '../auth';-import { appWebhookSetupInfo, getChannels, multiSelectChannelInfo, userId } from '../common/props';-import { getBotToken, getTeamId, SlackAuthValue } from '../common/auth-helpers';+import { appWebhookSetupInfo, onlyBotChannels, slackChannels, multiSelectChannelInfo, userId } from '../common/props';+import { getTeamId, SlackAuthValue } from '../common/auth-helpers';import { newReactionRemovedTriggerOutputSchema } from '../output-schemas';export const newReactionRemoved = createTrigger({@@ -27,29 +27,8 @@ export const newReactionRemoved = createTrigger({required: false,}),user: userId(false),- channels: Property.MultiSelectDropdown({- auth: slackAuth,- displayName: 'Channels',- description: 'Empty means every channel the bot is in.',- required: false,- refreshers: [],- async options({ auth }) {- if (!auth) {- return {- disabled: true,- placeholder: 'connect slack account',- options: [],- };- }- const accessToken = getBotToken(auth as SlackAuthValue);- const channels = await getChannels(accessToken);- return {- disabled: false,- placeholder: 'Select channels',- options: channels,- };- },- }),+ onlyBotChannels,+ channels: slackChannels,},type: TriggerStrategy.APP_WEBHOOK,sampleData: undefined,diff --git a/packages/pieces/community/slack/test/get-channels.test.ts b/packages/pieces/community/slack/test/get-channels.test.tsnew file mode 100644index 00000000000..d32fdb38038--- /dev/null+++ b/packages/pieces/community/slack/test/get-channels.test.ts@@ -0,0 +1,109 @@+import { AppConnectionType } from '@activepieces/pieces-framework';+import { beforeEach, describe, expect, it, vi } from 'vitest';++const calls: { method: string; params: Record<string, unknown> }[] = [];+let pages: { channels: { id: string; name: string }[]; next?: string }[] = [];++vi.mock('@slack/web-api', () => ({+ WebClient: class {+ conversations = {+ list: async (params: Record<string, unknown>) => nextPage({ method: 'conversations.list', params }),+ };+ users = {+ conversations: async (params: Record<string, unknown>) => nextPage({ method: 'users.conversations', params }),+ };+ },+}));++import { getChannels, onlyBotChannels, slackChannel, slackChannels } from '../src/lib/common/props';++const auth = {+ type: AppConnectionType.CUSTOM_AUTH,+ props: { botToken: 'xoxb-test' },+};++function nextPage(call: { method: string; params: Record<string, unknown> }) {+ calls.push(call);+ const page = pages[calls.length - 1] ?? { channels: [] };+ return { channels: page.channels, response_metadata: { next_cursor: page.next ?? '' } };+}++function channelsOf({ count, prefix }: { count: number; prefix: string }) {+ return Array.from({ length: count }, (_, i) => ({ id: `${prefix}${i}`, name: `${prefix}-${i}` }));+}++describe('channel listing', () => {+ beforeEach(() => {+ calls.length = 0;+ pages = [{ channels: [{ id: 'C1', name: 'general' }] }];+ });++ it('checkbox defaults to on', () => {+ expect(onlyBotChannels.defaultValue).toBe(true);+ });++ it('lists only the bot channels via users.conversations when the toggle is on', async () => {+ const channels = await getChannels({ accessToken: 'xoxb-test', onlyBotChannels: true });++ expect(calls.map((c) => c.method)).toEqual(['users.conversations']);+ expect(channels).toEqual([{ label: 'general', value: 'C1' }]);+ });++ it('lists all channels via conversations.list when the toggle is off or unset', async () => {+ await getChannels({ accessToken: 'xoxb-test', onlyBotChannels: false });+ await getChannels({ accessToken: 'xoxb-test' });++ expect(calls.map((c) => c.method)).toEqual(['conversations.list', 'conversations.list']);+ });++ it('follows next_cursor and stops at the 2000 channel cap', async () => {+ pages = [+ { channels: channelsOf({ count: 1000, prefix: 'A' }), next: 'cursor-1' },+ { channels: channelsOf({ count: 1000, prefix: 'B' }), next: 'cursor-2' },+ { channels: channelsOf({ count: 1000, prefix: 'C' }), next: 'cursor-3' },+ ];++ const channels = await getChannels({ accessToken: 'xoxb-test', onlyBotChannels: true });++ expect(channels).toHaveLength(2000);+ expect(calls).toHaveLength(2);+ expect(calls[1].params.cursor).toBe('cursor-1');+ });++ it('stops when there is no next cursor', async () => {+ pages = [{ channels: channelsOf({ count: 3, prefix: 'A' }) }];++ const channels = await getChannels({ accessToken: 'xoxb-test' });++ expect(channels).toHaveLength(3);+ expect(calls).toHaveLength(1);+ });++ describe.each([+ ['slackChannel', slackChannel(true)],+ ['slackChannels', slackChannels],+ ])('%s dropdown', (_name, prop) => {+ it('refreshes on the toggle', () => {+ expect(prop.refreshers).toEqual(['onlyBotChannels']);+ });++ it('uses users.conversations only when the toggle is exactly true', async () => {+ await prop.options({ auth, onlyBotChannels: true }, {});+ await prop.options({ auth, onlyBotChannels: false }, {});+ await prop.options({ auth }, {});++ expect(calls.map((c) => c.method)).toEqual([+ 'users.conversations',+ 'conversations.list',+ 'conversations.list',+ ]);+ });++ it('is disabled without a connection', async () => {+ const result = await prop.options({ onlyBotChannels: true }, {});++ expect(result.disabled).toBe(true);+ expect(calls).toHaveLength(0);+ });+ });+});