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

89 lines
8.2 KiB
JavaScript

// LinkSpin support (2026-10-16): the public /support form and the private ticket link page (/support/t/<token>).
// Both talk to this site's /api/support routes, which proxy to the one shared desk on InstantAdPay (helpdesk.js).
// They pass the curtain, so nothing here may depend on a route that does not (a failed /api/me just means signed out).
// Times show in US Central. Members follow up in the Control Room's Help screen (help-screen.js).
(function () {
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const CATS = ['Account & sign-in', 'Wallet & payouts', 'Buying packages', 'Ads & campaigns', 'Earning credits & games', 'Team & referrals', 'Other'];
const STATUS = { open: 'Open', waiting_on_member: 'Waiting on you', closed: 'Closed' };
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 $ = id => document.getElementById(id);
async function call(path, body) {
const o = { method: body === undefined ? 'GET' : 'POST', headers: { Accept: 'application/json' } };
if (body !== undefined) { o.headers['Content-Type'] = 'application/json'; o.body = JSON.stringify(body); }
let r; try { r = await (await fetch(path, o)).json(); } catch (e) { throw new Error('Could not reach support. Check your connection and try again.'); }
if (r.error && !r.challenge) throw new Error(r.error);
return r;
}
const host = $('supMain'); if (!host) return;
const panel = (title, inner) => '<div class="tile">' + (title ? '<div class="ph"><h2>' + esc(title) + '</h2></div>' : '') + '<div class="pb">' + inner + '</div></div>';
function threadHtml(v) {
const t = v.ticket;
return '<div class="tile"><div class="ph"><h2>' + esc(t.subject) + '</h2><span class="sup-st ' + esc(t.status) + '">' + esc(STATUS[t.status] || t.status) + '</span></div><div class="pb">'
+ '<span class="mono muted" style="font-size:11px">' + esc(t.ref) + ' · ' + esc(t.category) + ' · opened ' + esc(when(t.created)) + '</span>'
+ 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" style="font-size:13px">This ticket is closed. Write below and it opens again.</span>' : '') + '</div></div>';
}
async function page() {
const m = /^\/support\/t\/([A-Za-z0-9_.-]{20,80})$/.exec(location.pathname);
if (m) return tokenPage(m[1]);
let me = null; try { me = await (await fetch('/api/me', { headers: { Accept: 'application/json' } })).json(); } catch (e) {}
const signedIn = !!(me && me.signedIn && me.email);
host.innerHTML = (signedIn ? panel('', '<span class="ink2" style="font-size:14px">You are signed in as <b>' + esc(me.username ? '@' + me.username : me.email) + '</b>. Your tickets and Marty\'s replies live in <a href="/help">Help in your Control Room</a>, the easiest place to follow up. This form works too and files the ticket under your account.</span>') : '')
+ '<div class="tile"><div class="ph"><h2>Send a ticket</h2><span class="meta">Marty reads every one</span></div><form class="pb" id="supForm" novalidate autocomplete="on">'
+ '<input class="hp-field" type="text" name="website_url" id="supHp" tabindex="-1" aria-hidden="true" autocomplete="off">'
+ (signedIn ? '' : '<label class="lbl" for="supName">Your name<input class="field" id="supName" maxlength="80" autocomplete="name"></label>'
+ '<label class="lbl" for="supEmail">Your email (replies go here)<input class="field" id="supEmail" type="email" maxlength="190" autocomplete="email" required></label>')
+ '<label class="lbl" for="supCat">What is it about?<select class="field" id="supCat">' + CATS.map(c => '<option>' + esc(c) + '</option>').join('') + '</select></label>'
+ '<label class="lbl" for="supSubject">Subject<input class="field" id="supSubject" maxlength="140" placeholder="A few words, like: my sign-in code does not arrive"></label>'
+ '<label class="lbl" for="supBody">Message<textarea class="field" id="supBody" rows="7" maxlength="5000" placeholder="What happened, what you expected, and anything you already tried. Never send your recovery phrase or private key."></textarea></label>'
+ '<div id="supCheck" hidden></div>'
+ '<div class="acts"><button class="btn pri" type="submit" id="supSend">Send to support</button><span class="msg" id="supMsg"></span></div>'
+ '</form></div>';
$('supForm').addEventListener('submit', async e => {
e.preventDefault();
const btn = $('supSend'); if (btn.disabled) return; btn.disabled = true;
const msg = $('supMsg'); msg.className = 'msg'; msg.textContent = 'Sending…';
const val = id => { const el = $(id); return el ? el.value : ''; };
try {
const g = IAP.guard; await g.formSettled();
let pick = null, r = null;
for (let i = 0; i < 4; i++) {
r = await call('/api/support', { name: val('supName'), email: val('supEmail'), category: val('supCat'), subject: val('supSubject'), body: val('supBody'),
fts: g.FORM_TS, hp_field_x9: g.hpValue($('supHp')), pick });
if (r.challenge) { msg.textContent = ''; pick = await g.iconCheck($('supCheck'), r.challenge, r.error); continue; }
break;
}
if (!r || !r.ok) throw new Error('Could not verify. Refresh the page and try again.');
host.innerHTML = panel('Got it. Your ticket is ' + r.ref, '<span class="ink2" style="font-size:14px">Marty reads every ticket and replies as soon as he can. '
+ (r.member ? 'His reply shows up in Help in your Control Room and in your email.' : 'We just emailed you a private link to this ticket, so you can check on it or add more detail without signing in. If it does not arrive, look in spam or promotions.') + '</span>'
+ '<div class="acts">' + (r.member ? '<a class="btn pri" href="/help#t=' + esc(r.ref) + '">Open it in Help</a>' : '<a class="btn pri" href="/support/t/' + esc(r.token) + '">View your ticket</a>') + '<a class="btn" href="/">Back to LinkSpin</a></div>');
window.scrollTo(0, 0);
} catch (err) { msg.className = 'msg bad'; msg.textContent = err.message; }
finally { btn.disabled = false; }
});
}
async function tokenPage(tok) {
const h = $('supH'); if (h) h.textContent = 'Your support ticket';
host.innerHTML = panel('', '<span class="muted">Loading your ticket…</span>');
let v; try { v = await call('/api/support/t/' + encodeURIComponent(tok)); }
catch (e) { host.innerHTML = panel('', '<span>' + esc(e.message) + '</span><div class="acts"><a class="btn pri" href="/support">Send a new ticket</a></div>'); return; }
const draw = v2 => {
host.innerHTML = threadHtml(v2) + panel('Your reply', '<textarea class="field" id="tkBody" rows="4" maxlength="5000" placeholder="Add more detail or answer Marty here"></textarea>'
+ '<div class="acts"><button class="btn pri" type="button" id="tkSend">Send reply</button><span class="msg" id="tkMsg"></span></div>'
+ '<span class="muted" style="font-size:12.5px">Keep this link private: anyone with it can read and answer this ticket. Members can also follow up from <a href="/help">Help in the Control Room</a>.</span>');
const btn = $('tkSend');
btn.addEventListener('click', async () => {
if (btn.disabled) return; btn.disabled = true;
try { const nv = await call('/api/support/t/' + encodeURIComponent(tok) + '/reply', { body: $('tkBody').value }); draw(nv); const mm = $('tkMsg'); mm.className = 'msg'; mm.textContent = 'Reply sent. Marty will see it.'; }
catch (e) { const mm = $('tkMsg'); mm.className = 'msg bad'; mm.textContent = e.message; btn.disabled = false; }
});
};
draw(v);
}
page();
})();