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 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-02 08:23:40 -06:00
parent 27d7215f0f
commit 4bcc867679
2 changed files with 20 additions and 4 deletions
+18 -3
View File
@@ -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 };