From f4488a079f3b859aa6a85ae85cc23324c06aa5a4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 22 Mar 2026 12:39:42 +0100 Subject: [PATCH] fix: add getChat before forwardMessages and debug logging for bot sends The bot may not have the source channel loaded in TDLib's internal state. Calling getChat first ensures it's resolved. Also added result logging to diagnose silent send failures. Co-Authored-By: Claude Opus 4.6 (1M context) --- bot/src/tdlib/client.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bot/src/tdlib/client.ts b/bot/src/tdlib/client.ts index a0c0442..6b14584 100644 --- a/bot/src/tdlib/client.ts +++ b/bot/src/tdlib/client.ts @@ -69,7 +69,7 @@ export async function closeBotClient(): Promise { /** * Copy a message from a channel to a user's DM. - * Uses forwardMessages (not send_copy) to forward the file directly. + * Uses forwardMessages with send_copy so it appears sent by the bot. * * The fromChatId is the Telegram chat ID from the DB (e.g. -1003767441152). * The messageId is the TDLib message ID stored in the DB. @@ -84,9 +84,16 @@ export async function copyMessageToUser( log.info( { fromChatId: fromChatId.toString(), messageId: messageId.toString(), toUserId: toUserId.toString() }, - "Forwarding message to user" + "Copying message to user" ); + // First, ensure TDLib knows about the source chat by opening it + try { + await c.invoke({ _: "getChat", chat_id: Number(fromChatId) }); + } catch (err) { + log.warn({ err, chatId: fromChatId.toString() }, "getChat failed for source channel"); + } + const result = await withFloodWait( () => c.invoke({ @@ -94,13 +101,18 @@ export async function copyMessageToUser( chat_id: Number(toUserId), from_chat_id: Number(fromChatId), message_ids: [Number(messageId)], - send_copy: false, + send_copy: true, remove_caption: false, }), "copyMessageToUser" ); - log.info({ result: JSON.stringify(result) }, "forwardMessages result"); + // forwardMessages returns immediately with temp messages — check result + const messages = (result as { messages?: unknown[] })?.messages; + log.info( + { messageCount: messages?.length ?? 0, result: JSON.stringify(result).slice(0, 500) }, + "forwardMessages result" + ); } /**