Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pieces/community/slack/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-slack",
"version": "0.10.9"
"version": "0.10.10"
}
66 changes: 59 additions & 7 deletions packages/pieces/community/slack/src/lib/triggers/new-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,28 @@ export const newMessageTrigger = createTrigger({
props: {
ignoreBots: Property.Checkbox({
displayName: 'Ignore Bot Messages ?',
required: true,
required: false,
defaultValue: false,
}),
keyword: Property.ShortText({
displayName: 'Keyword',
description: 'The keyword to search for in messages. Leave empty to trigger on all messages.',
required: false,
}),
includeThreads: Property.Checkbox({
displayName: 'Include Thread Messages',
description: 'If enabled, also triggers on matches in thread replies',
required: false,
defaultValue: true,
}),
matchWholeWord: Property.Checkbox({
displayName: 'Match Whole Word Only',
description: 'If enabled, only matches the keyword as a complete word (e.g. "test" won\'t match "testing").',
required: false,
defaultValue: false,
}),
},

type: TriggerStrategy.APP_WEBHOOK,
sampleData: undefined,
onEnable: async (context) => {
Expand All @@ -29,24 +47,58 @@ export const newMessageTrigger = createTrigger({

run: async (context) => {
const payloadBody = context.payload.body as PayloadBody;
const {ignoreBots, keyword, includeThreads, matchWholeWord} = context.propsValue;

// check if it's channel message
if (!['channel','group'].includes(payloadBody.event.channel_type)) {
// ignore system messages (joins, leaves, file shares, etc.)
if (payloadBody.event.subtype) {
return [];
}

// check for bot messages
if (context.propsValue.ignoreBots && payloadBody.event.bot_id) {

if (ignoreBots && payloadBody.event.bot_id) {
return [];
}
// check if it's channel message
if (!['channel','group'].includes(payloadBody.event.channel_type)) {
if (!includeThreads || !payloadBody.event.thread_ts) {
return [];
}
}

// if keyword is provided, check if the message contains the keyword
if (keyword && keyword.trim()) {
if (!payloadBody.event.text) {
return [];
}

const messageText = payloadBody.event.text.toLowerCase();
const searchKeyword = keyword.toLowerCase();
let keywordFound = false;

if (matchWholeWord) {
const wordRegex = new RegExp(`\\b${searchKeyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i');
keywordFound = wordRegex.test(payloadBody.event.text);
} else {
keywordFound = messageText.includes(searchKeyword);
}

if (!keywordFound) {
return [];
}
}

return [payloadBody.event];

},
});

type PayloadBody = {
event: {
text?: string;
channel: string;
user?: string;
channel_type:string;
bot_id?: string;
channel_type:string
thread_ts?: string;
subtype?: string;
};
};
Loading