UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

1,243 lines 92.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Telegram = void 0; const mime_types_1 = require("mime-types"); const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("./GenericFunctions"); const descriptions_1 = require("../../utils/descriptions"); const configureWaitTillDate_util_1 = require("../../utils/sendAndWait/configureWaitTillDate.util"); const descriptions_2 = require("../../utils/sendAndWait/descriptions"); const utils_1 = require("../../utils/sendAndWait/utils"); class Telegram { description = { displayName: 'Telegram', name: 'telegram', icon: 'file:telegram.svg', group: ['output'], version: [1, 1.1, 1.2], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Sends data to Telegram', defaults: { name: 'Telegram', }, usableAsTool: true, inputs: [n8n_workflow_1.NodeConnectionTypes.Main], outputs: [n8n_workflow_1.NodeConnectionTypes.Main], credentials: [ { name: 'telegramApi', required: true, }, ], waitingNodeTooltip: utils_1.SEND_AND_WAIT_WAITING_TOOLTIP, webhooks: descriptions_2.sendAndWaitWebhooksDescription, properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ // { // name: 'Bot', // value: 'bot', // }, { name: 'Chat', value: 'chat', }, { name: 'Callback', value: 'callback', }, { name: 'File', value: 'file', }, { name: 'Message', value: 'message', }, ], default: 'message', }, // ---------------------------------- // operation // ---------------------------------- // { // displayName: 'Operation', // name: 'operation', // type: 'options', // displayOptions: { // show: { // resource: [ // 'bot', // ], // }, // }, // options: [ // { // name: 'Info', // value: 'info', // description: 'Get information about the bot associated with the access token.', // }, // ], // default: 'info', // description: 'The operation to perform.', // }, // ---------------------------------- // operation // ---------------------------------- { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['chat'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get up to date information about a chat', action: 'Get a chat', }, { name: 'Get Administrators', value: 'administrators', description: 'Get the Administrators of a chat', action: 'Get all administrators in a chat', }, { name: 'Get Member', value: 'member', description: 'Get the member of a chat', action: 'Get a member in a chat', }, { name: 'Leave', value: 'leave', description: 'Leave a group, supergroup or channel', action: 'Leave a chat', }, { name: 'Set Description', value: 'setDescription', description: 'Set the description of a chat', action: 'Set description on a chat', }, { name: 'Set Title', value: 'setTitle', description: 'Set the title of a chat', action: 'Set a title on a chat', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['callback'], }, }, options: [ { name: 'Answer Query', value: 'answerQuery', description: 'Send answer to callback query sent from inline keyboard', action: 'Answer Query a callback', }, { name: 'Answer Inline Query', value: 'answerInlineQuery', description: 'Send answer to callback query sent from inline bot', action: 'Answer an inline query callback', }, ], default: 'answerQuery', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['file'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get a file', action: 'Get a file', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['message'], }, }, options: [ { name: 'Delete Chat Message', value: 'deleteMessage', description: 'Delete a chat message', action: 'Delete a chat message', }, { name: 'Edit Message Text', value: 'editMessageText', description: 'Edit a text message', action: 'Edit a text message', }, { name: 'Pin Chat Message', value: 'pinChatMessage', description: 'Pin a chat message', action: 'Pin a chat message', }, { name: 'Send Animation', value: 'sendAnimation', description: 'Send an animated file', action: 'Send an animated file', }, { name: 'Send Audio', value: 'sendAudio', description: 'Send a audio file', action: 'Send an audio file', }, { name: 'Send Chat Action', value: 'sendChatAction', description: 'Send a chat action', action: 'Send a chat action', }, { name: 'Send Document', value: 'sendDocument', description: 'Send a document', action: 'Send a document', }, { name: 'Send Location', value: 'sendLocation', description: 'Send a location', action: 'Send a location', }, { name: 'Send Media Group', value: 'sendMediaGroup', description: 'Send group of photos or videos to album', action: 'Send a media group message', }, { name: 'Send Message', value: 'sendMessage', description: 'Send a text message', action: 'Send a text message', }, { name: 'Send and Wait for Response', value: n8n_workflow_1.SEND_AND_WAIT_OPERATION, description: 'Send a message and wait for response', action: 'Send message and wait for response', }, { name: 'Send Photo', value: 'sendPhoto', description: 'Send a photo', action: 'Send a photo message', }, { name: 'Send Sticker', value: 'sendSticker', description: 'Send a sticker', action: 'Send a sticker', }, { name: 'Send Video', value: 'sendVideo', description: 'Send a video', action: 'Send a video', }, { name: 'Unpin Chat Message', value: 'unpinChatMessage', description: 'Unpin a chat message', action: 'Unpin a chat message', }, ], default: 'sendMessage', }, // ---------------------------------- // chat / message // ---------------------------------- { displayName: 'Chat ID', name: 'chatId', type: 'string', default: '', displayOptions: { show: { operation: [ 'administrators', 'deleteMessage', 'get', 'leave', 'member', 'pinChatMessage', 'setDescription', 'setTitle', 'sendAnimation', 'sendAudio', 'sendChatAction', 'sendDocument', 'sendLocation', 'sendMessage', 'sendMediaGroup', 'sendPhoto', 'sendSticker', 'sendVideo', 'unpinChatMessage', ], resource: ['chat', 'message'], }, }, required: true, description: 'Unique identifier for the target chat or username, To find your chat ID ask @get_id_bot', }, // ---------------------------------- // message:deleteMessage // ---------------------------------- { displayName: 'Message ID', name: 'messageId', type: 'string', default: '', displayOptions: { show: { operation: ['deleteMessage'], resource: ['message'], }, }, required: true, description: 'Unique identifier of the message to delete', }, // ---------------------------------- // message:pinChatMessage // ---------------------------------- { displayName: 'Message ID', name: 'messageId', type: 'string', default: '', displayOptions: { show: { operation: ['pinChatMessage', 'unpinChatMessage'], resource: ['message'], }, }, required: true, description: 'Unique identifier of the message to pin or unpin', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { operation: ['pinChatMessage'], resource: ['message'], }, }, default: {}, options: [ { displayName: 'Disable Notification', name: 'disable_notification', type: 'boolean', default: false, description: 'Whether to send a notification to all chat members about the new pinned message', }, ], }, // ---------------------------------- // chat // ---------------------------------- // ---------------------------------- // chat:member // ---------------------------------- { displayName: 'User ID', name: 'userId', type: 'string', default: '', displayOptions: { show: { operation: ['member'], resource: ['chat'], }, }, required: true, description: 'Unique identifier of the target user', }, // ---------------------------------- // chat:setDescription // ---------------------------------- { displayName: 'Description', name: 'description', type: 'string', default: '', displayOptions: { show: { operation: ['setDescription'], resource: ['chat'], }, }, required: true, description: 'New chat description, 0-255 characters', }, // ---------------------------------- // chat:setTitle // ---------------------------------- { displayName: 'Title', name: 'title', type: 'string', default: '', displayOptions: { show: { operation: ['setTitle'], resource: ['chat'], }, }, required: true, description: 'New chat title, 1-255 characters', }, // ---------------------------------- // callback // ---------------------------------- // ---------------------------------- // callback:answerQuery // ---------------------------------- { displayName: 'Query ID', name: 'queryId', type: 'string', default: '', displayOptions: { show: { operation: ['answerQuery'], resource: ['callback'], }, }, required: true, description: 'Unique identifier for the query to be answered', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { operation: ['answerQuery'], resource: ['callback'], }, }, default: {}, options: [ { displayName: 'Cache Time', name: 'cache_time', type: 'number', typeOptions: { minValue: 0, }, default: 0, description: 'The maximum amount of time in seconds that the result of the callback query may be cached client-side', }, { displayName: 'Show Alert', name: 'show_alert', type: 'boolean', default: false, description: 'Whether an alert will be shown by the client instead of a notification at the top of the chat screen', }, { displayName: 'Text', name: 'text', type: 'string', default: '', description: 'Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.', }, { displayName: 'URL', name: 'url', type: 'string', default: '', description: "URL that will be opened by the user's client", }, ], }, // ----------------------------------------------- // callback:answerInlineQuery // ----------------------------------------------- { displayName: 'Query ID', name: 'queryId', type: 'string', default: '', displayOptions: { show: { operation: ['answerInlineQuery'], resource: ['callback'], }, }, required: true, description: 'Unique identifier for the answered query', }, { displayName: 'Results', name: 'results', type: 'string', default: '', displayOptions: { show: { operation: ['answerInlineQuery'], resource: ['callback'], }, }, required: true, description: 'A JSON-serialized array of results for the inline query', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { operation: ['answerInlineQuery'], resource: ['callback'], }, }, default: {}, options: [ { displayName: 'Cache Time', name: 'cache_time', type: 'number', typeOptions: { minValue: 0, }, default: 0, description: 'The maximum amount of time in seconds that the result of the callback query may be cached client-side', }, { displayName: 'Show Alert', name: 'show_alert', type: 'boolean', default: false, description: 'Whether an alert will be shown by the client instead of a notification at the top of the chat screen', }, { displayName: 'Text', name: 'text', type: 'string', default: '', description: 'Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.', }, { displayName: 'URL', name: 'url', type: 'string', default: '', description: "URL that will be opened by the user's client", }, ], }, // ---------------------------------- // file // ---------------------------------- // ---------------------------------- // file:get/download // ---------------------------------- { displayName: 'File ID', name: 'fileId', type: 'string', default: '', displayOptions: { show: { operation: ['get'], resource: ['file'], }, }, required: true, description: 'The ID of the file', }, { displayName: 'Download', name: 'download', type: 'boolean', displayOptions: { show: { operation: ['get'], resource: ['file'], }, }, default: true, description: 'Whether to download the file', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { operation: ['get'], resource: ['file'], download: [true], }, }, default: {}, options: [ { displayName: 'MIME Type', name: 'mimeType', type: 'string', placeholder: 'image/jpeg', default: '', description: 'The MIME type of the file. If not specified, the MIME type will be determined by the file extension.', }, ], }, // ---------------------------------- // message // ---------------------------------- // ---------------------------------- // message:editMessageText // ---------------------------------- { displayName: 'Message Type', name: 'messageType', type: 'options', displayOptions: { show: { operation: ['editMessageText'], resource: ['message'], }, }, options: [ { name: 'Inline Message', value: 'inlineMessage', }, { name: 'Message', value: 'message', }, ], default: 'message', description: 'The type of the message to edit', }, { displayName: 'Chat ID', name: 'chatId', type: 'string', default: '', displayOptions: { show: { messageType: ['message'], operation: ['editMessageText'], resource: ['message'], }, }, required: true, description: 'Unique identifier for the target chat or username, To find your chat ID ask @get_id_bot', }, // ---------------------------------- // message:sendAnimation/sendAudio/sendDocument/sendPhoto/sendSticker/sendVideo // ---------------------------------- { displayName: 'Binary File', name: 'binaryData', type: 'boolean', default: false, required: true, displayOptions: { show: { operation: [ 'sendAnimation', 'sendAudio', 'sendDocument', 'sendPhoto', 'sendVideo', 'sendSticker', ], resource: ['message'], }, }, description: 'Whether the data to upload should be taken from binary field', }, { displayName: 'Input Binary Field', name: 'binaryPropertyName', type: 'string', default: 'data', required: true, hint: 'The name of the input binary field containing the file to be written', displayOptions: { show: { operation: [ 'sendAnimation', 'sendAudio', 'sendDocument', 'sendPhoto', 'sendVideo', 'sendSticker', ], resource: ['message'], binaryData: [true], }, }, placeholder: '', description: 'Name of the binary property that contains the data to upload', }, { displayName: 'Message ID', name: 'messageId', type: 'string', default: '', displayOptions: { show: { messageType: ['message'], operation: ['editMessageText'], resource: ['message'], }, }, required: true, description: 'Unique identifier of the message to edit', }, { displayName: 'Inline Message ID', name: 'inlineMessageId', type: 'string', default: '', displayOptions: { show: { messageType: ['inlineMessage'], operation: ['editMessageText'], resource: ['message'], }, }, required: true, description: 'Unique identifier of the inline message to edit', }, { displayName: 'Reply Markup', name: 'replyMarkup', displayOptions: { show: { operation: ['editMessageText'], resource: ['message'], }, }, type: 'options', options: [ { name: 'None', value: 'none', }, { name: 'Inline Keyboard', value: 'inlineKeyboard', }, ], default: 'none', description: 'Additional interface options', }, // ---------------------------------- // message:sendAnimation // ---------------------------------- { displayName: 'Animation', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendAnimation'], resource: ['message'], binaryData: [false], }, }, description: 'Animation to send. Pass a file_id to send an animation that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get an animation from the Internet.', }, // ---------------------------------- // message:sendAudio // ---------------------------------- { displayName: 'Audio', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendAudio'], resource: ['message'], binaryData: [false], }, }, description: 'Audio file to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a file from the Internet.', }, // ---------------------------------- // message:sendChatAction // ---------------------------------- { displayName: 'Action', name: 'action', type: 'options', displayOptions: { show: { operation: ['sendChatAction'], resource: ['message'], }, }, options: [ { name: 'Find Location', value: 'find_location', action: 'Find location', }, { name: 'Record Audio', value: 'record_audio', action: 'Record audio', }, { name: 'Record Video', value: 'record_video', action: 'Record video', }, { name: 'Record Video Note', value: 'record_video_note', action: 'Record video note', }, { name: 'Typing', value: 'typing', action: 'Typing a message', }, { name: 'Upload Audio', value: 'upload_audio', action: 'Upload audio', }, { name: 'Upload Document', value: 'upload_document', action: 'Upload document', }, { name: 'Upload Photo', value: 'upload_photo', action: 'Upload photo', }, { name: 'Upload Video', value: 'upload_video', action: 'Upload video', }, { name: 'Upload Video Note', value: 'upload_video_note', action: 'Upload video note', }, ], default: 'typing', description: 'Type of action to broadcast. Choose one, depending on what the user is about to receive. The status is set for 5 seconds or less (when a message arrives from your bot).', }, // ---------------------------------- // message:sendDocument // ---------------------------------- { displayName: 'Document', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendDocument'], resource: ['message'], binaryData: [false], }, }, description: 'Document to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a file from the Internet.', }, // ---------------------------------- // message:sendLocation // ---------------------------------- { displayName: 'Latitude', name: 'latitude', type: 'number', default: 0.0, typeOptions: { numberPrecision: 10, minValue: -90, maxValue: 90, }, displayOptions: { show: { operation: ['sendLocation'], resource: ['message'], }, }, description: 'Location latitude', }, { displayName: 'Longitude', name: 'longitude', type: 'number', typeOptions: { numberPrecision: 10, minValue: -180, maxValue: 180, }, default: 0.0, displayOptions: { show: { operation: ['sendLocation'], resource: ['message'], }, }, description: 'Location longitude', }, // ---------------------------------- // message:sendMediaGroup // ---------------------------------- { displayName: 'Media', name: 'media', type: 'fixedCollection', displayOptions: { show: { operation: ['sendMediaGroup'], resource: ['message'], }, }, description: 'The media to add', placeholder: 'Add Media', typeOptions: { multipleValues: true, }, default: {}, options: [ { displayName: 'Media', name: 'media', values: [ { displayName: 'Type', name: 'type', type: 'options', options: [ { name: 'Photo', value: 'photo', }, { name: 'Video', value: 'video', }, ], default: 'photo', description: 'The type of the media to add', }, { displayName: 'Media File', name: 'media', type: 'string', default: '', description: 'Media to send. Pass a file_id to send a file that exists on the Telegram servers (recommended) or pass an HTTP URL for Telegram to get a file from the Internet.', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, options: [ { displayName: 'Caption', name: 'caption', type: 'string', default: '', description: 'Caption text to set, 0-1024 characters', }, { displayName: 'Parse Mode', name: 'parse_mode', type: 'options', options: [ { name: 'Markdown (Legacy)', value: 'Markdown', }, { name: 'MarkdownV2', value: 'MarkdownV2', }, { name: 'HTML', value: 'HTML', }, ], default: 'HTML', description: 'How to parse the text', }, ], }, ], }, ], }, // ---------------------------------- // message:sendMessage // ---------------------------------- { displayName: 'Text', name: 'text', type: 'string', required: true, default: '', displayOptions: { show: { operation: ['editMessageText', 'sendMessage'], resource: ['message'], }, }, description: 'Text of the message to be sent', }, // ---------------------------------- // message:sendPhoto // ---------------------------------- { displayName: 'Photo', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendPhoto'], resource: ['message'], binaryData: [false], }, }, description: 'Photo to send. Pass a file_id to send a photo that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a photo from the Internet.', }, // ---------------------------------- // message:sendSticker // ---------------------------------- { displayName: 'Sticker', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendSticker'], resource: ['message'], binaryData: [false], }, }, description: 'Sticker to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a .webp file from the Internet.', }, // ---------------------------------- // message:sendVideo // ---------------------------------- { displayName: 'Video', name: 'file', type: 'string', default: '', displayOptions: { show: { operation: ['sendVideo'], resource: ['message'], binaryData: [false], }, }, description: 'Video file to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a file from the Internet.', }, // ---------------------------------- // message:editMessageText/sendAnimation/sendAudio/sendLocation/sendMessage/sendPhoto/sendSticker/sendVideo // ---------------------------------- { displayName: 'Reply Markup', name: 'replyMarkup', displayOptions: { show: { operation: [ 'sendAnimation', 'sendDocument', 'sendMessage', 'sendPhoto', 'sendSticker', 'sendVideo', 'sendAudio', 'sendLocation', ], resource: ['message'], }, }, type: 'options', options: [ { name: 'Force Reply', value: 'forceReply', }, { name: 'Inline Keyboard', value: 'inlineKeyboard', }, { name: 'None', value: 'none', }, { name: 'Reply Keyboard', value: 'replyKeyboard', }, { name: 'Reply Keyboard Remove', value: 'replyKeyboardRemove', }, ], default: 'none', description: 'Additional interface options', }, { displayName: 'Force Reply', name: 'forceReply', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { replyMarkup: ['forceReply'], resource: ['message'], }, }, default: {}, options: [ { displayName: 'Force Reply', name: 'force_reply', type: 'boolean', default: false, description: 'Whether to show reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply', }, { displayName: 'Selective', name: 'selective', type: 'boolean', default: false, description: 'Whether to force reply from specific users only', }, ], }, { displayName: 'Inline Keyboard', name: 'inlineKeyboard', placeholder: 'Add Keyboard Row', description: 'Adds an inline keyboard that appears right next to the message it belongs to', type: 'fixedCollection', typeOptions: { multipleValues: true, }, displayOptions: { show: { replyMarkup: ['inlineKeyboard'], resource: ['message'], }, }, default: {}, options: [ { displayName: 'Rows', name: 'rows', values: [ { displayName: 'Row', name: 'row', type: 'fixedCollection', description: 'The value to set', placeholder: 'Add Button', typeOptions: { multipleValues: true, }, default: {}, options: [ { displayName: 'Buttons', name: 'buttons', values: [ { displayName: 'Text', name: 'text', type: 'string', default: '', description: 'Label text on the button', }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, options: [ { displayName: 'Callback Data', name: 'callback_data', type: 'string', default: '', description: 'Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes', }, { displayName: 'Pay', name: 'pay', type: 'boolean', default: false, description: 'Whether to send a Pay button', }, { displayName: 'Switch Inline Query Current Chat', name: 'switch_inline_query_current_chat', type: 'string', default: '', description: "If set, pressing the button will insert the bot‘s username and the spec