From ff292e67cec85decae68626517e09c2a7959d136 Mon Sep 17 00:00:00 2001 From: Azade Date: Mon, 12 Jan 2026 10:49:33 +0000 Subject: [PATCH] fix(telegram): show typing indicator in General forum topic In forum supergroups, messages from the General topic arrive without message_thread_id in updates, but sendChatAction requires one to display the typing indicator in the correct topic. Use message_thread_id=1 (Telegram's internal ID for General topic) as fallback when messageThreadId is undefined in a forum chat. --- src/telegram/bot.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/telegram/bot.ts b/src/telegram/bot.ts index 8e430a0a7..e23bac5f7 100644 --- a/src/telegram/bot.ts +++ b/src/telegram/bot.ts @@ -1,4 +1,11 @@ // @ts-nocheck +/** + * Telegram uses message_thread_id=1 internally for the General topic in forum supergroups. + * User-created topics have IDs based on message_id (typically millions+), so no collision risk. + * See: https://core.telegram.org/bots/api#sendchataction + */ +const TELEGRAM_GENERAL_TOPIC_ID = 1; + import { sequentialize } from "@grammyjs/runner"; import { apiThrottler } from "@grammyjs/transformer-throttler"; import type { ApiClientOptions, Message } from "grammy"; @@ -426,10 +433,16 @@ export function createTelegramBot(opts: TelegramBotOptions) { const sendTyping = async () => { try { + // In forums, the General topic has no message_thread_id in updates, + // but sendChatAction requires one to show typing. + const typingThreadId = + isForum && messageThreadId == null + ? TELEGRAM_GENERAL_TOPIC_ID + : messageThreadId; await bot.api.sendChatAction( chatId, "typing", - buildTelegramThreadParams(messageThreadId), + buildTelegramThreadParams(typingThreadId), ); } catch (err) { logVerbose(