fix: handle Telegram API array-like response format
This commit is contained in:
@@ -60,12 +60,24 @@ export async function sendStreamingMessage(ctx, text, options = {}) {
|
|||||||
|
|
||||||
logger.info('📡 Reply response type:', typeof sentMsg);
|
logger.info('📡 Reply response type:', typeof sentMsg);
|
||||||
logger.info('📡 Reply response keys:', sentMsg ? Object.keys(sentMsg) : 'null');
|
logger.info('📡 Reply response keys:', sentMsg ? Object.keys(sentMsg) : 'null');
|
||||||
logger.info('📡 Message ID:', sentMsg?.message_id);
|
|
||||||
logger.info('📡 Chat ID:', sentMsg?.chat?.id);
|
|
||||||
|
|
||||||
// Extract IDs safely
|
// Handle Telegram API response format (can be array-like)
|
||||||
const messageId = sentMsg?.message_id;
|
let messageId, chatId;
|
||||||
const chatId = sentMsg?.chat?.id;
|
if (sentMsg?.message_id !== undefined) {
|
||||||
|
messageId = sentMsg.message_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 Chat ID:', chatId);
|
||||||
|
|
||||||
if (!messageId || !chatId) {
|
if (!messageId || !chatId) {
|
||||||
logger.error('Failed to extract message ID or chat ID from reply response');
|
logger.error('Failed to extract message ID or chat ID from reply response');
|
||||||
|
|||||||
Reference in New Issue
Block a user