fix: retain verified Telegram message receipts for weekly briefs

This commit is contained in:
2026-09-06 14:39:12 +03:00
parent 7a01e4bed7
commit df0626a71f
7 changed files with 63 additions and 9 deletions
+10 -2
View File
@@ -26,7 +26,7 @@ export async function botAdi() {
return null;
}
export async function sendTelegram(chatId, text, { parseMode = 'HTML' } = {}) {
export async function sendTelegram(chatId, text, { parseMode = 'HTML', returnReceipt = false } = {}) {
if (!telegramConfigured() || !chatId) return false;
const r = await fetch(`${API()}/sendMessage`, {
method: 'POST',
@@ -35,7 +35,15 @@ export async function sendTelegram(chatId, text, { parseMode = 'HTML' } = {}) {
signal: AbortSignal.timeout(15000),
});
const d = await r.json().catch(() => ({}));
if (!d.ok) throw new Error(d.description || `Telegram HTTP ${r.status}`);
if (!r.ok || d.ok !== true) throw new Error(d.description || `Telegram HTTP ${r.status}`);
if (returnReceipt) {
const messageId=d.result?.message_id,returnedChat=d.result?.chat?.id;
if (!Number.isSafeInteger(messageId) || messageId <= 0 || !Number.isSafeInteger(returnedChat) || returnedChat === 0)
throw new Error('Telegram mesaj kimliği doğrulanamadı; gönderim sonucu belirsiz.');
if (/^-?\d+$/.test(String(chatId)) && String(returnedChat) !== String(chatId))
throw new Error('Telegram kabulü hedef sohbetle eşleşmiyor; gönderim sonucu belirsiz.');
return { id:`${returnedChat}:${messageId}`, chatId:String(returnedChat), messageId };
}
return true;
}