diff --git a/server.js b/server.js index 754424a..0c670da 100644 --- a/server.js +++ b/server.js @@ -1151,8 +1151,16 @@ async function telegramSend(chatId, text, threadId) { if (!sc.telegramBotToken || !chatId) return; const body = JSON.stringify(Object.assign({ chat_id: chatId, text, parse_mode: 'HTML', disable_web_page_preview: true }, threadId ? { message_thread_id: Number(threadId) } : {})); await new Promise((resolve) => { - const rq = https.request({ hostname: 'api.telegram.org', path: '/bot' + sc.telegramBotToken + '/sendMessage', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, timeout: 10000 }, r => { r.resume(); r.on('end', resolve); }); - rq.on('error', () => resolve()); rq.on('timeout', () => { rq.destroy(); resolve(); }); rq.end(body); + const rq = https.request({ hostname: 'api.telegram.org', path: '/bot' + sc.telegramBotToken + '/sendMessage', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, timeout: 10000 }, r => { + // say what happened: a feed that fails silently is indistinguishable from a quiet day (2026-09-25) + let raw = ''; r.setEncoding('utf8'); r.on('data', d => { raw += d; }); + r.on('end', () => { let j = null; try { j = JSON.parse(raw); } catch (e) {} + if (j && j.ok) console.log('tg-ok chat=' + chatId + (threadId ? ' thread=' + threadId : '') + ' message_id=' + (j.result && j.result.message_id)); + else console.error('tg-fail chat=' + chatId + (threadId ? ' thread=' + threadId : '') + ' http=' + r.statusCode + ' ' + ((j && j.description) || raw.slice(0, 160))); + resolve(); }); + }); + rq.on('error', e => { console.error('tg-fail chat=' + chatId + ' network: ' + e.message); resolve(); }); + rq.on('timeout', () => { console.error('tg-fail chat=' + chatId + ' timeout'); rq.destroy(); resolve(); }); rq.end(body); }); }