Files
linkspin/public/assets/help-screen.js
T
martbost aa7595a9cd Smarter chatbot + support matching by meaning (Marty 2026-11-16): the hub's semantic match (free core2 embeddings)
Chatbot (chatbot.js + netkb.js route): a hand-off pattern still answers first; then the hub's POST /v1/kb/match answers with
this site's entry when it is sure, keeps or overrules the CANNED regex hit, and picks the AI prompt context, this site's own
entries first. 1.5 s timeout, then the hub is skipped for 30 s and the old pattern + BM25 path answers (NETKB_MATCH=0 = off).
Support desk: while a signed-in member types a new ticket, POST /api/my/support/suggest shows the closest help answers (KB
entries only, incl. ones written from past tickets, never another member's ticket; BM25 when the hub is down); Send is never
blocked. help-screen.js?v=20261116sg.
Tests: qa/netkb-semantic.test.mjs (route/suggest decisions, fail soft, shared-file parity; run.sh kb) and
qa/support-suggest.mjs (run.sh member). netkb.js is the same file in all eight network sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 05:53:38 -06:00

107 lines
9.2 KiB
JavaScript
Raw 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 id="hnSuggest" class="hsg" hidden aria-live="polite"></div>'
+ '<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>';
suggest();
$('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();
}
// help answers while typing (2026-11-16): debounced, from the KB only (the hub's semantic match); a suggestion never blocks Send
function suggest() {
const box = $('hnSuggest'), subj = $('hnSubject'), body = $('hnBody');
if (!box || !subj || !body) return;
let timer = null, seq = 0, last = '';
const run = async () => {
const text = (subj.value + ' ' + body.value).replace(/\s+/g, ' ').trim();
if (text.replace(/[^A-Za-z0-9]/g, '').length < 10) { box.hidden = true; box.innerHTML = ''; last = ''; return; }
if (text === last) return; last = text; const mine = ++seq;
let r; try { r = await CR.api('/api/my/support/suggest', { subject: subj.value, body: body.value }); } catch (e) { return; }
if (mine !== seq || !document.body.contains(box)) return;
const items = (r && r.items) || [];
if (!items.length) { box.hidden = true; box.innerHTML = ''; return; }
box.innerHTML = '<p class="hsg-h"><b>These answers may help</b> <span>You can still send your ticket.</span></p>'
+ items.map(i => '<details><summary>' + esc(i.title) + (i.site ? ' <span class="hsg-s">(' + esc(i.site) + ')</span>' : '') + (i.fromTicket ? ' <span class="hsg-s">from a past ticket</span>' : '') + '</summary>'
+ '<div class="hsg-b">' + linkify(i.answer) + (i.link && i.site ? '<br><a href="' + esc(i.link) + '" target="_blank" rel="noopener">Open ' + esc(i.site) + '</a>' : '') + '</div></details>').join('');
box.hidden = false;
};
const kick = () => { clearTimeout(timer); timer = setTimeout(run, 700); };
subj.addEventListener('input', kick); body.addEventListener('input', kick);
}
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); });
})();