mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-10 22:01:16 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
@@ -69,7 +69,7 @@ export async function closeBotClient(): Promise<void> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a message from a channel to a user's DM.
|
* 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 fromChatId is the Telegram chat ID from the DB (e.g. -1003767441152).
|
||||||
* The messageId is the TDLib message ID stored in the DB.
|
* The messageId is the TDLib message ID stored in the DB.
|
||||||
@@ -84,9 +84,16 @@ export async function copyMessageToUser(
|
|||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
{ fromChatId: fromChatId.toString(), messageId: messageId.toString(), toUserId: toUserId.toString() },
|
{ 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(
|
const result = await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
c.invoke({
|
c.invoke({
|
||||||
@@ -94,13 +101,18 @@ export async function copyMessageToUser(
|
|||||||
chat_id: Number(toUserId),
|
chat_id: Number(toUserId),
|
||||||
from_chat_id: Number(fromChatId),
|
from_chat_id: Number(fromChatId),
|
||||||
message_ids: [Number(messageId)],
|
message_ids: [Number(messageId)],
|
||||||
send_copy: false,
|
send_copy: true,
|
||||||
remove_caption: false,
|
remove_caption: false,
|
||||||
}),
|
}),
|
||||||
"copyMessageToUser"
|
"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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user