Skip to content

Commit 0530f7d

Browse files
committed
feat(slack): allow multi channel filter for new message trigger
1 parent cfaa02e commit 0530f7d

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

packages/pieces/community/slack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@activepieces/piece-slack",
3-
"version": "0.10.15",
3+
"version": "0.10.16",
44
"dependencies": {
55
"@slack/web-api": "7.9.0",
66
"slackify-markdown": "4.4.0"

packages/pieces/community/slack/src/lib/triggers/new-message-in-channel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { getFirstFiveOrAll } from '../common/utils';
1010
export const newMessageInChannelTrigger = createTrigger({
1111
auth: slackAuth,
1212
name: 'new-message-in-channel',
13-
displayName: 'New Message Posted to Channel',
14-
description: 'Triggers when a new message is posted to a specific #channel you choose.',
13+
displayName: 'New Message Posted to Channel (DEPRECATED)',
14+
description: 'Triggers when a new message is posted to a specific #channel you choose. This trigger is deprecated: use the "New message posted" trigger instead',
1515
props: {
1616
info: singleSelectChannelInfo,
1717
channel: slackChannel(true),
@@ -42,7 +42,7 @@ export const newMessageInChannelTrigger = createTrigger({
4242
if (!['channel','group'].includes(payloadBody.event.channel_type)) {
4343
return [];
4444
}
45-
45+
4646
if (payloadBody.event.channel === context.propsValue.channel) {
4747
// check for bot messages
4848
if (context.propsValue.ignoreBots && payloadBody.event.bot_id) {

packages/pieces/community/slack/src/lib/triggers/new-message.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1-
import { Property, TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
1+
import {
2+
Property,
3+
TriggerStrategy,
4+
createTrigger,
5+
OAuth2PropertyValue,
6+
} from '@activepieces/pieces-framework';
27
import { slackAuth } from '../../';
8+
import { getChannels } from '../common/props';
39

410
export const newMessageTrigger = createTrigger({
511
auth: slackAuth,
612
name: 'new-message',
7-
displayName: 'New Public Message Posted Anywhere',
8-
description: 'Triggers when a new message is posted to any channel.',
13+
displayName: 'New message posted',
14+
description: 'Triggers when a new message is posted (optionally on one or more channels)',
915
props: {
16+
channels: Property.MultiSelectDropdown({
17+
displayName: 'Channels',
18+
description:
19+
'If no channel is selected, the flow will be triggered for messages in all channels',
20+
required: false,
21+
refreshers: [],
22+
async options({ auth }) {
23+
if (!auth) {
24+
return {
25+
disabled: true,
26+
placeholder: 'connect slack account',
27+
options: [],
28+
};
29+
}
30+
const authentication = auth as OAuth2PropertyValue;
31+
const channels = await getChannels(authentication['access_token']);
32+
return {
33+
disabled: false,
34+
placeholder: 'Select channel(s)',
35+
options: channels,
36+
};
37+
},
38+
}),
1039
ignoreBots: Property.Checkbox({
1140
displayName: 'Ignore Bot Messages ?',
1241
required: true,
@@ -35,6 +64,11 @@ export const newMessageTrigger = createTrigger({
3564
return [];
3665
}
3766

67+
// check if the channel is among one of the requested ones
68+
if (context.propsValue.channels && !context.propsValue.channels.includes(payloadBody.event.channel)) {
69+
return []
70+
}
71+
3872
// check for bot messages
3973
if (context.propsValue.ignoreBots && payloadBody.event.bot_id) {
4074
return [];

0 commit comments

Comments
 (0)