fix: require thread specs for telegram sends

This commit is contained in:
Ayaan Zaidi
2026-02-02 09:05:36 +05:30
committed by Ayaan Zaidi
parent 19b8416a81
commit 1d7dd5f261
5 changed files with 22 additions and 20 deletions

View File

@@ -69,18 +69,12 @@ export function resolveTelegramThreadSpec(params: {
* General forum topic (id=1) must be treated like a regular supergroup send:
* Telegram rejects sendMessage/sendMedia with message_thread_id=1 ("thread not found").
*/
export function buildTelegramThreadParams(thread?: TelegramThreadSpec | number | null) {
let spec: TelegramThreadSpec | undefined;
if (typeof thread === "number") {
spec = { id: thread, scope: "forum" };
} else if (thread && typeof thread === "object") {
spec = thread;
}
if (!spec?.id) {
export function buildTelegramThreadParams(thread?: TelegramThreadSpec | null) {
if (!thread?.id) {
return undefined;
}
const normalized = Math.trunc(spec.id);
if (normalized === TELEGRAM_GENERAL_TOPIC_ID && spec.scope === "forum") {
const normalized = Math.trunc(thread.id);
if (normalized === TELEGRAM_GENERAL_TOPIC_ID && thread.scope === "forum") {
return undefined;
}
return { message_thread_id: normalized };