fix: use bracket notation for Telegram API response
This commit is contained in:
@@ -58,23 +58,12 @@ export async function sendStreamingMessage(ctx, text, options = {}) {
|
|||||||
// Send initial placeholder message using ctx.api.sendMessage directly
|
// Send initial placeholder message using ctx.api.sendMessage directly
|
||||||
const sentMsg = await ctx.api.sendMessage(ctx.chat.id, '⌨️ ⌨️', { parse_mode: 'Markdown' });
|
const sentMsg = await ctx.api.sendMessage(ctx.chat.id, '⌨️ ⌨️', { parse_mode: 'Markdown' });
|
||||||
|
|
||||||
logger.info('📡 Reply response type:', typeof sentMsg);
|
logger.info('📡 Full response:', JSON.stringify(sentMsg, null, 2).substring(0, 500));
|
||||||
logger.info('📡 Reply response keys:', sentMsg ? Object.keys(sentMsg) : 'null');
|
|
||||||
|
|
||||||
// Handle Telegram API response format (can be array-like)
|
// The Telegram API returns a response with numeric keys mapping to property names
|
||||||
let messageId, chatId;
|
// We need to access sentMsg['message_id'] directly
|
||||||
if (sentMsg?.message_id !== undefined) {
|
const messageId = sentMsg?.['message_id'];
|
||||||
messageId = sentMsg.message_id;
|
const chatId = sentMsg?.['chat']?.['id'];
|
||||||
chatId = sentMsg.chat?.id;
|
|
||||||
} else if (Array.isArray(sentMsg) || Object.keys(sentMsg).every(k => /^\d+$/.test(k))) {
|
|
||||||
// Array-like response from Telegram API
|
|
||||||
messageId = sentMsg[0]?.message_id || sentMsg['message_id'];
|
|
||||||
chatId = sentMsg[0]?.chat?.id || sentMsg['chat']?.id;
|
|
||||||
} else {
|
|
||||||
// Try direct property access
|
|
||||||
messageId = sentMsg?.['message_id'] || sentMsg?.[0]?.['message_id'];
|
|
||||||
chatId = sentMsg?.['chat']?.['id'] || sentMsg?.[0]?.['chat']?.['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('📡 Extracted Message ID:', messageId);
|
logger.info('📡 Extracted Message ID:', messageId);
|
||||||
logger.info('📡 Extracted Chat ID:', chatId);
|
logger.info('📡 Extracted Chat ID:', chatId);
|
||||||
|
|||||||
Reference in New Issue
Block a user