Holding tank batches: throttled emails + round announcement (Marty 2026-11-15: "spread the emails out", "Post it to the new members area")

Assignments still happen at once. Only the assigned people's "X is now your sponsor" emails go
into a MySQL outbox (tank_batch_outbox, survives deploys): tankBatchEmailsPerDay (100) per
Central day, evenly spaced from tankBatchEmailStartHour 8 to tankBatchEmailEndHour 20 CT,
oldest first, through the site mailer (unsubscribe rules + link). Right before each send:
still with that sponsor, not unsubscribed, flagged, spam or erased, else skipped. Exactly once
across app copies: MySQL lock + conditional UPDATE queued->sending + marks claim per row. The
switch-on reminders for a batch person start when their email goes out.

Telegram: one announcement per round for the CTB group's General topic (tankBatchAnnounce,
tankBatchAnnounceChatId blank = the payments group, tankBatchAnnounceTopicId blank = General),
with the ladder card image (banners/holding-tank-leads-1200x675.jpg): total, sponsors by
level, how to qualify; then one card per sponsor in the payments topic, at least
tankBatchFeedGapMin (2) minutes apart. Sponsor emails stay one digest per round.

Admin: GET/POST /api/admin/tank/batches/mail (queued, sent today, next send, pause/resume),
POST /api/admin/tank/batches/round (the normal round path). Preview shows the email plan.
qa/tank-batch.test.mjs 78 checks (cap, window, skip-if-changed, two copies, pause).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 15:39:18 -06:00
parent ade472cbc8
commit 8e6b5674ae
5 changed files with 191 additions and 24 deletions
+9
View File
@@ -855,9 +855,15 @@ async function boot() {
hooks: { excluded: em => fraud.excluded(em), companyId: () => Number(siteConfig().defaultSponsorId) || 1, claim: key => marks.claim(key), toast: ev => pushFeed(ev),
excludedPerson: async em => { if (spamSet().has(em)) return 'spam scan'; const d = String(em).split('@')[1] || ''; const fix = require('./emailcheck').suggestDomain(d); if (fix && fix !== d) return 'mistyped email domain'; if (erase.isErased(em)) return 'erased'; if (await drip.isUnsubscribed(em).catch(() => false)) return 'unsubscribed from email'; return null; },
notify: async (email, subject, text) => { const html = '<p>' + String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/(https:\/\/[^\s)]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>').split('\n\n').join('</p><p>').replace(/\n/g, '<br>') + '</p>'; await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [email], subject, html, 'notice'); },
// the round's announcement in the new members area (CTB group General: no thread id), with the ladder card image; a caption over
// Telegram's 1,024 characters goes as one text post instead
announce: async html => { const sc = siteConfig(); const chat = String(sc.tankBatchAnnounceChatId || sc.telegramEchoChatId || '').trim(); if (!sc.telegramBotToken || !chat) return; const topic = String(sc.tankBatchAnnounceTopicId || '').trim() || null;
let jpeg = null; try { jpeg = fs.readFileSync(path.join(__dirname, 'public', 'banners', 'holding-tank-leads-1200x675.jpg')); } catch (e) {}
if (jpeg && html.length <= 1024 && await telegramSendPhoto(chat, jpeg, html, topic)) return; await telegramSend(chat, html, topic); },
feed: async (who, what, level) => { const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return; const clean = t => String(t || '').replace(/[<>&]/g, ''); await telegramSend(sc.telegramEchoChatId, '\u{1F91D} <b>InstantAdPay</b> · <b>' + clean(who) + '</b> just received ' + clean(what) + ' from the holding tank (' + clean(level) + ' level)', sc.telegramEchoTopicId); } } }).catch(e => console.error('tankbatch init', e.message)); }
setTimeout(() => tankbatch.tick().catch(e => console.error('tankbatch', e.message)), 4 * 60 * 1000); // past the deploy overlap window
setInterval(() => tankbatch.tick().catch(e => console.error('tankbatch', e.message)), 60 * 60 * 1000);
setInterval(() => tankbatch.mailTick().catch(e => console.error('tankbatch mail', e.message)), 60 * 1000); // throttled batch emails (tankBatchEmailsPerDay, 8 AM to 8 PM CT) + spaced Telegram cards
setInterval(() => draftpartner.sweep().then(r => { if (r.done || r.returned || r.kept || r.moved) console.log('draft sweep', JSON.stringify(r)); }).catch(e => console.error('draft sweep', e.message)), 60 * 60 * 1000); // 5xYourTeam picks: 3-day window
burner.init({ chain, ads, accounts });
setTimeout(() => coach.nudgeTick().catch(e => console.error('coach', e.message)), 90 * 1000);
@@ -3892,6 +3898,9 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, await draftpartner.adminView());
}
if (p === '/api/admin/tank/batches/preview' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await tankbatch.preview()); } // read-only: no writes, no mail
if (p === '/api/admin/tank/batches/mail' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await tankbatch.mailView()); } // queued, sent today, next send time
if (p === '/api/admin/tank/batches/mail' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); return json(res, 200, await tankbatch.setPaused(!!(b && b.paused))); } // pause / resume
if (p === '/api/admin/tank/batches/round' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await tankbatch.round()); } // run a round now (the normal path; nothing while tankBatches is off)
if (p === '/api/admin/tank/batches' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await tankbatch.adminView()); }
if (p === '/api/admin/tank' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });