From 4ae5687b617740e1fb3def2932427cab8224cf17 Mon Sep 17 00:00:00 2001 From: Clawdbot Date: Wed, 28 Jan 2026 21:29:39 +0100 Subject: [PATCH] fix(telegram): restore DM thread delivery after forum-only gate Commit 9154971 changed resolveTelegramForumThreadId to return undefined when is_forum is false. This broke DM thread delivery because Telegram Bot API never sets is_forum=true for private chats. Introduce effectiveThreadId that uses raw messageThreadId for DMs while preserving forum-resolved value for groups. --- src/telegram/bot-message-context.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/telegram/bot-message-context.ts b/src/telegram/bot-message-context.ts index ccc9407cf..bf4d6baaa 100644 --- a/src/telegram/bot-message-context.ts +++ b/src/telegram/bot-message-context.ts @@ -161,6 +161,9 @@ export const buildTelegramMessageContext = async ({ isForum, messageThreadId, }); + // Effective thread ID for outbound delivery: groups use forum-resolved; DMs use raw messageThreadId + // (private chats never set is_forum=true per Telegram Bot API, so resolvedThreadId is always undefined for DMs) + const effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId; const { groupConfig, topicConfig } = resolveTelegramGroupConfig(chatId, resolvedThreadId); const peerId = isGroup ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : String(chatId); const route = resolveAgentRoute({ @@ -203,7 +206,8 @@ export const buildTelegramMessageContext = async ({ const sendTyping = async () => { await withTelegramApiErrorLogging({ operation: "sendChatAction", - fn: () => bot.api.sendChatAction(chatId, "typing", buildTypingThreadParams(resolvedThreadId)), + fn: () => + bot.api.sendChatAction(chatId, "typing", buildTypingThreadParams(effectiveThreadId)), }); }; @@ -212,7 +216,11 @@ export const buildTelegramMessageContext = async ({ await withTelegramApiErrorLogging({ operation: "sendChatAction", fn: () => - bot.api.sendChatAction(chatId, "record_voice", buildTypingThreadParams(resolvedThreadId)), + bot.api.sendChatAction( + chatId, + "record_voice", + buildTypingThreadParams(effectiveThreadId), + ), }); } catch (err) { logVerbose(`telegram record_voice cue failed for chat ${chatId}: ${String(err)}`); @@ -658,7 +666,7 @@ export const buildTelegramMessageContext = async ({ msg, chatId, isGroup, - resolvedThreadId, + resolvedThreadId: effectiveThreadId, isForum, historyKey, historyLimit,