Files
martbost df1b900f45 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>
2026-10-16 18:05:02 -05:00

84 lines
7.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// LinkSpin Help (2026-10-16): the member's support tickets. List, new ticket (same categories as the desk), thread,
// reply; a dot marks a ticket Marty answered that the member has not opened, and the rail badge counts them.
// Server: /api/my/support* in server.js, which proxy to the one shared desk on InstantAdPay (helpdesk.js).
// #t=LS-1042 opens that ticket (the link in reply emails); #new opens the form. Times in US Central.
(function () {
const $ = id => document.getElementById(id); const esc = CR.esc;
const CATS = ['Account & sign-in', 'Wallet & payouts', 'Buying packages', 'Ads & campaigns', 'Earning credits & games', 'Team & referrals', 'Other'];
const STATUS = { open: ['Open', 't'], waiting_on_member: ['Waiting on you', 'warn'], closed: ['Closed', 'dim'] };
const AUTHOR = { member: 'You', admin: 'Marty, LinkSpin support', system: 'LinkSpin' };
const when = ts => ts ? new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : '';
const linkify = s => esc(s).replace(/(https?:\/\/[^\s<]+[^\s<.,;:!?)\]])/g, '<a href="$1" target="_blank" rel="noopener nofollow">$1</a>');
const st = s => { const x = STATUS[s] || [s, 'dim']; return '<span class="tag ' + x[1] + '">' + esc(x[0]) + '</span>'; };
const host = () => $('helpBody');
CR.mount({ active: 'help', title: 'Help', sub: 'support tickets' });
async function list(openNew) {
host().innerHTML = '<div class="panel"><span class="muted">loading your tickets</span></div>';
let r; try { r = await CR.get('/api/my/support'); } catch (e) { host().innerHTML = '<div class="panel"><span>Could not load your tickets. ' + esc(e.message) + '</span></div>'; return; }
const ts = r.tickets || [];
CR.helpBadge(); // the list just refreshed the server's badge count (the rail's first paint may be up to a minute old)
CR.sub(ts.length + ' ticket' + (ts.length === 1 ? '' : 's') + (r.unread ? ' · ' + r.unread + ' new repl' + (r.unread === 1 ? 'y' : 'ies') : ''));
host().innerHTML = '<div class="panel"><h2>Help and support</h2><div class="ink2">Stuck on something? Send Marty a ticket. He reads every one and replies here, and you get an email when he does. Quick answers to common questions are in the chat bubble on More and in Training.</div>'
+ '<div class="acts"><button class="btn pri" type="button" id="hNew">New ticket</button><a class="btn" href="/support">Public support page</a></div></div>'
+ '<div class="panel" id="hForm" hidden></div>'
+ '<div class="tbl hl"><div class="hd"><span>Your tickets</span><span class="up">Updated</span><span>Status</span></div>'
+ (ts.length ? ts.map(t => '<div class="rw" data-ref="' + esc(t.ref) + '"><span style="min-width:0"><div class="sb">' + (t.unread ? '<span class="hdot" title="New reply"></span>' : '') + esc(t.subject) + '</div><div class="mt">' + esc(t.ref) + ' · ' + esc(t.category) + '</div></span>'
+ '<span class="mt up">' + esc(when(t.updated)) + '</span><span>' + st(t.status) + '</span></div>').join('')
: '<div class="rw" style="cursor:default"><span class="muted">No tickets yet. When you send one, it shows up here with Marty\'s replies.</span></div>')
+ '<div class="ft">one shared desk for the Crypto Team Build Network · Marty answers every ticket himself</div></div>';
host().querySelectorAll('.rw[data-ref]').forEach(el => el.addEventListener('click', () => { history.replaceState(null, '', '#t=' + el.dataset.ref); open(el.dataset.ref); }));
$('hNew').addEventListener('click', form);
if (openNew) form();
}
function form() {
const box = $('hForm'); box.hidden = false;
box.innerHTML = '<h2>New ticket</h2><div class="hf">'
+ '<label>What is it about?<select class="field" id="hnCat">' + CATS.map(c => '<option>' + esc(c) + '</option>').join('') + '</select></label>'
+ '<label>Subject<input class="field" id="hnSubject" maxlength="140" placeholder="A few words, like: my spin link stopped rotating"></label>'
+ '<label>Message<textarea class="field" id="hnBody" rows="6" maxlength="5000" placeholder="What happened, what you expected, and anything you already tried. Never send your recovery phrase or private key."></textarea></label>'
+ '<div class="acts"><button class="btn pri" type="button" id="hnSend">Send to support</button><button class="btn" type="button" id="hnCancel">Cancel</button><span class="hmsg" id="hnMsg"></span></div></div>';
$('hnCancel').addEventListener('click', () => { box.hidden = true; box.innerHTML = ''; });
const send = $('hnSend');
send.addEventListener('click', async () => {
if (send.disabled) return; send.disabled = true;
try {
const r = await CR.api('/api/my/support', { category: $('hnCat').value, subject: $('hnSubject').value, body: $('hnBody').value });
CR.toast('Sent: ticket ' + r.ref);
history.replaceState(null, '', '#t=' + r.ref); open(r.ref);
} catch (e) { const m = $('hnMsg'); m.className = 'hmsg bad'; m.textContent = e.message; send.disabled = false; }
});
$('hnSubject').focus();
}
async function open(ref) {
host().innerHTML = '<div class="panel"><span class="muted">loading</span></div>';
let v; try { v = await CR.get('/api/my/support/' + encodeURIComponent(ref)); }
catch (e) { host().innerHTML = '<div class="panel"><span>' + esc(e.message) + '</span><div class="acts"><a class="btn" href="#" id="hBack">Back to your tickets</a></div></div>'; wireBack(); return; }
draw(v); CR.helpBadge();
}
const wireBack = () => { const a = $('hBack'); if (a) a.addEventListener('click', e => { e.preventDefault(); history.replaceState(null, '', location.pathname); list(); }); };
function draw(v) {
const t = v.ticket;
CR.sub(t.ref + ' · ' + (STATUS[t.status] || [t.status])[0].toLowerCase());
host().innerHTML = '<div><a href="#" id="hBack">‹ All your tickets</a></div>'
+ '<div class="panel"><h2>' + esc(t.subject) + '</h2><div class="acts">' + st(t.status) + '<span class="mono muted" style="font-size:11px">' + esc(t.ref) + ' · ' + esc(t.category) + ' · opened ' + esc(when(t.created)) + '</span></div>'
+ v.messages.map(m => '<div class="sup-msg ' + esc(m.author) + '"><div class="sm-head"><b>' + esc(AUTHOR[m.author] || m.author) + '</b><span>' + esc(when(m.created)) + '</span></div><div class="sm-body">' + linkify(m.body) + '</div></div>').join('')
+ (t.status === 'closed' ? '<span class="muted">This ticket is closed. Write below and it opens again.</span>' : '') + '</div>'
+ '<div class="panel"><h2>Your reply</h2><div class="hf"><textarea class="field" id="hrBody" rows="4" maxlength="5000" placeholder="Add more detail or answer Marty here"></textarea>'
+ '<div class="acts"><button class="btn pri" type="button" id="hrSend">Send reply</button><span class="hmsg" id="hrMsg"></span></div></div></div>';
wireBack();
const btn = $('hrSend');
btn.addEventListener('click', async () => {
if (btn.disabled) return; btn.disabled = true;
try { const nv = await CR.api('/api/my/support/' + encodeURIComponent(t.ref) + '/reply', { body: $('hrBody').value }); draw(nv); CR.toast('Reply sent'); }
catch (e) { const m = $('hrMsg'); m.className = 'hmsg bad'; m.textContent = e.message; btn.disabled = false; }
});
}
function route() {
const ref = (/(?:^#|&)t=(LS-\d{4,9})/.exec(location.hash) || [])[1];
if (ref) return open(ref);
list(/^#new\b/.test(location.hash));
}
CR.requireSession(() => { route(); window.addEventListener('hashchange', route); });
})();