From 29d9d875a790ca3a9808ecda85aff51f59a3479b Mon Sep 17 00:00:00 2001 From: Muhammed Mukhthar CM Date: Tue, 27 Jan 2026 10:10:58 +0000 Subject: [PATCH] telegram-user: align outbound reply + chunking --- extensions/telegram-user/src/channel.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/extensions/telegram-user/src/channel.ts b/extensions/telegram-user/src/channel.ts index 59d8519a6..45d59fb89 100644 --- a/extensions/telegram-user/src/channel.ts +++ b/extensions/telegram-user/src/channel.ts @@ -58,6 +58,12 @@ type TelegramUserSetupInput = ChannelSetupInput & { apiHash?: string; }; +function parseReplyToId(replyToId?: string | null): number | undefined { + if (!replyToId) return undefined; + const parsed = Number.parseInt(replyToId, 10); + return Number.isFinite(parsed) ? parsed : undefined; +} + function normalizeTelegramUserGroupKey(raw?: string | null): string | undefined { if (!raw) return undefined; const trimmed = raw.trim(); @@ -238,16 +244,20 @@ export const telegramUserPlugin: ChannelPlugin = { deliveryMode: "direct", chunker: (text, limit) => getTelegramUserRuntime().channel.text.chunkMarkdownText(text, limit), + chunkerMode: "markdown", textChunkLimit: 4000, pollMaxOptions: 10, - sendText: async ({ to, text, accountId, threadId }) => { + sendText: async ({ to, text, accountId, threadId, replyToId }) => { + const parsedReplyToId = parseReplyToId(replyToId); const result = await sendMessageTelegramUser(to, text, { accountId: accountId ?? undefined, threadId, + ...(parsedReplyToId ? { replyToId: parsedReplyToId } : {}), }); return { channel: "telegram-user", ...result }; }, - sendMedia: async ({ cfg, to, text, mediaUrl, accountId, threadId }) => { + sendMedia: async ({ cfg, to, text, mediaUrl, accountId, threadId, replyToId }) => { + const parsedReplyToId = parseReplyToId(replyToId); const maxBytes = resolveChannelMediaMaxBytes({ cfg, resolveChannelLimitMb: ({ cfg, accountId }) => @@ -261,14 +271,17 @@ export const telegramUserPlugin: ChannelPlugin = { accountId: accountId ?? undefined, mediaUrl, threadId, + ...(parsedReplyToId ? { replyToId: parsedReplyToId } : {}), ...(maxBytes ? { maxBytes } : {}), }); return { channel: "telegram-user", ...result }; }, - sendPoll: async ({ to, poll, accountId, threadId }) => { + sendPoll: async ({ to, poll, accountId, threadId, replyToId }) => { + const parsedReplyToId = parseReplyToId(replyToId); const result = await sendPollTelegramUser(to, poll, { accountId: accountId ?? undefined, threadId, + ...(parsedReplyToId ? { replyToId: parsedReplyToId } : {}), }); return { channel: "telegram-user", ...result }; },