mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Telegram Trigger Node): Add options to restrict to chat and user IDs (#14164)
This commit is contained in:
@@ -18,8 +18,8 @@ export class TelegramTrigger implements INodeType {
|
||||
name: 'telegramTrigger',
|
||||
icon: 'file:telegram.svg',
|
||||
group: ['trigger'],
|
||||
version: [1, 1.1],
|
||||
defaultVersion: 1.1,
|
||||
version: [1, 1.1, 1.2],
|
||||
defaultVersion: 1.2,
|
||||
subtitle: '=Updates: {{$parameter["updates"].join(", ")}}',
|
||||
description: 'Starts the workflow on a Telegram update',
|
||||
defaults: {
|
||||
@@ -168,6 +168,32 @@ export class TelegramTrigger implements INodeType {
|
||||
default: 'large',
|
||||
description: 'The size of the image to be downloaded',
|
||||
},
|
||||
{
|
||||
displayName: 'Restrict to Chat IDs',
|
||||
name: 'chatIds',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The chat IDs to restrict the trigger to. Multiple can be defined separated by comma.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [{ _cnd: { gte: 1.1 } }],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Restrict to User IDs',
|
||||
name: 'userIds',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The user IDs to restrict the trigger to. Multiple can be defined separated by comma.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [{ _cnd: { gte: 1.1 } }],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -333,6 +359,24 @@ export class TelegramTrigger implements INodeType {
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeVersion >= 1.2) {
|
||||
if (additionalFields.chatIds) {
|
||||
const chatIds = additionalFields.chatIds as string;
|
||||
const splitIds = chatIds.split(',').map((chatId) => chatId.trim());
|
||||
if (!splitIds.includes(String(bodyData.message?.chat?.id))) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalFields.userIds) {
|
||||
const userIds = additionalFields.userIds as string;
|
||||
const splitIds = userIds.split(',').map((userId) => userId.trim());
|
||||
if (!splitIds.includes(String(bodyData.message?.from?.id))) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray([bodyData as unknown as IDataObject])],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user