fix: retain verified Telegram message receipts for weekly briefs
This commit is contained in:
+10
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user