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.
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
// @ts-nocheck
|
// @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 { sequentialize } from "@grammyjs/runner";
|
||||||
import { apiThrottler } from "@grammyjs/transformer-throttler";
|
import { apiThrottler } from "@grammyjs/transformer-throttler";
|
||||||
import type { ApiClientOptions, Message } from "grammy";
|
import type { ApiClientOptions, Message } from "grammy";
|
||||||
@@ -426,10 +433,16 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
|
|
||||||
const sendTyping = async () => {
|
const sendTyping = async () => {
|
||||||
try {
|
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(
|
await bot.api.sendChatAction(
|
||||||
chatId,
|
chatId,
|
||||||
"typing",
|
"typing",
|
||||||
buildTelegramThreadParams(messageThreadId),
|
buildTelegramThreadParams(typingThreadId),
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logVerbose(
|
logVerbose(
|
||||||
|
|||||||
Reference in New Issue
Block a user