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:
@@ -10,6 +10,12 @@ interface EventBody {
|
|||||||
video?: {
|
video?: {
|
||||||
file_id: string;
|
file_id: string;
|
||||||
};
|
};
|
||||||
|
chat?: {
|
||||||
|
id: number;
|
||||||
|
};
|
||||||
|
from?: {
|
||||||
|
id: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEvent {
|
export interface IEvent {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ export class TelegramTrigger implements INodeType {
|
|||||||
name: 'telegramTrigger',
|
name: 'telegramTrigger',
|
||||||
icon: 'file:telegram.svg',
|
icon: 'file:telegram.svg',
|
||||||
group: ['trigger'],
|
group: ['trigger'],
|
||||||
version: [1, 1.1],
|
version: [1, 1.1, 1.2],
|
||||||
defaultVersion: 1.1,
|
defaultVersion: 1.2,
|
||||||
subtitle: '=Updates: {{$parameter["updates"].join(", ")}}',
|
subtitle: '=Updates: {{$parameter["updates"].join(", ")}}',
|
||||||
description: 'Starts the workflow on a Telegram update',
|
description: 'Starts the workflow on a Telegram update',
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -168,6 +168,32 @@ export class TelegramTrigger implements INodeType {
|
|||||||
default: 'large',
|
default: 'large',
|
||||||
description: 'The size of the image to be downloaded',
|
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 {
|
return {
|
||||||
workflowData: [this.helpers.returnJsonArray([bodyData as unknown as IDataObject])],
|
workflowData: [this.helpers.returnJsonArray([bodyData as unknown as IDataObject])],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user