fix: retain verified Telegram message receipts for weekly briefs
This commit is contained in:
@@ -20,8 +20,8 @@ export function createBriefSender({ store, buildBrief, text, html, telegramConfi
|
||||
if (telegramConfigured() && telegram?.chatId) {
|
||||
for (const part of splitBriefText(text(brief))) channels.push({
|
||||
payload:{channel:'telegram',chatId:telegram.chatId,text:part},
|
||||
name:'telegram', send:() => sendTelegram(telegram.chatId, part, { parseMode:null }),
|
||||
valid:receipt => receipt === true,
|
||||
name:'telegram', send:() => sendTelegram(telegram.chatId, part, { parseMode:null, returnReceipt:true }),
|
||||
valid:receipt => typeof receipt?.id === 'string' && Boolean(receipt.id.trim()),
|
||||
});
|
||||
}
|
||||
if (emailConfigured()) channels.push({
|
||||
@@ -50,7 +50,7 @@ export function createBriefSender({ store, buildBrief, text, html, telegramConfi
|
||||
try {
|
||||
const receipt = await channel.send();
|
||||
if (!channel.valid(receipt)) throw new Error('Sağlayıcı gönderimi doğrulamadı.');
|
||||
if (claim) outbox.accept(claim,receipt === true ? 'telegram-accepted' : receipt.id);
|
||||
if (claim) outbox.accept(claim,receipt.id);
|
||||
counts.kabul++;
|
||||
accepted = true;
|
||||
} catch (error) {
|
||||
|
||||
+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