From d87b54c86efb877ab4e7c7c2e16350dc160c0551 Mon Sep 17 00:00:00 2001 From: SimplyRohit Date: Tue, 7 Oct 2025 09:36:19 +0530 Subject: [PATCH 1/5] feat(telegram): added delete message,send photo-video-audio-animation tools --- apps/sim/blocks/blocks/telegram.ts | 273 +++++++++++++++++++++++++-- apps/sim/tools/registry.ts | 16 +- apps/sim/tools/telegram/animation.ts | 270 ++++++++++++++++++++++++++ apps/sim/tools/telegram/audio.ts | 163 ++++++++++++++++ apps/sim/tools/telegram/delete.ts | 80 ++++++++ apps/sim/tools/telegram/index.ts | 16 +- apps/sim/tools/telegram/message.ts | 85 +++++++-- apps/sim/tools/telegram/photo.ts | 154 +++++++++++++++ apps/sim/tools/telegram/types.ts | 173 +++++++++++++++-- apps/sim/tools/telegram/video.ts | 269 ++++++++++++++++++++++++++ 10 files changed, 1453 insertions(+), 46 deletions(-) create mode 100644 apps/sim/tools/telegram/animation.ts create mode 100644 apps/sim/tools/telegram/audio.ts create mode 100644 apps/sim/tools/telegram/delete.ts create mode 100644 apps/sim/tools/telegram/photo.ts create mode 100644 apps/sim/tools/telegram/video.ts diff --git a/apps/sim/blocks/blocks/telegram.ts b/apps/sim/blocks/blocks/telegram.ts index 3f247c525ae..27866368634 100644 --- a/apps/sim/blocks/blocks/telegram.ts +++ b/apps/sim/blocks/blocks/telegram.ts @@ -1,21 +1,36 @@ import { TelegramIcon } from '@/components/icons' import type { BlockConfig } from '@/blocks/types' import { AuthMode } from '@/blocks/types' -import type { TelegramMessageResponse } from '@/tools/telegram/types' +import type { TelegramResponse } from '@/tools/telegram/types' -export const TelegramBlock: BlockConfig = { +export const TelegramBlock: BlockConfig = { type: 'telegram', name: 'Telegram', - description: 'Send messages through Telegram or trigger workflows from Telegram events', + description: 'Interact with Telegram', authMode: AuthMode.BotToken, longDescription: - 'Integrate Telegram into the workflow. Can send messages. Can be used in trigger mode to trigger a workflow when a message is sent to a chat.', + 'Integrate Telegram into the workflow. Can send and delete messages. Can be used in trigger mode to trigger a workflow when a message is sent to a chat.', docsLink: 'https://docs.sim.ai/tools/telegram', category: 'tools', bgColor: '#E0E0E0', icon: TelegramIcon, triggerAllowed: true, subBlocks: [ + { + id: 'operation', + title: 'Operation', + type: 'dropdown', + layout: 'full', + options: [ + { label: 'Send Message', id: 'telegram_send_message' }, + { label: 'Send Photo', id: 'telegram_send_photo' }, + { label: 'Send Video', id: 'telegram_send_video' }, + { label: 'Send Audio', id: 'telegram_send_audio' }, + { label: 'Send Animation', id: 'telegram_send_animation' }, + { label: 'Delete Message', id: 'telegram_delete_message' }, + ], + value: () => 'telegram_send_message', + }, { id: 'botToken', title: 'Bot Token', @@ -40,7 +55,7 @@ export const TelegramBlock: BlockConfig = { 1. Add your bot as a member to desired Telegram channel 2. Send any message to the channel (e.g. "I love Sim") 3. Visit https://api.telegram.org/bot/getUpdates -4. Look for the chat field in the JSON response at the very bottomwhere you'll find the chat ID`, +4. Look for the chat field in the JSON response at the very bottom where you'll find the chat ID`, required: true, }, { @@ -49,7 +64,88 @@ export const TelegramBlock: BlockConfig = { type: 'long-input', layout: 'full', placeholder: 'Enter the message to send', - required: true, + condition: { field: 'operation', value: 'telegram_send_message' }, + }, + { + id: 'photo', + title: 'Photo', + type: 'short-input', + layout: 'full', + placeholder: 'Enter photo URL or file_id', + description: 'Photo to send. Pass a file_id or HTTP URL', + condition: { field: 'operation', value: 'telegram_send_photo' }, + }, + { + id: 'caption', + title: 'Caption', + type: 'long-input', + layout: 'full', + placeholder: 'Enter optional caption', + description: 'Photo caption (optional)', + condition: { field: 'operation', value: 'telegram_send_photo' }, + }, + { + id: 'video', + title: 'Video', + type: 'short-input', + layout: 'full', + placeholder: 'Enter video URL or file_id', + description: 'Video to send. Pass a file_id or HTTP URL', + condition: { field: 'operation', value: 'telegram_send_video' }, + }, + { + id: 'videoCaption', + title: 'Caption', + type: 'long-input', + layout: 'full', + placeholder: 'Enter optional caption', + description: 'Video caption (optional)', + condition: { field: 'operation', value: 'telegram_send_video' }, + }, + { + id: 'audio', + title: 'Audio', + type: 'short-input', + layout: 'full', + placeholder: 'Enter audio URL or file_id', + description: 'Audio file to send. Pass a file_id or HTTP URL', + condition: { field: 'operation', value: 'telegram_send_audio' }, + }, + { + id: 'audioCaption', + title: 'Caption', + type: 'long-input', + layout: 'full', + placeholder: 'Enter optional caption', + description: 'Audio caption (optional)', + condition: { field: 'operation', value: 'telegram_send_audio' }, + }, + { + id: 'animation', + title: 'Animation', + type: 'short-input', + layout: 'full', + placeholder: 'Enter animation URL or file_id', + description: 'Animation (GIF) to send. Pass a file_id or HTTP URL', + condition: { field: 'operation', value: 'telegram_send_animation' }, + }, + { + id: 'animationCaption', + title: 'Caption', + type: 'long-input', + layout: 'full', + placeholder: 'Enter optional caption', + description: 'Animation caption (optional)', + condition: { field: 'operation', value: 'telegram_send_animation' }, + }, + { + id: 'messageId', + title: 'Message ID', + type: 'short-input', + layout: 'full', + placeholder: 'Enter the message ID to delete', + description: 'The unique identifier of the message you want to delete', + condition: { field: 'operation', value: 'telegram_delete_message' }, }, // TRIGGER MODE: Trigger configuration (only shown when trigger mode is active) { @@ -62,39 +158,184 @@ export const TelegramBlock: BlockConfig = { }, ], tools: { - access: ['telegram_message'], + access: [ + 'telegram_send_message', + 'telegram_delete_message', + 'telegram_send_photo', + 'telegram_send_video', + 'telegram_send_audio', + 'telegram_send_animation', + ], + config: { + tool: (params) => { + switch (params.operation) { + case 'telegram_send_message': + return 'telegram_send_message' + case 'telegram_delete_message': + return 'telegram_delete_message' + case 'telegram_send_photo': + return 'telegram_send_photo' + case 'telegram_send_video': + return 'telegram_send_video' + case 'telegram_send_audio': + return 'telegram_send_audio' + case 'telegram_send_animation': + return 'telegram_send_animation' + default: + return 'telegram_send_message' + } + }, + params: (params) => { + const commonParams: Record = {} + + if (!params.botToken) throw new Error('Bot token required for this operation') + commonParams.botToken = params.botToken + + const chatId = (params.chatId || '').trim() + if (!chatId) { + throw new Error('Chat ID is required.') + } + + switch (params.operation) { + case 'telegram_send_message': + return { + ...commonParams, + chatId, + text: params.text, + } + case 'telegram_delete_message': + if (!params.messageId) { + throw new Error('Message ID is required for delete operation.') + } + return { + ...commonParams, + chatId, + messageId: params.messageId, + } + case 'telegram_send_photo': + if (!params.photo) { + throw new Error('Photo URL or file_id is required.') + } + return { + ...commonParams, + chatId, + photo: params.photo, + caption: params.caption, + } + case 'telegram_send_video': + if (!params.video) { + throw new Error('Video URL or file_id is required.') + } + return { + ...commonParams, + chatId, + video: params.video, + caption: params.videoCaption, + } + case 'telegram_send_audio': + if (!params.audio) { + throw new Error('Audio URL or file_id is required.') + } + return { + ...commonParams, + chatId, + audio: params.audio, + caption: params.audioCaption, + } + case 'telegram_send_animation': + if (!params.animation) { + throw new Error('Animation URL or file_id is required.') + } + return { + ...commonParams, + chatId, + animation: params.animation, + caption: params.animationCaption, + } + default: + return { + ...commonParams, + chatId, + } + } + }, + }, }, inputs: { + operation: { type: 'string', description: 'Operation to perform' }, botToken: { type: 'string', description: 'Telegram bot token' }, chatId: { type: 'string', description: 'Chat identifier' }, text: { type: 'string', description: 'Message text' }, + photo: { type: 'string', description: 'Photo URL or file_id' }, + video: { type: 'string', description: 'Video URL or file_id' }, + audio: { type: 'string', description: 'Audio URL or file_id' }, + animation: { type: 'string', description: 'Animation URL or file_id' }, + caption: { type: 'string', description: 'Caption for media' }, + videoCaption: { type: 'string', description: 'Caption for video' }, + audioCaption: { type: 'string', description: 'Caption for audio' }, + animationCaption: { type: 'string', description: 'Caption for animation' }, + messageId: { type: 'string', description: 'Message ID to delete' }, }, outputs: { // Send message operation outputs ok: { type: 'boolean', description: 'API response success status' }, - result: { type: 'json', description: 'Complete message result object from Telegram API' }, + result: { + type: 'json', + description: 'Complete message result object from Telegram API', + }, + message: { type: 'string', description: 'Success or error message' }, + data: { type: 'json', description: 'Response data' }, // Specific result fields messageId: { type: 'number', description: 'Sent message ID' }, chatId: { type: 'number', description: 'Chat ID where message was sent' }, - chatType: { type: 'string', description: 'Type of chat (private, group, supergroup, channel)' }, + chatType: { + type: 'string', + description: 'Type of chat (private, group, supergroup, channel)', + }, username: { type: 'string', description: 'Chat username (if available)' }, - messageDate: { type: 'number', description: 'Unix timestamp of sent message' }, - messageText: { type: 'string', description: 'Text content of sent message' }, + messageDate: { + type: 'number', + description: 'Unix timestamp of sent message', + }, + messageText: { + type: 'string', + description: 'Text content of sent message', + }, + // Delete message outputs + deleted: { + type: 'boolean', + description: 'Whether the message was successfully deleted', + }, // Webhook trigger outputs (incoming messages) - update_id: { type: 'number', description: 'Unique identifier for the update' }, - message_id: { type: 'number', description: 'Unique message identifier from webhook' }, + update_id: { + type: 'number', + description: 'Unique identifier for the update', + }, + message_id: { + type: 'number', + description: 'Unique message identifier from webhook', + }, from_id: { type: 'number', description: 'User ID who sent the message' }, from_username: { type: 'string', description: 'Username of the sender' }, - from_first_name: { type: 'string', description: 'First name of the sender' }, + from_first_name: { + type: 'string', + description: 'First name of the sender', + }, from_last_name: { type: 'string', description: 'Last name of the sender' }, chat_id: { type: 'number', description: 'Unique identifier for the chat' }, chat_type: { type: 'string', description: 'Type of chat (private, group, supergroup, channel)', }, - chat_title: { type: 'string', description: 'Title of the chat (for groups and channels)' }, + chat_title: { + type: 'string', + description: 'Title of the chat (for groups and channels)', + }, text: { type: 'string', description: 'Message text content from webhook' }, - date: { type: 'number', description: 'Date the message was sent (Unix timestamp)' }, + date: { + type: 'number', + description: 'Date the message was sent (Unix timestamp)', + }, entities: { type: 'json', description: 'Special entities in the message (mentions, hashtags, etc.)', diff --git a/apps/sim/tools/registry.ts b/apps/sim/tools/registry.ts index f110ef01242..3464efa648b 100644 --- a/apps/sim/tools/registry.ts +++ b/apps/sim/tools/registry.ts @@ -175,7 +175,14 @@ import { supabaseUpsertTool, } from '@/tools/supabase' import { tavilyExtractTool, tavilySearchTool } from '@/tools/tavily' -import { telegramMessageTool } from '@/tools/telegram' +import { + telegramDeleteMessageTool, + telegramSendAnimationTool, + telegramSendAudioTool, + telegramSendMessageTool, + telegramSendPhotoTool, + telegramSendVideoTool, +} from '@/tools/telegram' import { thinkingTool } from '@/tools/thinking' import { sendSMSTool } from '@/tools/twilio' import { typeformFilesTool, typeformInsightsTool, typeformResponsesTool } from '@/tools/typeform' @@ -325,7 +332,12 @@ export const tools: Record = { knowledge_create_document: knowledgeCreateDocumentTool, elevenlabs_tts: elevenLabsTtsTool, s3_get_object: s3GetObjectTool, - telegram_message: telegramMessageTool, + telegram_send_message: telegramSendMessageTool, + telegram_delete_message: telegramDeleteMessageTool, + telegram_send_audio: telegramSendAudioTool, + telegram_send_animation: telegramSendAnimationTool, + telegram_send_photo: telegramSendPhotoTool, + telegram_send_video: telegramSendVideoTool, clay_populate: clayPopulateTool, discord_send_message: discordSendMessageTool, discord_get_messages: discordGetMessagesTool, diff --git a/apps/sim/tools/telegram/animation.ts b/apps/sim/tools/telegram/animation.ts new file mode 100644 index 00000000000..f373b2b15bf --- /dev/null +++ b/apps/sim/tools/telegram/animation.ts @@ -0,0 +1,270 @@ +import type { + TelegramMedia, + TelegramSendAnimationParams, + TelegramSendMediaResponse, +} from '@/tools/telegram/types' +import { convertMarkdownToHTML } from '@/tools/telegram/utils' +import type { ToolConfig } from '@/tools/types' + +export const telegramSendAnimationTool: ToolConfig< + TelegramSendAnimationParams, + TelegramSendMediaResponse +> = { + id: 'telegram_send_animation', + name: 'Telegram Send Animation', + description: 'Send animations (GIFs) to Telegram channels or users through the Telegram Bot API.', + version: '1.0.0', + + params: { + botToken: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Your Telegram Bot API Token', + }, + chatId: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Target Telegram chat ID', + }, + animation: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Animation to send. Pass a file_id or HTTP URL', + }, + caption: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Animation caption (optional)', + }, + }, + + request: { + url: (params: TelegramSendAnimationParams) => + `https://api.telegram.org/bot${params.botToken}/sendAnimation`, + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params: TelegramSendAnimationParams) => { + const body: Record = { + chat_id: params.chatId, + animation: params.animation, + } + + if (params.caption) { + body.caption = convertMarkdownToHTML(params.caption) + body.parse_mode = 'HTML' + } + + return body + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + const result = data.result as TelegramMedia + return { + success: data.ok, + output: { + message: data.ok ? 'Animation sent successfully' : 'Failed to send animation', + data: result, + }, + } + }, + + outputs: { + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Telegram message data including optional media', + properties: { + message_id: { + type: 'number', + description: 'Unique Telegram message identifier', + }, + from: { + type: 'object', + description: 'Information about the sender', + properties: { + id: { type: 'number', description: 'Sender ID' }, + is_bot: { + type: 'string', + description: 'Whether the sender is a bot', + }, + first_name: { + type: 'string', + description: "Sender's first name (if available)", + }, + username: { + type: 'string', + description: "Sender's username (if available)", + }, + }, + }, + chat: { + type: 'object', + description: 'Information about the chat where message was sent', + properties: { + id: { type: 'number', description: 'Chat ID' }, + first_name: { + type: 'string', + description: 'Chat first name (if private chat)', + }, + username: { + type: 'string', + description: 'Chat username (for private or channels)', + }, + type: { + type: 'string', + description: 'Type of chat (private, group, supergroup, or channel)', + }, + }, + }, + date: { + type: 'number', + description: 'Unix timestamp when the message was sent', + }, + text: { + type: 'string', + description: 'Text content of the sent message (if applicable)', + }, + format: { + type: 'object', + description: 'Media format information (for videos, GIFs, etc.)', + properties: { + file_name: { type: 'string', description: 'Media file name' }, + mime_type: { type: 'string', description: 'Media MIME type' }, + duration: { + type: 'number', + description: 'Duration of media in seconds', + }, + width: { type: 'number', description: 'Media width in pixels' }, + height: { type: 'number', description: 'Media height in pixels' }, + thumbnail: { + type: 'object', + description: 'Thumbnail image details', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + thumb: { + type: 'object', + description: 'Secondary thumbnail details (duplicate of thumbnail)', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + file_id: { type: 'string', description: 'Media file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique media file identifier', + }, + file_size: { + type: 'number', + description: 'Size of media file in bytes', + }, + }, + }, + document: { + type: 'object', + description: 'Document file details if the message contains a document', + properties: { + file_name: { type: 'string', description: 'Document file name' }, + mime_type: { type: 'string', description: 'Document MIME type' }, + thumbnail: { + type: 'object', + description: 'Document thumbnail information', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + thumb: { + type: 'object', + description: 'Duplicate thumbnail info (used for compatibility)', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + file_id: { type: 'string', description: 'Document file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique document file identifier', + }, + file_size: { + type: 'number', + description: 'Size of document file in bytes', + }, + }, + }, + }, + }, + }, +} diff --git a/apps/sim/tools/telegram/audio.ts b/apps/sim/tools/telegram/audio.ts new file mode 100644 index 00000000000..0d48a44c0b7 --- /dev/null +++ b/apps/sim/tools/telegram/audio.ts @@ -0,0 +1,163 @@ +import type { + TelegramAudio, + TelegramSendAudioParams, + TelegramSendAudioResponse, +} from '@/tools/telegram/types' +import { convertMarkdownToHTML } from '@/tools/telegram/utils' +import type { ToolConfig } from '@/tools/types' + +export const telegramSendAudioTool: ToolConfig = + { + id: 'telegram_send_audio', + name: 'Telegram Send Audio', + description: 'Send audio files to Telegram channels or users through the Telegram Bot API.', + version: '1.0.0', + + params: { + botToken: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Your Telegram Bot API Token', + }, + chatId: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Target Telegram chat ID', + }, + audio: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Audio file to send. Pass a file_id or HTTP URL', + }, + caption: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Audio caption (optional)', + }, + }, + + request: { + url: (params: TelegramSendAudioParams) => + `https://api.telegram.org/bot${params.botToken}/sendAudio`, + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params: TelegramSendAudioParams) => { + const body: Record = { + chat_id: params.chatId, + audio: params.audio, + } + + if (params.caption) { + body.caption = convertMarkdownToHTML(params.caption) + body.parse_mode = 'HTML' + } + + return body + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + const result = data.result as TelegramAudio + + return { + success: data.ok, + output: { + message: data.ok ? 'Audio sent successfully' : 'Failed to send audio', + data: result, + }, + } + }, + + outputs: { + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Telegram message data including voice/audio information', + properties: { + message_id: { + type: 'number', + description: 'Unique Telegram message identifier', + }, + from: { + type: 'object', + description: 'Information about the sender', + properties: { + id: { type: 'number', description: 'Sender ID' }, + is_bot: { + type: 'string', + description: 'Whether the sender is a bot', + }, + first_name: { + type: 'string', + description: "Sender's first name (if available)", + }, + username: { + type: 'string', + description: "Sender's username (if available)", + }, + }, + }, + chat: { + type: 'object', + description: 'Information about the chat where the message was sent', + properties: { + id: { type: 'number', description: 'Chat ID' }, + first_name: { + type: 'string', + description: 'Chat first name (if private chat)', + }, + username: { + type: 'string', + description: 'Chat username (for private or channels)', + }, + type: { + type: 'string', + description: 'Type of chat (private, group, supergroup, or channel)', + }, + }, + }, + date: { + type: 'number', + description: 'Unix timestamp when the message was sent', + }, + text: { + type: 'string', + description: 'Text content of the sent message (if applicable)', + }, + voice: { + type: 'object', + description: 'Voice message (audio note) details', + properties: { + duration: { + type: 'number', + description: 'Duration of the voice message in seconds', + }, + mime_type: { + type: 'string', + description: 'MIME type of the audio file (e.g., audio/ogg)', + }, + file_id: { + type: 'string', + description: 'Unique file identifier for this voice message', + }, + file_unique_id: { + type: 'string', + description: 'Unique identifier across different bots for this file', + }, + file_size: { + type: 'number', + description: 'Size of the voice file in bytes', + }, + }, + }, + }, + }, + }, + } diff --git a/apps/sim/tools/telegram/delete.ts b/apps/sim/tools/telegram/delete.ts new file mode 100644 index 00000000000..0d86ab3dd20 --- /dev/null +++ b/apps/sim/tools/telegram/delete.ts @@ -0,0 +1,80 @@ +import type { + TelegramDeleteMessageParams, + TelegramDeleteMessageResponse, +} from '@/tools/telegram/types' +import type { ToolConfig } from '@/tools/types' + +export const telegramDeleteMessageTool: ToolConfig< + TelegramDeleteMessageParams, + TelegramDeleteMessageResponse +> = { + id: 'telegram_delete_message', + name: 'Telegram Delete Message', + description: + 'Delete messages in Telegram channels or chats through the Telegram Bot API. Requires the message ID of the message to delete.', + version: '1.0.0', + + params: { + botToken: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Your Telegram Bot API Token', + }, + chatId: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Target Telegram chat ID', + }, + messageId: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Message ID to delete', + }, + }, + + request: { + url: (params: TelegramDeleteMessageParams) => + `https://api.telegram.org/bot${params.botToken}/deleteMessage`, + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params: TelegramDeleteMessageParams) => ({ + chat_id: params.chatId, + message_id: params.messageId, + }), + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + console.log(data.result) + return { + success: data.ok, + output: { + message: data.ok ? 'Message deleted successfully' : 'Failed to delete message', + data: { + ok: data.ok, + deleted: data.result, + }, + }, + } + }, + + outputs: { + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Delete operation result', + properties: { + ok: { type: 'boolean', description: 'API response success status' }, + deleted: { + type: 'boolean', + description: 'Whether the message was successfully deleted', + }, + }, + }, + }, +} diff --git a/apps/sim/tools/telegram/index.ts b/apps/sim/tools/telegram/index.ts index 8b8e96974e3..8e1a098f216 100644 --- a/apps/sim/tools/telegram/index.ts +++ b/apps/sim/tools/telegram/index.ts @@ -1,3 +1,15 @@ -import { telegramMessageTool } from '@/tools/telegram/message' +import { telegramSendAnimationTool } from '@/tools/telegram/animation' +import { telegramSendAudioTool } from '@/tools/telegram/audio' +import { telegramDeleteMessageTool } from '@/tools/telegram/delete' +import { telegramSendMessageTool } from '@/tools/telegram/message' +import { telegramSendPhotoTool } from '@/tools/telegram/photo' +import { telegramSendVideoTool } from '@/tools/telegram/video' -export { telegramMessageTool } +export { + telegramSendAnimationTool, + telegramSendAudioTool, + telegramDeleteMessageTool, + telegramSendMessageTool, + telegramSendPhotoTool, + telegramSendVideoTool, +} diff --git a/apps/sim/tools/telegram/message.ts b/apps/sim/tools/telegram/message.ts index 620363869de..2004a441a64 100644 --- a/apps/sim/tools/telegram/message.ts +++ b/apps/sim/tools/telegram/message.ts @@ -1,10 +1,17 @@ -import type { TelegramMessageParams, TelegramMessageResponse } from '@/tools/telegram/types' +import type { + TelegramMessage, + TelegramSendMessageParams, + TelegramSendMessageResponse, +} from '@/tools/telegram/types' import { convertMarkdownToHTML } from '@/tools/telegram/utils' import type { ToolConfig } from '@/tools/types' -export const telegramMessageTool: ToolConfig = { - id: 'telegram_message', - name: 'Telegram Message', +export const telegramSendMessageTool: ToolConfig< + TelegramSendMessageParams, + TelegramSendMessageResponse +> = { + id: 'telegram_send_message', + name: 'Telegram Send Message', description: 'Send messages to Telegram channels or users through the Telegram Bot API. Enables direct communication and notifications with message tracking and chat confirmation.', version: '1.0.0', @@ -31,13 +38,13 @@ export const telegramMessageTool: ToolConfig + url: (params: TelegramSendMessageParams) => `https://api.telegram.org/bot${params.botToken}/sendMessage`, method: 'POST', headers: () => ({ 'Content-Type': 'application/json', }), - body: (params: TelegramMessageParams) => ({ + body: (params: TelegramSendMessageParams) => ({ chat_id: params.chatId, text: convertMarkdownToHTML(params.text), parse_mode: 'HTML', @@ -46,18 +53,68 @@ export const telegramMessageTool: ToolConfig { const data = await response.json() + const result = data.result as TelegramMessage + return { - success: true, - output: data.result, + success: data.ok, + output: { + message: data.ok ? 'Message sent successfully' : 'Failed to send message', + data: result, + }, } }, outputs: { - success: { type: 'boolean', description: 'Telegram message send success status' }, - messageId: { type: 'number', description: 'Unique Telegram message identifier' }, - chatId: { type: 'string', description: 'Target chat ID where message was sent' }, - text: { type: 'string', description: 'Text content of the sent message' }, - timestamp: { type: 'number', description: 'Unix timestamp when message was sent' }, - from: { type: 'object', description: 'Information about the bot that sent the message' }, + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Telegram message data', + properties: { + message_id: { + type: 'number', + description: 'Unique Telegram message identifier', + }, + from: { + type: 'object', + description: 'Chat information', + properties: { + id: { type: 'number', description: 'Chat ID' }, + is_bot: { + type: 'string', + description: 'Type of chat (private, group, supergroup, channel)', + }, + first_name: { + type: 'string', + description: 'Chat username (if available)', + }, + username: { + type: 'string', + description: 'Chat title (for groups and channels)', + }, + }, + }, + chat: { + type: 'object', + description: 'Information about the bot that sent the message', + properties: { + id: { type: 'number', description: 'Bot user ID' }, + first_name: { type: 'string', description: 'Bot first name' }, + username: { type: 'string', description: 'Bot username' }, + type: { + type: 'string', + description: 'chat type private or channel', + }, + }, + }, + date: { + type: 'number', + description: 'Unix timestamp when message was sent', + }, + text: { + type: 'string', + description: 'Text content of the sent message', + }, + }, + }, }, } diff --git a/apps/sim/tools/telegram/photo.ts b/apps/sim/tools/telegram/photo.ts new file mode 100644 index 00000000000..c6b68f5932b --- /dev/null +++ b/apps/sim/tools/telegram/photo.ts @@ -0,0 +1,154 @@ +import type { + TelegramPhoto, + TelegramSendPhotoParams, + TelegramSendPhotoResponse, +} from '@/tools/telegram/types' +import { convertMarkdownToHTML } from '@/tools/telegram/utils' +import type { ToolConfig } from '@/tools/types' + +export const telegramSendPhotoTool: ToolConfig = + { + id: 'telegram_send_photo', + name: 'Telegram Send Photo', + description: 'Send photos to Telegram channels or users through the Telegram Bot API.', + version: '1.0.0', + + params: { + botToken: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Your Telegram Bot API Token', + }, + chatId: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Target Telegram chat ID', + }, + photo: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Photo to send. Pass a file_id or HTTP URL', + }, + caption: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Photo caption (optional)', + }, + }, + + request: { + url: (params: TelegramSendPhotoParams) => + `https://api.telegram.org/bot${params.botToken}/sendPhoto`, + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params: TelegramSendPhotoParams) => { + const body: Record = { + chat_id: params.chatId, + photo: params.photo, + } + + if (params.caption) { + body.caption = convertMarkdownToHTML(params.caption) + body.parse_mode = 'HTML' + } + + return body + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + const result = data.result as TelegramPhoto + + return { + success: data.ok, + output: { + message: data.ok ? 'Photo sent successfully' : 'Failed to send photo', + data: result, + }, + } + }, + + outputs: { + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Telegram message data including optional photo(s)', + properties: { + message_id: { + type: 'number', + description: 'Unique Telegram message identifier', + }, + from: { + type: 'object', + description: 'Chat information', + properties: { + id: { type: 'number', description: 'Chat ID' }, + is_bot: { + type: 'string', + description: 'Type of chat (private, group, supergroup, channel)', + }, + first_name: { + type: 'string', + description: 'Chat username (if available)', + }, + username: { + type: 'string', + description: 'Chat title (for groups and channels)', + }, + }, + }, + chat: { + type: 'object', + description: 'Information about the bot that sent the message', + properties: { + id: { type: 'number', description: 'Bot user ID' }, + first_name: { type: 'string', description: 'Bot first name' }, + username: { type: 'string', description: 'Bot username' }, + type: { + type: 'string', + description: 'Chat type (private, group, supergroup, channel)', + }, + }, + }, + date: { + type: 'number', + description: 'Unix timestamp when message was sent', + }, + text: { + type: 'string', + description: 'Text content of the sent message (if applicable)', + }, + photo: { + type: 'array', + description: 'List of photos included in the message', + items: { + type: 'object', + properties: { + file_id: { + type: 'string', + description: 'Unique file ID of the photo', + }, + file_unique_id: { + type: 'string', + description: 'Unique identifier for this file across different bots', + }, + file_size: { + type: 'number', + description: 'Size of the photo file in bytes', + }, + width: { type: 'number', description: 'Photo width in pixels' }, + height: { type: 'number', description: 'Photo height in pixels' }, + }, + }, + }, + }, + }, + }, + } diff --git a/apps/sim/tools/telegram/types.ts b/apps/sim/tools/telegram/types.ts index 965f61c72f5..87b40fbbdf3 100644 --- a/apps/sim/tools/telegram/types.ts +++ b/apps/sim/tools/telegram/types.ts @@ -1,23 +1,172 @@ import type { ToolResponse } from '@/tools/types' -export interface TelegramMessageParams { +export interface TelegramMessage { + message_id: number + from: { + id: number + is_bot: string + first_name?: string + username?: string + } + chat?: { + id: number + first_name?: string + username?: string + type?: string + } + date: number + text?: string +} + +export interface TelegramAudio extends TelegramMessage { + voice: { + duration: 2 + mime_type: string + file_id: string + file_unique_id: string + file_size: number + } +} + +export interface TelegramPhoto extends TelegramMessage { + photo?: { + file_id: string + file_unique_id: string + file_size: number + width: number + height: number + } +} + +export interface TelegramMedia extends TelegramMessage { + format?: { + file_name: string + mime_type: string + duration: number + width: number + height: number + thumbnail: { + file_id: string + file_unique_id: string + file_size: number + width: number + height: number + } + thumb: { + file_id: string + file_unique_id: string + file_size: number + width: number + height: number + } + file_id: string + file_unique_id: string + file_size: number + } + document?: { + file_name: string + mime_type: string + thumbnail: { + file_id: string + file_unique_id: string + file_size: number + width: number + height: number + } + thumb: { + file_id: string + file_unique_id: string + file_size: number + width: number + height: number + } + file_id: string + file_unique_id: string + file_size: number + } +} + +export interface TelegramAuthParams { botToken: string chatId: string +} + +export interface TelegramSendMessageParams extends TelegramAuthParams { text: string } -export interface TelegramMessageResponse extends ToolResponse { +export interface TelegramSendPhotoParams extends TelegramAuthParams { + photo: string + caption?: string +} + +export interface TelegramSendVideoParams extends TelegramAuthParams { + video: string + caption?: string +} + +export interface TelegramSendAudioParams extends TelegramAuthParams { + audio: string + caption?: string +} + +export interface TelegramSendAnimationParams extends TelegramAuthParams { + animation: string + caption?: string +} + +export interface TelegramDeleteMessageParams extends TelegramAuthParams { + messageId: string +} + +export interface TelegramSendMessageResponse extends ToolResponse { + output: { + message: string + data?: TelegramMessage + } +} + +export interface TelegramSendMediaResponse extends ToolResponse { output: { - ok: boolean - result: { - message_id: number - chat: { - id: number - type: string - username: string - } - date: number - text: string + message: string + data?: TelegramMedia + } +} + +export interface TelegramSendAudioResponse extends ToolResponse { + output: { + message: string + data?: TelegramAudio + } +} + +export interface TelegramDeleteMessageResponse extends ToolResponse { + output: { + message: string + data?: { + ok: boolean + deleted: boolean } } } + +export interface TelegramSendPhotoResponse extends ToolResponse { + output: { + message: string + data?: TelegramPhoto + } +} + +export type TelegramResponse = + | TelegramSendMessageResponse + | TelegramSendPhotoResponse + | TelegramSendAudioResponse + | TelegramSendMediaResponse + | TelegramDeleteMessageResponse + +// Legacy type for backwards compatibility +export interface TelegramMessageParams { + botToken: string + chatId: string + text: string +} diff --git a/apps/sim/tools/telegram/video.ts b/apps/sim/tools/telegram/video.ts new file mode 100644 index 00000000000..83e1ba5ed67 --- /dev/null +++ b/apps/sim/tools/telegram/video.ts @@ -0,0 +1,269 @@ +import type { + TelegramMedia, + TelegramSendMediaResponse, + TelegramSendVideoParams, +} from '@/tools/telegram/types' +import { convertMarkdownToHTML } from '@/tools/telegram/utils' +import type { ToolConfig } from '@/tools/types' + +export const telegramSendVideoTool: ToolConfig = + { + id: 'telegram_send_video', + name: 'Telegram Send Video', + description: 'Send videos to Telegram channels or users through the Telegram Bot API.', + version: '1.0.0', + + params: { + botToken: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Your Telegram Bot API Token', + }, + chatId: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Target Telegram chat ID', + }, + video: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Video to send. Pass a file_id or HTTP URL', + }, + caption: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Video caption (optional)', + }, + }, + + request: { + url: (params: TelegramSendVideoParams) => + `https://api.telegram.org/bot${params.botToken}/sendVideo`, + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params: TelegramSendVideoParams) => { + const body: Record = { + chat_id: params.chatId, + video: params.video, + } + + if (params.caption) { + body.caption = convertMarkdownToHTML(params.caption) + body.parse_mode = 'HTML' + } + + return body + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + const result = data.result as TelegramMedia + + return { + success: data.ok, + output: { + message: data.ok ? 'Video sent successfully' : 'Failed to send video', + data: result, + }, + } + }, + + outputs: { + message: { type: 'string', description: 'Success or error message' }, + data: { + type: 'object', + description: 'Telegram message data including optional media', + properties: { + message_id: { + type: 'number', + description: 'Unique Telegram message identifier', + }, + from: { + type: 'object', + description: 'Information about the sender', + properties: { + id: { type: 'number', description: 'Sender ID' }, + is_bot: { + type: 'string', + description: 'Whether the sender is a bot', + }, + first_name: { + type: 'string', + description: "Sender's first name (if available)", + }, + username: { + type: 'string', + description: "Sender's username (if available)", + }, + }, + }, + chat: { + type: 'object', + description: 'Information about the chat where message was sent', + properties: { + id: { type: 'number', description: 'Chat ID' }, + first_name: { + type: 'string', + description: 'Chat first name (if private chat)', + }, + username: { + type: 'string', + description: 'Chat username (for private or channels)', + }, + type: { + type: 'string', + description: 'Type of chat (private, group, supergroup, or channel)', + }, + }, + }, + date: { + type: 'number', + description: 'Unix timestamp when the message was sent', + }, + text: { + type: 'string', + description: 'Text content of the sent message (if applicable)', + }, + format: { + type: 'object', + description: 'Media format information (for videos, GIFs, etc.)', + properties: { + file_name: { type: 'string', description: 'Media file name' }, + mime_type: { type: 'string', description: 'Media MIME type' }, + duration: { + type: 'number', + description: 'Duration of media in seconds', + }, + width: { type: 'number', description: 'Media width in pixels' }, + height: { type: 'number', description: 'Media height in pixels' }, + thumbnail: { + type: 'object', + description: 'Thumbnail image details', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + thumb: { + type: 'object', + description: 'Secondary thumbnail details (duplicate of thumbnail)', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + file_id: { type: 'string', description: 'Media file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique media file identifier', + }, + file_size: { + type: 'number', + description: 'Size of media file in bytes', + }, + }, + }, + document: { + type: 'object', + description: 'Document file details if the message contains a document', + properties: { + file_name: { type: 'string', description: 'Document file name' }, + mime_type: { type: 'string', description: 'Document MIME type' }, + thumbnail: { + type: 'object', + description: 'Document thumbnail information', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + thumb: { + type: 'object', + description: 'Duplicate thumbnail info (used for compatibility)', + properties: { + file_id: { type: 'string', description: 'Thumbnail file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique thumbnail file identifier', + }, + file_size: { + type: 'number', + description: 'Thumbnail file size in bytes', + }, + width: { + type: 'number', + description: 'Thumbnail width in pixels', + }, + height: { + type: 'number', + description: 'Thumbnail height in pixels', + }, + }, + }, + file_id: { type: 'string', description: 'Document file ID' }, + file_unique_id: { + type: 'string', + description: 'Unique document file identifier', + }, + file_size: { + type: 'number', + description: 'Size of document file in bytes', + }, + }, + }, + }, + }, + }, + } From 5f1bc4c47e42084604b42bd90b5f818aabb91301 Mon Sep 17 00:00:00 2001 From: SimplyRohit Date: Wed, 8 Oct 2025 10:43:59 +0530 Subject: [PATCH 2/5] fix: updated Telegram tool types and removed debug logs --- apps/sim/blocks/blocks/telegram.ts | 75 +++++++++++----------------- apps/sim/tools/telegram/animation.ts | 4 +- apps/sim/tools/telegram/audio.ts | 28 ++++++++--- apps/sim/tools/telegram/delete.ts | 1 - apps/sim/tools/telegram/message.ts | 4 +- apps/sim/tools/telegram/photo.ts | 4 +- apps/sim/tools/telegram/types.ts | 4 +- apps/sim/tools/telegram/video.ts | 4 +- 8 files changed, 59 insertions(+), 65 deletions(-) diff --git a/apps/sim/blocks/blocks/telegram.ts b/apps/sim/blocks/blocks/telegram.ts index 27866368634..28fb8f22d05 100644 --- a/apps/sim/blocks/blocks/telegram.ts +++ b/apps/sim/blocks/blocks/telegram.ts @@ -64,6 +64,7 @@ export const TelegramBlock: BlockConfig = { type: 'long-input', layout: 'full', placeholder: 'Enter the message to send', + required: true, condition: { field: 'operation', value: 'telegram_send_message' }, }, { @@ -73,15 +74,7 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter photo URL or file_id', description: 'Photo to send. Pass a file_id or HTTP URL', - condition: { field: 'operation', value: 'telegram_send_photo' }, - }, - { - id: 'caption', - title: 'Caption', - type: 'long-input', - layout: 'full', - placeholder: 'Enter optional caption', - description: 'Photo caption (optional)', + required: true, condition: { field: 'operation', value: 'telegram_send_photo' }, }, { @@ -91,15 +84,7 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter video URL or file_id', description: 'Video to send. Pass a file_id or HTTP URL', - condition: { field: 'operation', value: 'telegram_send_video' }, - }, - { - id: 'videoCaption', - title: 'Caption', - type: 'long-input', - layout: 'full', - placeholder: 'Enter optional caption', - description: 'Video caption (optional)', + required: true, condition: { field: 'operation', value: 'telegram_send_video' }, }, { @@ -109,15 +94,7 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter audio URL or file_id', description: 'Audio file to send. Pass a file_id or HTTP URL', - condition: { field: 'operation', value: 'telegram_send_audio' }, - }, - { - id: 'audioCaption', - title: 'Caption', - type: 'long-input', - layout: 'full', - placeholder: 'Enter optional caption', - description: 'Audio caption (optional)', + required: true, condition: { field: 'operation', value: 'telegram_send_audio' }, }, { @@ -127,16 +104,25 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter animation URL or file_id', description: 'Animation (GIF) to send. Pass a file_id or HTTP URL', + required: true, condition: { field: 'operation', value: 'telegram_send_animation' }, }, { - id: 'animationCaption', + id: 'caption', title: 'Caption', type: 'long-input', layout: 'full', placeholder: 'Enter optional caption', - description: 'Animation caption (optional)', - condition: { field: 'operation', value: 'telegram_send_animation' }, + description: 'Media caption (optional)', + condition: { + field: 'operation', + value: [ + 'telegram_send_photo', + 'telegram_send_video', + 'telegram_send_audio', + 'telegram_send_animation', + ], + }, }, { id: 'messageId', @@ -145,6 +131,7 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter the message ID to delete', description: 'The unique identifier of the message you want to delete', + required: true, condition: { field: 'operation', value: 'telegram_delete_message' }, }, // TRIGGER MODE: Trigger configuration (only shown when trigger mode is active) @@ -186,21 +173,25 @@ export const TelegramBlock: BlockConfig = { } }, params: (params) => { - const commonParams: Record = {} - if (!params.botToken) throw new Error('Bot token required for this operation') - commonParams.botToken = params.botToken const chatId = (params.chatId || '').trim() if (!chatId) { throw new Error('Chat ID is required.') } + const commonParams = { + botToken: params.botToken, + chatId, + } + switch (params.operation) { case 'telegram_send_message': + if (!params.text) { + throw new Error('Message text is required.') + } return { ...commonParams, - chatId, text: params.text, } case 'telegram_delete_message': @@ -209,7 +200,6 @@ export const TelegramBlock: BlockConfig = { } return { ...commonParams, - chatId, messageId: params.messageId, } case 'telegram_send_photo': @@ -218,7 +208,6 @@ export const TelegramBlock: BlockConfig = { } return { ...commonParams, - chatId, photo: params.photo, caption: params.caption, } @@ -228,9 +217,8 @@ export const TelegramBlock: BlockConfig = { } return { ...commonParams, - chatId, video: params.video, - caption: params.videoCaption, + caption: params.caption, } case 'telegram_send_audio': if (!params.audio) { @@ -238,9 +226,8 @@ export const TelegramBlock: BlockConfig = { } return { ...commonParams, - chatId, audio: params.audio, - caption: params.audioCaption, + caption: params.caption, } case 'telegram_send_animation': if (!params.animation) { @@ -248,14 +235,13 @@ export const TelegramBlock: BlockConfig = { } return { ...commonParams, - chatId, animation: params.animation, - caption: params.animationCaption, + caption: params.caption, } default: return { ...commonParams, - chatId, + text: params.text, } } }, @@ -271,9 +257,6 @@ export const TelegramBlock: BlockConfig = { audio: { type: 'string', description: 'Audio URL or file_id' }, animation: { type: 'string', description: 'Animation URL or file_id' }, caption: { type: 'string', description: 'Caption for media' }, - videoCaption: { type: 'string', description: 'Caption for video' }, - audioCaption: { type: 'string', description: 'Caption for audio' }, - animationCaption: { type: 'string', description: 'Caption for animation' }, messageId: { type: 'string', description: 'Message ID to delete' }, }, outputs: { diff --git a/apps/sim/tools/telegram/animation.ts b/apps/sim/tools/telegram/animation.ts index f373b2b15bf..4b728b26442 100644 --- a/apps/sim/tools/telegram/animation.ts +++ b/apps/sim/tools/telegram/animation.ts @@ -92,8 +92,8 @@ export const telegramSendAnimationTool: ToolConfig< properties: { id: { type: 'number', description: 'Sender ID' }, is_bot: { - type: 'string', - description: 'Whether the sender is a bot', + type: 'boolean', + description: 'Whether the chat is a bot or not', }, first_name: { type: 'string', diff --git a/apps/sim/tools/telegram/audio.ts b/apps/sim/tools/telegram/audio.ts index 0d48a44c0b7..bee70fcb032 100644 --- a/apps/sim/tools/telegram/audio.ts +++ b/apps/sim/tools/telegram/audio.ts @@ -91,8 +91,8 @@ export const telegramSendAudioTool: ToolConfig { const data = await response.json() - console.log(data.result) return { success: data.ok, output: { diff --git a/apps/sim/tools/telegram/message.ts b/apps/sim/tools/telegram/message.ts index 2004a441a64..6cb72a06ec0 100644 --- a/apps/sim/tools/telegram/message.ts +++ b/apps/sim/tools/telegram/message.ts @@ -80,8 +80,8 @@ export const telegramSendMessageTool: ToolConfig< properties: { id: { type: 'number', description: 'Chat ID' }, is_bot: { - type: 'string', - description: 'Type of chat (private, group, supergroup, channel)', + type: 'boolean', + description: 'Whether the chat is a bot or not', }, first_name: { type: 'string', diff --git a/apps/sim/tools/telegram/photo.ts b/apps/sim/tools/telegram/photo.ts index c6b68f5932b..6c1d54a15cb 100644 --- a/apps/sim/tools/telegram/photo.ts +++ b/apps/sim/tools/telegram/photo.ts @@ -91,8 +91,8 @@ export const telegramSendPhotoTool: ToolConfig Date: Tue, 14 Oct 2025 11:59:03 -0700 Subject: [PATCH 3/5] reverted telegram message tool to older name --- apps/sim/blocks/blocks/telegram.ts | 16 ++++++++-------- apps/sim/tools/registry.ts | 4 ++-- .../telegram/{delete.ts => delete_message.ts} | 0 apps/sim/tools/telegram/index.ts | 6 +++--- apps/sim/tools/telegram/message.ts | 4 ++-- .../telegram/{animation.ts => send_animation.ts} | 0 .../tools/telegram/{audio.ts => send_audio.ts} | 0 .../tools/telegram/{photo.ts => send_photo.ts} | 0 .../tools/telegram/{video.ts => send_video.ts} | 0 9 files changed, 15 insertions(+), 15 deletions(-) rename apps/sim/tools/telegram/{delete.ts => delete_message.ts} (100%) rename apps/sim/tools/telegram/{animation.ts => send_animation.ts} (100%) rename apps/sim/tools/telegram/{audio.ts => send_audio.ts} (100%) rename apps/sim/tools/telegram/{photo.ts => send_photo.ts} (100%) rename apps/sim/tools/telegram/{video.ts => send_video.ts} (100%) diff --git a/apps/sim/blocks/blocks/telegram.ts b/apps/sim/blocks/blocks/telegram.ts index 28fb8f22d05..727411bdbb0 100644 --- a/apps/sim/blocks/blocks/telegram.ts +++ b/apps/sim/blocks/blocks/telegram.ts @@ -22,14 +22,14 @@ export const TelegramBlock: BlockConfig = { type: 'dropdown', layout: 'full', options: [ - { label: 'Send Message', id: 'telegram_send_message' }, + { label: 'Send Message', id: 'telegram_message' }, { label: 'Send Photo', id: 'telegram_send_photo' }, { label: 'Send Video', id: 'telegram_send_video' }, { label: 'Send Audio', id: 'telegram_send_audio' }, { label: 'Send Animation', id: 'telegram_send_animation' }, { label: 'Delete Message', id: 'telegram_delete_message' }, ], - value: () => 'telegram_send_message', + value: () => 'telegram_message', }, { id: 'botToken', @@ -65,7 +65,7 @@ export const TelegramBlock: BlockConfig = { layout: 'full', placeholder: 'Enter the message to send', required: true, - condition: { field: 'operation', value: 'telegram_send_message' }, + condition: { field: 'operation', value: 'telegram_message' }, }, { id: 'photo', @@ -146,7 +146,7 @@ export const TelegramBlock: BlockConfig = { ], tools: { access: [ - 'telegram_send_message', + 'telegram_message', 'telegram_delete_message', 'telegram_send_photo', 'telegram_send_video', @@ -156,8 +156,8 @@ export const TelegramBlock: BlockConfig = { config: { tool: (params) => { switch (params.operation) { - case 'telegram_send_message': - return 'telegram_send_message' + case 'telegram_message': + return 'telegram_message' case 'telegram_delete_message': return 'telegram_delete_message' case 'telegram_send_photo': @@ -169,7 +169,7 @@ export const TelegramBlock: BlockConfig = { case 'telegram_send_animation': return 'telegram_send_animation' default: - return 'telegram_send_message' + return 'telegram_message' } }, params: (params) => { @@ -186,7 +186,7 @@ export const TelegramBlock: BlockConfig = { } switch (params.operation) { - case 'telegram_send_message': + case 'telegram_message': if (!params.text) { throw new Error('Message text is required.') } diff --git a/apps/sim/tools/registry.ts b/apps/sim/tools/registry.ts index 3464efa648b..fda2fb95b95 100644 --- a/apps/sim/tools/registry.ts +++ b/apps/sim/tools/registry.ts @@ -177,9 +177,9 @@ import { import { tavilyExtractTool, tavilySearchTool } from '@/tools/tavily' import { telegramDeleteMessageTool, + telegramMessageTool, telegramSendAnimationTool, telegramSendAudioTool, - telegramSendMessageTool, telegramSendPhotoTool, telegramSendVideoTool, } from '@/tools/telegram' @@ -332,7 +332,7 @@ export const tools: Record = { knowledge_create_document: knowledgeCreateDocumentTool, elevenlabs_tts: elevenLabsTtsTool, s3_get_object: s3GetObjectTool, - telegram_send_message: telegramSendMessageTool, + telegram_message: telegramMessageTool, telegram_delete_message: telegramDeleteMessageTool, telegram_send_audio: telegramSendAudioTool, telegram_send_animation: telegramSendAnimationTool, diff --git a/apps/sim/tools/telegram/delete.ts b/apps/sim/tools/telegram/delete_message.ts similarity index 100% rename from apps/sim/tools/telegram/delete.ts rename to apps/sim/tools/telegram/delete_message.ts diff --git a/apps/sim/tools/telegram/index.ts b/apps/sim/tools/telegram/index.ts index 8e1a098f216..a99090622e5 100644 --- a/apps/sim/tools/telegram/index.ts +++ b/apps/sim/tools/telegram/index.ts @@ -1,15 +1,15 @@ -import { telegramSendAnimationTool } from '@/tools/telegram/animation' import { telegramSendAudioTool } from '@/tools/telegram/audio' import { telegramDeleteMessageTool } from '@/tools/telegram/delete' -import { telegramSendMessageTool } from '@/tools/telegram/message' +import { telegramMessageTool } from '@/tools/telegram/message' import { telegramSendPhotoTool } from '@/tools/telegram/photo' +import { telegramSendAnimationTool } from '@/tools/telegram/send_animation' import { telegramSendVideoTool } from '@/tools/telegram/video' export { telegramSendAnimationTool, telegramSendAudioTool, telegramDeleteMessageTool, - telegramSendMessageTool, + telegramMessageTool, telegramSendPhotoTool, telegramSendVideoTool, } diff --git a/apps/sim/tools/telegram/message.ts b/apps/sim/tools/telegram/message.ts index 6cb72a06ec0..1a86b542605 100644 --- a/apps/sim/tools/telegram/message.ts +++ b/apps/sim/tools/telegram/message.ts @@ -6,11 +6,11 @@ import type { import { convertMarkdownToHTML } from '@/tools/telegram/utils' import type { ToolConfig } from '@/tools/types' -export const telegramSendMessageTool: ToolConfig< +export const telegramMessageTool: ToolConfig< TelegramSendMessageParams, TelegramSendMessageResponse > = { - id: 'telegram_send_message', + id: 'telegram_message', name: 'Telegram Send Message', description: 'Send messages to Telegram channels or users through the Telegram Bot API. Enables direct communication and notifications with message tracking and chat confirmation.', diff --git a/apps/sim/tools/telegram/animation.ts b/apps/sim/tools/telegram/send_animation.ts similarity index 100% rename from apps/sim/tools/telegram/animation.ts rename to apps/sim/tools/telegram/send_animation.ts diff --git a/apps/sim/tools/telegram/audio.ts b/apps/sim/tools/telegram/send_audio.ts similarity index 100% rename from apps/sim/tools/telegram/audio.ts rename to apps/sim/tools/telegram/send_audio.ts diff --git a/apps/sim/tools/telegram/photo.ts b/apps/sim/tools/telegram/send_photo.ts similarity index 100% rename from apps/sim/tools/telegram/photo.ts rename to apps/sim/tools/telegram/send_photo.ts diff --git a/apps/sim/tools/telegram/video.ts b/apps/sim/tools/telegram/send_video.ts similarity index 100% rename from apps/sim/tools/telegram/video.ts rename to apps/sim/tools/telegram/send_video.ts From fd7acccdd29b015ace9f5df5d423a0dcc276a785 Mon Sep 17 00:00:00 2001 From: waleed Date: Tue, 14 Oct 2025 12:06:28 -0700 Subject: [PATCH 4/5] added docs for telegram --- apps/docs/content/docs/en/tools/telegram.mdx | 111 ++++++++++++++++-- .../components/user-input/user-input.tsx | 4 +- 2 files changed, 105 insertions(+), 10 deletions(-) diff --git a/apps/docs/content/docs/en/tools/telegram.mdx b/apps/docs/content/docs/en/tools/telegram.mdx index 34a364230e1..97628a0b454 100644 --- a/apps/docs/content/docs/en/tools/telegram.mdx +++ b/apps/docs/content/docs/en/tools/telegram.mdx @@ -1,6 +1,6 @@ --- title: Telegram -description: Send messages through Telegram or trigger workflows from Telegram events +description: Interact with Telegram --- import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -67,7 +67,7 @@ In Sim, the Telegram integration enables your agents to leverage these powerful ## Usage Instructions -Integrate Telegram into the workflow. Can send messages. Can be used in trigger mode to trigger a workflow when a message is sent to a chat. +Integrate Telegram into the workflow. Can send and delete messages. Can be used in trigger mode to trigger a workflow when a message is sent to a chat. @@ -89,12 +89,107 @@ Send messages to Telegram channels or users through the Telegram Bot API. Enable | Parameter | Type | Description | | --------- | ---- | ----------- | -| `success` | boolean | Telegram message send success status | -| `messageId` | number | Unique Telegram message identifier | -| `chatId` | string | Target chat ID where message was sent | -| `text` | string | Text content of the sent message | -| `timestamp` | number | Unix timestamp when message was sent | -| `from` | object | Information about the bot that sent the message | +| `message` | string | Success or error message | +| `data` | object | Telegram message data | + +### `telegram_delete_message` + +Delete messages in Telegram channels or chats through the Telegram Bot API. Requires the message ID of the message to delete. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `botToken` | string | Yes | Your Telegram Bot API Token | +| `chatId` | string | Yes | Target Telegram chat ID | +| `messageId` | string | Yes | Message ID to delete | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `message` | string | Success or error message | +| `data` | object | Delete operation result | + +### `telegram_send_photo` + +Send photos to Telegram channels or users through the Telegram Bot API. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `botToken` | string | Yes | Your Telegram Bot API Token | +| `chatId` | string | Yes | Target Telegram chat ID | +| `photo` | string | Yes | Photo to send. Pass a file_id or HTTP URL | +| `caption` | string | No | Photo caption \(optional\) | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `message` | string | Success or error message | +| `data` | object | Telegram message data including optional photo\(s\) | + +### `telegram_send_video` + +Send videos to Telegram channels or users through the Telegram Bot API. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `botToken` | string | Yes | Your Telegram Bot API Token | +| `chatId` | string | Yes | Target Telegram chat ID | +| `video` | string | Yes | Video to send. Pass a file_id or HTTP URL | +| `caption` | string | No | Video caption \(optional\) | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `message` | string | Success or error message | +| `data` | object | Telegram message data including optional media | + +### `telegram_send_audio` + +Send audio files to Telegram channels or users through the Telegram Bot API. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `botToken` | string | Yes | Your Telegram Bot API Token | +| `chatId` | string | Yes | Target Telegram chat ID | +| `audio` | string | Yes | Audio file to send. Pass a file_id or HTTP URL | +| `caption` | string | No | Audio caption \(optional\) | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `message` | string | Success or error message | +| `data` | object | Telegram message data including voice/audio information | + +### `telegram_send_animation` + +Send animations (GIFs) to Telegram channels or users through the Telegram Bot API. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `botToken` | string | Yes | Your Telegram Bot API Token | +| `chatId` | string | Yes | Target Telegram chat ID | +| `animation` | string | Yes | Animation to send. Pass a file_id or HTTP URL | +| `caption` | string | No | Animation caption \(optional\) | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `message` | string | Success or error message | +| `data` | object | Telegram message data including optional media | diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx index d2a98dc7488..ebb6e47a1ec 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx @@ -2054,7 +2054,7 @@ const UserInput = forwardRef( {/* Highlight overlay */}
                 {(() => {
@@ -2102,7 +2102,7 @@ const UserInput = forwardRef(
               placeholder={isDragging ? 'Drop files here...' : effectivePlaceholder}
               disabled={disabled}
               rows={1}
-              className='relative z-[2] mb-2 min-h-[32px] w-full resize-none overflow-y-auto overflow-x-hidden break-words border-0 bg-transparent pl-[2px] pr-14 py-1 font-sans text-sm text-transparent leading-[1.25rem] caret-foreground focus-visible:ring-0 focus-visible:ring-offset-0'
+              className='relative z-[2] mb-2 min-h-[32px] w-full resize-none overflow-y-auto overflow-x-hidden break-words border-0 bg-transparent py-1 pr-14 pl-[2px] font-sans text-sm text-transparent leading-[1.25rem] caret-foreground focus-visible:ring-0 focus-visible:ring-offset-0'
               style={{ height: 'auto', wordBreak: 'break-word' }}
             />
 

From 5b92fb0db34c5ea7903d72906928cf45d374c606 Mon Sep 17 00:00:00 2001
From: waleed 
Date: Tue, 14 Oct 2025 15:31:00 -0700
Subject: [PATCH 5/5] updated telegram docs

---
 apps/docs/content/docs/en/tools/telegram.mdx | 8 ++++++--
 apps/sim/tools/telegram/index.ts             | 8 ++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/apps/docs/content/docs/en/tools/telegram.mdx b/apps/docs/content/docs/en/tools/telegram.mdx
index 97628a0b454..22e9c743497 100644
--- a/apps/docs/content/docs/en/tools/telegram.mdx
+++ b/apps/docs/content/docs/en/tools/telegram.mdx
@@ -89,8 +89,12 @@ Send messages to Telegram channels or users through the Telegram Bot API. Enable
 
 | Parameter | Type | Description |
 | --------- | ---- | ----------- |
-| `message` | string | Success or error message |
-| `data` | object | Telegram message data |
+| `success` | boolean | Telegram message send success status |
+| `messageId` | number | Unique Telegram message identifier |
+| `chatId` | string | Target chat ID where message was sent |
+| `text` | string | Text content of the sent message |
+| `timestamp` | number | Unix timestamp when message was sent |
+| `from` | object | Information about the bot that sent the message |
 
 ### `telegram_delete_message`
 
diff --git a/apps/sim/tools/telegram/index.ts b/apps/sim/tools/telegram/index.ts
index a99090622e5..567a4d016b6 100644
--- a/apps/sim/tools/telegram/index.ts
+++ b/apps/sim/tools/telegram/index.ts
@@ -1,9 +1,9 @@
-import { telegramSendAudioTool } from '@/tools/telegram/audio'
-import { telegramDeleteMessageTool } from '@/tools/telegram/delete'
+import { telegramDeleteMessageTool } from '@/tools/telegram/delete_message'
 import { telegramMessageTool } from '@/tools/telegram/message'
-import { telegramSendPhotoTool } from '@/tools/telegram/photo'
 import { telegramSendAnimationTool } from '@/tools/telegram/send_animation'
-import { telegramSendVideoTool } from '@/tools/telegram/video'
+import { telegramSendAudioTool } from '@/tools/telegram/send_audio'
+import { telegramSendPhotoTool } from '@/tools/telegram/send_photo'
+import { telegramSendVideoTool } from '@/tools/telegram/send_video'
 
 export {
   telegramSendAnimationTool,