Weekly member email as sectioned HTML (plain-text twin kept); PassiveDrip one-tap hand-off (inert until PD_SSO_SECRET)
- coach.js: weeklyDigest() builds one card per topic (credits, streak, contest, tank, team) with the key number up front and one button; mailer.send takes optional html - server.js: /api/my/passivedrip mints a signed hand-off (memberId, email, username, verified wallet, sponsor email); Games card for PassiveDrip (admin preview until gamesLive includes passivedrip) with the member's own coins line via the bridge 'member' lookup; sign-in return path - my.js: card button label, return redirect; v=20261001b Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -205,6 +205,103 @@ async function linkStats(email) {
|
||||
return { angles: Object.values(rows), sources, totalViews: views.length, totalJoins: joined.length };
|
||||
}
|
||||
|
||||
// ---- the weekly member email (Marty, 2026-09-14; reformatted 2026-10-01 because one long text block was hard to read):
|
||||
// one section per topic, each with a heading, the number that matters up front and ONE button. Sent as HTML with a
|
||||
// plain-text twin built from the same sections.
|
||||
const SITE = 'https://instantadpay.com';
|
||||
const escH = v => String(v == null ? '' : v).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
const n0 = v => Number(v || 0).toLocaleString('en-US');
|
||||
async function weeklyDigest(acct, view, lbWeek, tankN, now) {
|
||||
const name = acct.username ? '@' + acct.username : 'there';
|
||||
const S = []; // { title, big, bigLabel, lines[], rows[[label, value]], quotes[{to, text}], button{label, url} }
|
||||
// credits: they sit on positions and each campaign pays from one, so the pooled total alone misleads
|
||||
// members with linked positions (Jim Watts, 2026-09-27: "561 unspent" but a top-up allowed 19)
|
||||
try {
|
||||
const ids = [acct.memberId, ...(await accounts.positions(acct.email)).map(p => p.memberId)].filter(Boolean);
|
||||
const bal = await X.ads.balances(ids, acct.email);
|
||||
if (bal.available > 0) {
|
||||
const onPos = (bal.per || []).filter(p => p.avail > 0).sort((a, b) => b.avail - a.avail);
|
||||
const loose = (bal.credited || 0) + (bal.earned || 0);
|
||||
const sec = { title: 'Ad credits ready to use', big: n0(bal.available), bigLabel: 'credits not running yet', lines: [], button: { label: 'Start a campaign', url: SITE + '/my#campaigns' } };
|
||||
if (onPos.length > 1) {
|
||||
sec.rows = onPos.map(p => ['Position #' + p.memberId, n0(p.avail)]);
|
||||
if (loose) sec.rows.push(['Any position can use', n0(loose)]);
|
||||
sec.lines.push('Each campaign spends from one position. Start from #' + onPos[0].memberId + ' to use the most credits at once.');
|
||||
}
|
||||
sec.lines.push('Point the campaign at your invite link so the views bring people to you.');
|
||||
S.push(sec);
|
||||
} else if (bal.inCampaigns > 0) S.push({ title: 'Ad credits', big: n0(bal.inCampaigns), bigLabel: 'credits working in live campaigns', lines: ['Everything you have is running. Nice.'] });
|
||||
} catch (e) {}
|
||||
// streak
|
||||
try {
|
||||
const st = await X.ads.viewStatus(acct.email);
|
||||
if (st.streakDay > 1) S.push({ title: 'Daily claim streak', big: 'Day ' + st.streakDay, bigLabel: 'of your streak. Today’s claim pays ' + n0(st.claimCredits) + ' credits.', lines: ['Miss a day and the streak starts over.'], button: { label: 'Claim today', url: SITE + '/my#earn' } });
|
||||
else S.push({ title: 'Free daily credits', lines: ['View five ads and claim once a day. The claim grows 5, 7, 10 credits, then 25 on every seventh day in a row.'], button: { label: 'Start today', url: SITE + '/my#earn' } });
|
||||
} catch (e) {}
|
||||
// contest
|
||||
let first = false;
|
||||
if (lbWeek && lbWeek.top) {
|
||||
const me = lbWeek.top.find(r => r.name === '@' + acct.username) || null;
|
||||
let mine = me; if (!mine) { try { mine = (await X.lb().view('week', acct.email)).me; } catch (e) {} }
|
||||
first = !!(lbWeek.top.length && lbWeek.top[0].name === '@' + acct.username);
|
||||
const sec = { title: 'This week’s referral contest', lines: [], button: { label: 'See the leaderboard', url: SITE + '/leaderboard' } };
|
||||
if (lbWeek.prize) sec.intro = 'Prizes: ' + lbWeek.prize + '.';
|
||||
if (lbWeek.top.length) sec.rows = lbWeek.top.slice(0, 3).map(r => [r.rank + '. ' + r.name, r.sales + ' sold']);
|
||||
else sec.lines.push('No sales yet. The first one takes the top spot.');
|
||||
if (mine) { sec.big = '#' + mine.rank; sec.bigLabel = 'is your place, with ' + mine.sales + ' sold'; }
|
||||
else sec.lines.push('You are not on the board yet. One $20 package bought by someone you sponsor puts you there.');
|
||||
S.push(sec);
|
||||
}
|
||||
// tank
|
||||
if (tankN > 0 && acct.memberId) S.push({ title: 'Holding tank', big: n0(tankN), bigLabel: 'member' + (tankN === 1 ? '' : 's') + ' waiting for a sponsor', lines: ['Adopt one from My line and they join your team.'], button: { label: 'Adopt a member', url: SITE + '/my#line' } });
|
||||
// line (sponsors only)
|
||||
if (view.directs.length) {
|
||||
const week = view.directs.filter(d => now - d.joined < 7 * DAY).length;
|
||||
const sec = { title: 'Your team', rows: [['Direct members', n0(view.directs.length)], ['Joined this week', n0(week)], ['Gone quiet', n0(view.stalled)]], lines: [], button: { label: 'Open My line', url: SITE + '/my#line' } };
|
||||
const q = view.directs.filter(d => d.stalled).slice(0, 3).map(d => ({ to: d.name, text: d.say.replace('{{name}}', d.name.replace(/^@/, '')) }));
|
||||
if (q.length) { sec.lines.push('A quick message gets most people moving again. Copy these:'); sec.quotes = q; }
|
||||
S.push(sec);
|
||||
}
|
||||
const subject = first ? 'You are #1 this week on InstantAdPay' : 'Your week on InstantAdPay: credits, streak, contest';
|
||||
const tip = { text: 'Short on time? The twenty-minute day: claim your set, message one person on your team, check the tank, start one new conversation.', link: SITE + '/blog/the-twenty-minute-day' };
|
||||
const legal = 'No income is guaranteed. Credits are advertising, not money.';
|
||||
|
||||
// plain text twin
|
||||
const T = ['Hi ' + name + ', here is your week on InstantAdPay.', ''];
|
||||
for (const s of S) {
|
||||
T.push(s.title.toUpperCase());
|
||||
if (s.big) T.push(s.big + ' ' + s.bigLabel);
|
||||
if (s.intro) T.push(s.intro);
|
||||
for (const r of s.rows || []) T.push(' ' + r[0] + ': ' + r[1]);
|
||||
for (const l of s.lines) T.push(l);
|
||||
for (const q of s.quotes || []) T.push(' To ' + q.to + ': "' + q.text + '"');
|
||||
if (s.button) T.push(s.button.label + ': ' + s.button.url);
|
||||
T.push('');
|
||||
}
|
||||
T.push(tip.text + ' ' + tip.link, '', 'InstantAdPay · ' + SITE + '/my', legal);
|
||||
|
||||
// html
|
||||
const btn = b => '<a href="' + escH(b.url) + '" style="display:inline-block;background:#1e3a8a;color:#ffffff;text-decoration:none;font-weight:600;font-size:15px;padding:11px 20px;border-radius:8px">' + escH(b.label) + '</a>';
|
||||
const card = s => '<tr><td style="padding:0 0 14px"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#ffffff;border:1px solid #e3e6ee;border-radius:12px"><tr><td style="padding:18px 20px">'
|
||||
+ '<div style="font-size:12px;letter-spacing:.06em;text-transform:uppercase;color:#6b7280;font-weight:700;margin:0 0 6px">' + escH(s.title) + '</div>'
|
||||
+ (s.big ? '<div style="margin:0 0 10px"><span style="font-size:30px;font-weight:800;color:#111827">' + escH(s.big) + '</span> <span style="font-size:15px;color:#4b5563">' + escH(s.bigLabel) + '</span></div>' : '')
|
||||
+ (s.intro ? '<p style="margin:0 0 8px;font-size:15px;line-height:1.5;color:#374151">' + escH(s.intro) + '</p>' : '')
|
||||
+ (s.rows ? '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="margin:0 0 10px;font-size:15px">' + s.rows.map(r => '<tr><td style="padding:5px 0;border-bottom:1px solid #f0f1f5;color:#374151">' + escH(r[0]) + '</td><td align="right" style="padding:5px 0;border-bottom:1px solid #f0f1f5;color:#111827;font-weight:700">' + escH(r[1]) + '</td></tr>').join('') + '</table>' : '')
|
||||
+ s.lines.map(l => '<p style="margin:0 0 10px;font-size:15px;line-height:1.5;color:#374151">' + escH(l) + '</p>').join('')
|
||||
+ (s.quotes || []).map(q => '<div style="margin:0 0 10px;padding:10px 12px;background:#f5f6fa;border-radius:8px;font-size:14px;line-height:1.5;color:#374151"><b style="color:#111827">To ' + escH(q.to) + '</b><br>' + escH(q.text) + '</div>').join('')
|
||||
+ (s.button ? '<div style="margin:6px 0 0">' + btn(s.button) + '</div>' : '')
|
||||
+ '</td></tr></table></td></tr>';
|
||||
const html = '<!doctype html><html><body style="margin:0;padding:0;background:#f3f4f8">'
|
||||
+ '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f8"><tr><td align="center" style="padding:20px 12px">'
|
||||
+ '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif">'
|
||||
+ '<tr><td style="padding:4px 4px 16px"><div style="font-size:20px;font-weight:800;color:#111827">Your week on InstantAdPay</div><div style="font-size:15px;color:#4b5563;margin-top:4px">Hi ' + escH(name) + ', here is where things stand.</div></td></tr>'
|
||||
+ S.map(card).join('')
|
||||
+ '<tr><td style="padding:2px 4px 14px;font-size:14px;line-height:1.5;color:#4b5563">' + escH(tip.text) + ' <a href="' + escH(tip.link) + '" style="color:#1e3a8a">Read how</a></td></tr>'
|
||||
+ '<tr><td style="padding:0 4px 8px;font-size:12px;color:#9ca3af">InstantAdPay · <a href="' + SITE + '/my" style="color:#9ca3af">' + 'instantadpay.com/my</a><br>' + escH(legal) + '</td></tr>'
|
||||
+ '</table></td></tr></table></body></html>';
|
||||
return { subject, text: T.join('\n'), html, sections: S };
|
||||
}
|
||||
|
||||
// ---- automatic nudges to stalled members + weekly digest to sponsors ----
|
||||
let ticking = false;
|
||||
const NUDGE_GAP = 5 * DAY;
|
||||
@@ -242,48 +339,8 @@ async function nudgeTick() {
|
||||
// audience: sponsors with directs (as before) unless the admin switched the weekly on for every member
|
||||
const everyone = X.siteConfig && String(X.siteConfig().memberWeeklyEmail || '0') === '1';
|
||||
if (!everyone && !view.directs.length) { await impl().setDigest(acct.email, now); continue; }
|
||||
const name = acct.username ? '@' + acct.username : 'there';
|
||||
const parts = ['Hi ' + name + ', your week on InstantAdPay:'];
|
||||
// credits
|
||||
try {
|
||||
const ids = [acct.memberId, ...(await accounts.positions(acct.email)).map(p => p.memberId)].filter(Boolean);
|
||||
const bal = await X.ads.balances(ids, acct.email);
|
||||
if (bal.available > 0) {
|
||||
// credits sit on positions and each campaign pays from one, so a pooled total alone misleads
|
||||
// members with linked positions (Jim Watts, 2026-09-27: "561 unspent" but a top-up allowed 19)
|
||||
const onPos = (bal.per || []).filter(p => p.avail > 0).sort((a, b) => b.avail - a.avail);
|
||||
const loose = (bal.credited || 0) + (bal.earned || 0);
|
||||
let where = '';
|
||||
if (onPos.length > 1) where = ' They are spread across your positions: ' + onPos.map(p => '#' + p.memberId + ' has ' + p.avail.toLocaleString()).join(', ') + (loose ? ', plus ' + loose.toLocaleString() + ' that any position can use' : '') + '. Each campaign pays from one position, so start a new campaign from #' + onPos[0].memberId + ' to use the most in one go.';
|
||||
parts.push('- You have ' + bal.available.toLocaleString() + ' ad credits sitting unspent. That is ' + bal.available.toLocaleString() + ' cents of delivery doing nothing.' + where + ' Campaigns > New campaign, point it at your invite link: https://instantadpay.com/my#campaigns');
|
||||
}
|
||||
else if (bal.inCampaigns > 0) parts.push('- All ' + bal.inCampaigns.toLocaleString() + ' of your credits are working in live campaigns. Good.');
|
||||
} catch (e) {}
|
||||
// streak
|
||||
try {
|
||||
const st = await X.ads.viewStatus(acct.email);
|
||||
if (st.streakDay > 1) parts.push('- Your claim streak is on day ' + st.streakDay + '. Today\'s claim pays ' + (st.claimCredits || 0) + ' credits; miss a day and it restarts at 5.');
|
||||
else parts.push('- Five ads and a claim a day is the free way in: 5, 7, 10, then 25 credits every seventh day in a row: https://instantadpay.com/my#earn');
|
||||
} catch (e) {}
|
||||
// contest
|
||||
if (lbWeek && lbWeek.top) {
|
||||
const me = lbWeek.top.find(r => r.name === '@' + acct.username) || null;
|
||||
let mine = me; if (!mine) { try { mine = (await X.lb().view('week', acct.email)).me; } catch (e) {} }
|
||||
parts.push('- Referral contest this week (' + (lbWeek.prize || 'credits to the top 3') + '): ' + (lbWeek.top.length ? lbWeek.top.slice(0, 3).map(r => r.rank + '. ' + r.name + ' (' + r.sales + ' sold)').join(', ') : 'no sales yet, first sale takes the top spot') + '.'
|
||||
+ (mine ? ' You are #' + mine.rank + ' with ' + mine.sales + ' sold.' : ' You are not on the board yet; one $20 package bought by someone you sponsor puts you there.') + ' https://instantadpay.com/leaderboard');
|
||||
}
|
||||
// tank
|
||||
if (tankN > 0 && acct.memberId) parts.push('- ' + tankN + ' member' + (tankN === 1 ? ' is' : 's are') + ' waiting for a sponsor in the holding tank. Adopt one from My line: https://instantadpay.com/my#line');
|
||||
// line (sponsors only)
|
||||
if (view.directs.length) {
|
||||
const week = view.directs.filter(d => now - d.joined < 7 * DAY).length;
|
||||
parts.push('- Your line: ' + view.directs.length + ' direct' + (view.directs.length === 1 ? '' : 's') + ', ' + week + ' joined this week, ' + view.stalled + ' gone quiet.');
|
||||
const actions = view.directs.filter(d => d.stalled).slice(0, 3).map(d => ' Message ' + d.name + ': "' + d.say.replace('{{name}}', d.name.replace(/^@/, '')) + '"');
|
||||
if (actions.length) parts.push(actions.join('\n'));
|
||||
}
|
||||
parts.push('\nTwenty minutes, in order: the set, one message to your line, the tank, one conversation outward. https://instantadpay.com/blog/the-twenty-minute-day\n\nInstantAdPay · https://instantadpay.com/my\nNo income is guaranteed. Credits are advertising, not money.');
|
||||
const subject = lbWeek && lbWeek.top && lbWeek.top.length && lbWeek.top[0].name === '@' + acct.username ? 'You are #1 this week on InstantAdPay' : 'Your week on InstantAdPay: credits, streak, contest';
|
||||
try { await mailer.send(acct.email, subject, parts.join('\n')); digests += 1; } catch (e) { console.error('digest', acct.email, e.message); }
|
||||
const { subject, text, html } = await weeklyDigest(acct, view, lbWeek, tankN, now);
|
||||
try { await mailer.send(acct.email, subject, text, html); digests += 1; } catch (e) { console.error('digest', acct.email, e.message); }
|
||||
await impl().setDigest(acct.email, now);
|
||||
if (digests >= 30) break;
|
||||
}
|
||||
@@ -297,4 +354,4 @@ function init(opts) { X = arguments[0] || {};
|
||||
J.load();
|
||||
}
|
||||
async function viewsSince(since) { return impl().viewsSince(since); }
|
||||
module.exports = { init, RUNGS, rungFor, describe, coachView, prospects, saveProspect, removeProspect, STATUSES, recordView, linkStats, nudgeTick, recordClick, clickSources, refHost, viewsSince };
|
||||
module.exports = { init, weeklyDigest, RUNGS, rungFor, describe, coachView, prospects, saveProspect, removeProspect, STATUSES, recordView, linkStats, nudgeTick, recordClick, clickSources, refHost, viewsSince };
|
||||
|
||||
Reference in New Issue
Block a user