From 48f8302ebfbc72b4f71a2cb5bf2ece57bbe2e972 Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:37:57 +0800 Subject: [PATCH] feat(telegram): handle voice and audio messages with placeholder Forward voice messages and audio files to the agent as placeholder text. In groups, only process voice/audio that replies to the bot. Includes caption text if present. Co-Authored-By: Claude Opus 4.6 --- src/channels/plugins/telegram.ts | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/channels/plugins/telegram.ts b/src/channels/plugins/telegram.ts index e1922b57..3174c5a8 100644 --- a/src/channels/plugins/telegram.ts +++ b/src/channels/plugins/telegram.ts @@ -120,6 +120,51 @@ export const telegramChannel: ChannelPlugin = { }); }); + // Handle voice messages — forward as placeholder + bot.on("message:voice", (ctx) => { + const msg = ctx.message; + const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup"; + + // In groups, only respond if replied to the bot + if (isGroup) { + const isReplyToBot = msg.reply_to_message?.from?.is_bot === true; + if (!isReplyToBot) return; + } + + console.log(`[Telegram] Received voice message: chatId=${msg.chat.id} from=${msg.from?.id} duration=${msg.voice.duration}s`); + + const caption = msg.caption ? ` ${msg.caption}` : ""; + onMessage({ + messageId: String(msg.message_id), + conversationId: String(msg.chat.id), + senderId: String(msg.from?.id ?? "unknown"), + text: `${caption}`, + chatType: isGroup ? "group" : "direct", + }); + }); + + // Handle audio file messages (music files, etc.) + bot.on("message:audio", (ctx) => { + const msg = ctx.message; + const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup"; + + if (isGroup) { + const isReplyToBot = msg.reply_to_message?.from?.is_bot === true; + if (!isReplyToBot) return; + } + + console.log(`[Telegram] Received audio file: chatId=${msg.chat.id} from=${msg.from?.id} title=${msg.audio.title ?? "unknown"}`); + + const caption = msg.caption ? ` ${msg.caption}` : ""; + onMessage({ + messageId: String(msg.message_id), + conversationId: String(msg.chat.id), + senderId: String(msg.from?.id ?? "unknown"), + text: `${caption}`, + chatType: isGroup ? "group" : "direct", + }); + }); + // Graceful shutdown on abort signal.addEventListener("abort", () => { console.log("[Telegram] Bot stopped");