Support: Help screen, public /support page, ticket link and chat hand-off on InstantAdPay's shared desk
helpdesk.js proxies to InstantAdPay's partner API (/api/partner/support/*), signed with the same LS_SYNC_SECRET + X-LS-Ts/X-LS-Sig as iapsync.js, IAP_URL as the base. No tickets are stored here. - /help: Control Room screen (list, new ticket with the desk's categories, thread, reply); Help on the rail with an unread badge when Marty has replied (/api/my/support/unread, 60 s cache) - /support and /support/t/<token>: public form + private ticket link, behind the sign-up guard's walls (honeypot, form age, IP/email limits, icon check) on their own counters; these pages, their API and their files pass the curtain for anonymous visitors - chat bubble: "Send this to support" hand-off, greeting points to Help and /support; chatbot flags hand-off on support questions and unsure answers; CANNED + FACTS updated, KNOWLEDGE_DATE 2026-10-16 - Support in the home nav, common.js nav/footer and every public footer; copy that said "message support" now points at Help - cache tags bumped (common.js, cr-shell.js, chat.js, my.js, credits-screen.js) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,7 @@ const leaderboard = require('./leaderboard');
|
||||
const toolkit = require('./toolkit');
|
||||
const registry = require('./registry'); // network registry: who is who across properties (LinkSpin, 2026-09-15)
|
||||
const iapsync = require('./iapsync'); // reverse registry sync: LinkSpin-first members reach InstantAdPay (2026-10-15)
|
||||
const helpdesk = require('./helpdesk'); // support: Help screen, /support, ticket link, chat hand-off, all on InstantAdPay's one desk (2026-10-16)
|
||||
const carry = require('./carry'); // sponsor carry-over: engine activation, claim window, notices
|
||||
const rotator = require('./rotator');
|
||||
const health = require('./health'); // destination health checks + auto-pause (2026-10-10)
|
||||
@@ -253,6 +254,45 @@ function codeGuard(req, b) {
|
||||
if (codeHits.size > 5000) for (const [k, v] of codeHits) { if (!v.t.length || now - v.t[v.t.length - 1] > 24 * 3600 * 1000) codeHits.delete(k); }
|
||||
return null;
|
||||
}
|
||||
// Public support form + signed-out chat hand-off (2026-10-16): the sign-up guard's walls (honeypot, form age, per-IP
|
||||
// limits with the icon check once tripped, a global cap) plus a hard per-email cap, on counters of their own so a
|
||||
// support ticket never eats into anyone's sign-in codes. Returns null to allow, or { status, body }.
|
||||
const SUPPORT_LIMITS = { ipHour: 5, ipDay: 15, emailHour: 3, emailDay: 8, globalPerMin: 20 };
|
||||
const supportHits = new Map(); // 'ip:<ip>' | 'em:<email>' | 'tk:<token or ref>' -> [timestamps, 24h]
|
||||
const supportChal = new Map(); // ip -> { chal, passUntil }
|
||||
const supportGlobal = { minute: 0, n: 0 };
|
||||
const supportRecent = (k, ms) => { const now = Date.now(); const t = (supportHits.get(k) || []).filter(ts => now - ts < 86400000); supportHits.set(k, t); return t.filter(ts => now - ts < ms).length; };
|
||||
const supportMark = k => { const t = supportHits.get(k) || []; t.push(Date.now()); supportHits.set(k, t); if (supportHits.size > 5000) for (const [kk, v] of supportHits) if (!v.length || Date.now() - v[v.length - 1] > 86400000) supportHits.delete(kk); };
|
||||
const supportFlood = (k, n, ms) => { if (supportRecent(k, ms) >= n) return true; supportMark(k); return false; }; // signed-in and private-link replies: a plain cap
|
||||
function supportGuard(req, b, email) {
|
||||
const now = Date.now();
|
||||
const hpRaw = String(b.hp_field_x9 || '').trim();
|
||||
const hp = !!hpRaw && hpRaw.toLowerCase() !== email; // own email = phone autofill, not a bot
|
||||
const fts = Number(b.fts) || 0;
|
||||
if (!fts || now - fts < CODE_LIMITS.minFormMs) { guardLog(req, 'support form-age', b); return { status: 400, body: { error: 'Give the page a few seconds, then send again.' } }; }
|
||||
if (now - fts > 12 * 3600 * 1000) { guardLog(req, 'support form-stale', b); return { status: 400, body: { error: 'This page has been open a long time. Refresh it, then send again.' } }; }
|
||||
const minute = Math.floor(now / 60000);
|
||||
if (supportGlobal.minute !== minute) { supportGlobal.minute = minute; supportGlobal.n = 0; }
|
||||
if (supportGlobal.n >= SUPPORT_LIMITS.globalPerMin) { guardLog(req, 'support global-limit', b); return { status: 429, body: { error: 'Busy right now. Try again in a minute.' } }; }
|
||||
if (supportRecent('em:' + email, 3600000) >= SUPPORT_LIMITS.emailHour || supportRecent('em:' + email, 86400000) >= SUPPORT_LIMITS.emailDay) {
|
||||
guardLog(req, 'support email-limit', b);
|
||||
return { status: 429, body: { error: 'You have sent several tickets already. Reply on the one you have open (the link is in your confirmation email) and Marty will see it there.' } };
|
||||
}
|
||||
const ip = clientIp(req);
|
||||
const limited = hp || supportRecent('ip:' + ip, 3600000) >= SUPPORT_LIMITS.ipHour || supportRecent('ip:' + ip, 86400000) >= SUPPORT_LIMITS.ipDay;
|
||||
const rec = supportChal.get(ip) || { chal: null, passUntil: 0 };
|
||||
if (limited && now >= rec.passUntil) {
|
||||
const pick = String(b.pick || '');
|
||||
if (pick && rec.chal && rec.chal.exp > now && pick === rec.chal.answer) { rec.passUntil = now + CODE_LIMITS.passMs; rec.chal = null; }
|
||||
else { guardLog(req, pick ? 'support wrong-pick' : hp ? 'support honeypot-challenge' : 'support ip-limit', b); const challenge = codeChallenge(rec); supportChal.set(ip, rec); if (supportChal.size > 5000) supportChal.clear(); return { status: 429, body: { error: pick ? 'That was not it. Try once more.' : 'Quick check before we send it.', challenge } }; }
|
||||
supportChal.set(ip, rec);
|
||||
}
|
||||
supportGlobal.n += 1; supportMark('ip:' + ip); supportMark('em:' + email);
|
||||
return null;
|
||||
}
|
||||
// what an anonymous visitor may load while the curtain is up: the support page, its ticket link, its API and the files they use
|
||||
const SUPPORT_OPEN = new Set(['/support', '/api/support', '/api/support/chatbot', '/assets/pub.css', '/assets/common.js', '/assets/support.js', '/logo-icon.png', '/favicon-256.png']);
|
||||
const supportOpen = p => SUPPORT_OPEN.has(p) || /^\/support\/t\/[A-Za-z0-9_.-]{20,80}$/.test(p) || /^\/api\/support\/t\/[A-Za-z0-9_.-]{20,80}(\/reply)?$/.test(p);
|
||||
// burst alert: at most one message per 10 minutes, to the admin Telegram chat if set, else the admin email
|
||||
function codeTrip(req, ip) {
|
||||
codeAlert.trips += 1; codeAlert.ips.add(ip);
|
||||
@@ -923,7 +963,8 @@ const server = http.createServer(async (req, res) => {
|
||||
const p = u.pathname;
|
||||
// zone endpoints run on other people's sites and show only ad creatives, so they pass the curtain
|
||||
const zonePath = p === '/z.js' || p === '/z/nas' || p === '/p.js' || p === '/p.gif' || p.startsWith('/u/pages/') || p.startsWith('/api/zone/') || p.startsWith('/banners/linkspin-') || p.startsWith('/art/house-');
|
||||
if (!zonePath && curtained(req, res, u)) return; // nothing below this line runs for an uninvited visitor
|
||||
// support must reach everyone, invited or not (2026-10-16): someone locked out or not yet let in is exactly who needs it
|
||||
if (!zonePath && !supportOpen(p) && curtained(req, res, u)) return; // nothing below this line runs for an uninvited visitor
|
||||
|
||||
// -- the rotator redirect: one hop, recorded, on any host (LinkSpin)
|
||||
let rm = /^\/r\/([a-z0-9]{4,12})$/i.exec(p);
|
||||
@@ -1213,6 +1254,80 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
|
||||
// -- help desk (2026-10-16, helpdesk.js): the tickets live on InstantAdPay's one shared desk; these routes check the
|
||||
// person (session or the support guard) and proxy. Public side first: the /support form, the private ticket link,
|
||||
// the chat hand-off. All three pass the curtain (supportOpen above).
|
||||
if (p === '/api/support' && req.method === 'POST') {
|
||||
const b = await readBody(req);
|
||||
const s = await auth.fromRequest(req);
|
||||
const acct = s && s.email ? await accounts.byEmail(s.email) : null; // signed in: the ticket is theirs, whatever was typed
|
||||
const email = acct ? acct.email : String(b.email || '').trim().toLowerCase();
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'That email address does not look right.' });
|
||||
const guard = supportGuard(req, b, email);
|
||||
if (guard) return json(res, guard.status, guard.body);
|
||||
const r = await helpdesk.call('create', { source: 'public', email, name: b.name || (acct && acct.username) || '', username: acct && acct.username, subject: b.subject, category: b.category, body: b.body });
|
||||
if (r.status !== 200) return json(res, r.status, r.data);
|
||||
helpdesk.forget(email);
|
||||
return json(res, 200, { ok: true, ref: r.data.ref, token: r.data.token, member: !!acct });
|
||||
}
|
||||
m = /^\/api\/support\/t\/([A-Za-z0-9_.-]{20,80})(\/reply)?$/.exec(p);
|
||||
if (m && (req.method === 'GET' || (m[2] && req.method === 'POST'))) {
|
||||
if (req.method === 'GET') { const r = await helpdesk.call('token', { token: m[1] }); return json(res, r.status, r.data); }
|
||||
const b = await readBody(req);
|
||||
if (supportFlood('tk:' + m[1], 20, 3600000)) return json(res, 429, { error: 'That is a lot of messages in an hour. Give Marty a moment to catch up.' });
|
||||
const r = await helpdesk.call('token-reply', { token: m[1], body: b.body });
|
||||
return json(res, r.status, r.data);
|
||||
}
|
||||
if (p === '/api/support/chatbot' && req.method === 'POST') {
|
||||
const b = await readBody(req);
|
||||
const s = await auth.fromRequest(req);
|
||||
const acct = s && s.email ? await accounts.byEmail(s.email) : null;
|
||||
const email = acct ? acct.email : String(b.email || '').trim().toLowerCase();
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'Add your email so Marty can reply.', needEmail: true });
|
||||
if (acct) { if (supportFlood('em:' + email, 5, 3600000)) return json(res, 429, { error: 'You have sent several tickets in the last hour. Open Help in your Control Room to add to one.' }); }
|
||||
else { const guard = supportGuard(req, b, email); if (guard) return json(res, guard.status, guard.body); }
|
||||
const tr = Array.isArray(b.transcript) ? b.transcript : [];
|
||||
const turns = tr.slice(-8).map(x => ((x && x.who === 'me') ? 'Me: ' : 'Assistant: ') + String((x && x.text) || '').replace(/\s+/g, ' ').trim().slice(0, 600)).filter(x => x.length > 6);
|
||||
const firstQ = tr.find(x => x && x.who === 'me' && String(x.text || '').trim());
|
||||
const note = String(b.note || '').trim().slice(0, 2000);
|
||||
const body = (note ? note + '\n\n' : '') + (turns.length ? 'From the chat assistant:\n' + turns.join('\n') : '(sent from the chat assistant)');
|
||||
const r = await helpdesk.call('create', { source: 'chatbot', email, name: b.name || (acct && acct.username) || '', username: acct && acct.username, category: 'Other',
|
||||
subject: 'Chat: ' + (firstQ ? String(firstQ.text).replace(/\s+/g, ' ').trim().slice(0, 100) : 'question for support'), body });
|
||||
if (r.status !== 200) return json(res, r.status, r.data);
|
||||
helpdesk.forget(email);
|
||||
return json(res, 200, { ok: true, ref: r.data.ref, member: !!acct, link: acct ? '/help#t=' + r.data.ref : '/support/t/' + r.data.token });
|
||||
}
|
||||
// member side: the Help screen lists, opens and answers this member's LinkSpin tickets; the rail badge reads /unread
|
||||
if (p === '/api/my/support/unread' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 200, { unread: 0 });
|
||||
return json(res, 200, { unread: await helpdesk.unread(s.email) });
|
||||
}
|
||||
if (p === '/api/my/support' && (req.method === 'GET' || req.method === 'POST')) {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const email = String(s.email).toLowerCase();
|
||||
if (req.method === 'GET') { const r = await helpdesk.call('list', { email }); return json(res, r.status, r.data); }
|
||||
const b = await readBody(req);
|
||||
if (supportFlood('em:' + email, 5, 3600000)) return json(res, 429, { error: 'You have opened several tickets in the last hour. Add to one of those instead.' });
|
||||
const a = await accounts.byEmail(email);
|
||||
const r = await helpdesk.call('create', { source: 'form', email, name: (a && a.username) || '', username: a && a.username, subject: b.subject, category: b.category, body: b.body });
|
||||
if (r.status !== 200) return json(res, r.status, r.data);
|
||||
return json(res, 200, { ok: true, ref: r.data.ref });
|
||||
}
|
||||
m = /^\/api\/my\/support\/(LS-\d{4,9})(\/reply)?$/.exec(p);
|
||||
if (m && (req.method === 'GET' || (m[2] && req.method === 'POST'))) {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const email = String(s.email).toLowerCase();
|
||||
helpdesk.forget(email); // opening or answering a ticket changes the badge
|
||||
if (req.method === 'GET') { const r = await helpdesk.call('view', { ref: m[1], email }); return json(res, r.status, r.data); }
|
||||
const b = await readBody(req);
|
||||
if (supportFlood('tk:' + m[1], 20, 3600000)) return json(res, 429, { error: 'That is a lot of messages in an hour. Give Marty a moment to catch up.' });
|
||||
const r = await helpdesk.call('reply', { ref: m[1], email, body: b.body });
|
||||
return json(res, r.status, r.data);
|
||||
}
|
||||
|
||||
// -- accounts: email + password is the normal join path (wallet comes
|
||||
// out only at purchase / payout-activation time and gets linked then)
|
||||
if (p === '/api/signup' && req.method === 'POST') {
|
||||
@@ -2208,7 +2323,7 @@ const server = http.createServer(async (req, res) => {
|
||||
// a username is permanent once set: the invite link, the public wall and every
|
||||
// banner already printed carry it (Marty, 2026-09-10)
|
||||
if (before && before.username && String(b.username || '').trim().toLowerCase() !== String(before.username).toLowerCase())
|
||||
return json(res, 400, { error: 'Your username is locked. Your invite link, your public page and any banners you shared all carry @' + before.username + '. Contact support if it truly has to change.' });
|
||||
return json(res, 400, { error: 'Your username is locked. Your invite link, your public page and any banners you shared all carry @' + before.username + '. Contact support (' + SITE_URL + '/support) if it truly has to change.' });
|
||||
const r = await accounts.setUsername(s.email, b.username);
|
||||
// First time a username is set (onboarding): now there's a real name to
|
||||
// show, so notify the sponsor here rather than at signup (where it'd just
|
||||
@@ -3200,6 +3315,8 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/team') return sendFile(res, path.join(PUBLIC_DIR, 'team.html'));
|
||||
if (p === '/wallet') return sendFile(res, path.join(PUBLIC_DIR, 'wallet.html'));
|
||||
if (p === '/credits') return sendFile(res, path.join(PUBLIC_DIR, 'credits.html')); // Control Room: buy packages, link wallet, payouts on (2026-10-07)
|
||||
if (p === '/help') return sendFile(res, path.join(PUBLIC_DIR, 'help.html')); // Control Room: Help, the member's support tickets (2026-10-16)
|
||||
if (p === '/support' || /^\/support\/t\/[A-Za-z0-9_.-]{20,80}$/.test(p)) return sendFile(res, path.join(PUBLIC_DIR, 'support.html')); // public form + private ticket link, open past the curtain
|
||||
if (p === '/join') return serveJoinPage(res, '', '', null, []); // bare join: sponsor from the cookie if any (home-page CTAs)
|
||||
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html'));
|
||||
if (p === '/shorts') return sendFile(res, path.join(PUBLIC_DIR, 'shorts.html'));
|
||||
|
||||
Reference in New Issue
Block a user