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,