From 4bcc867679bf75b6a7df984ee2ec21149b032fb6 Mon Sep 17 00:00:00 2001 From: martbost Date: Mon, 2 Nov 2026 08:23:40 -0600 Subject: [PATCH] Daily growth snapshot also posts to the InstantAdPay support topic: the 'support' target has been in snapshotTargets since 2026-09-24 but post() only knew feed and echo (Marty, 2026-11-02); POST /api/admin/snapshot/send takes {target} for a one-off post to one destination Co-Authored-By: Claude Fable 5.1 --- server.js | 3 ++- snapshot.js | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index a1fb018..0165a89 100644 --- a/server.js +++ b/server.js @@ -5662,7 +5662,8 @@ const server = http.createServer(async (req, res) => { } if (p === '/api/admin/snapshot/send' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); - const r = await snapshot.post(); return json(res, r.error ? 400 : 200, r); + let target = ''; try { target = String(((await readBody(req)) || {}).target || '').trim(); } catch (e) {} + const r = target ? await snapshot.postTo(target) : await snapshot.post(); return json(res, r.error ? 400 : 200, r); } // -- 1,000-member drop: view, mode (off|dry|armed via site config), snapshot now, pay now, resend the missed-it notices, reset (only before any payment) if (p === '/api/admin/milestone') { diff --git a/snapshot.js b/snapshot.js index 44c52c7..e517685 100644 --- a/snapshot.js +++ b/snapshot.js @@ -104,11 +104,26 @@ async function post() { const s = await gather(); const text = compose(s, sc.telegramCtaUrl); const targets = String(sc.snapshotTargets || 'feed,echo').split(',').map(x => x.trim()); let sent = 0; - if (targets.includes('feed') && sc.telegramChatId) { if (await X.send(sc.telegramChatId, text, sc.telegramTopicId)) sent++; } - if (targets.includes('echo') && sc.telegramEchoChatId) { if (await X.send(sc.telegramEchoChatId, text, sc.telegramEchoTopicId)) sent++; } + // Same three destinations as the milestone posts. 'support' was in the settings since 2026-09-24 but the daily + // card only knew feed and echo, so the InstantAdPay support topic never saw it (Marty, 2026-11-02). + for (const [name, chat, thread] of [['feed', sc.telegramChatId, sc.telegramTopicId], + ['support', sc.telegramSupportChatId, sc.telegramSupportTopicId], + ['echo', sc.telegramEchoChatId, sc.telegramEchoTopicId]]) { + if (!targets.includes(name)) continue; + if (!chat) { console.warn('snapshot: target "' + name + '" is listed but has no chat id, nothing sent'); continue; } + if (await X.send(chat, text, thread)) sent++; + } const st = state(); st.lastPost = Date.now(); st.lastDay = new Date().toISOString().slice(0, 10); setState(st); return { ok: true, sent, text }; } +// one destination by name, for a one-off post (admin: POST /api/admin/snapshot/send with {target}) +async function postTo(name) { + const sc = X.siteConfig(); if (!sc.telegramBotToken) return { error: 'No Telegram bot token set.' }; + const map = { feed: [sc.telegramChatId, sc.telegramTopicId], support: [sc.telegramSupportChatId, sc.telegramSupportTopicId], echo: [sc.telegramEchoChatId, sc.telegramEchoTopicId] }; + const t = map[name]; if (!t || !t[0]) return { error: 'No chat id for target ' + name + '.' }; + const text = compose(await gather(), sc.telegramCtaUrl); + const ok = await X.send(t[0], text, t[1]); return { ok: !!ok, sent: ok ? 1 : 0, target: name, text }; +} // every 10 minutes: post once a day at or after snapshotHourUtc (a restart never double-posts) async function tick() { @@ -203,4 +218,4 @@ async function milestoneTick() { } async function previewMilestone(mark) { const sc = X.siteConfig(); return composeMilestone(Number(mark) || 500, await gather(), sc.telegramCtaUrl); } -module.exports = { init, gather, compose, post, tick, preview, milestoneTick, previewMilestone, composeMilestone, memberCount, MILESTONES, STEP }; +module.exports = { init, gather, compose, post, postTo, tick, preview, milestoneTick, previewMilestone, composeMilestone, memberCount, MILESTONES, STEP };