Help desk: support tickets for members (Help pane), the public /support page with private ticket links, chatbot hand-off, and an admin Support pane
- tickets.js: one shared desk (platform iap now, linkspin later), dual-mode store (MySQL tables tickets + ticket_messages, else support.json); refs IAP-<1000+id> / LS-; private no-login link /support/t/<ref>.<HMAC> signed with DATA_DIR/support.key (or SUPPORT_SECRET); ingestEmail() ready for the support@ intake step (threads by Message-ID, then [ref] in the subject from the same sender) - Member Help pane (/my#help): list with status + unread badge, new ticket (category, subject, message, up to 2 screenshots via /api/my/upload), thread + reply (a reply reopens a closed ticket) - Public /support: name, email, category, subject, message behind the sign-up walls (honeypot, form age, per-IP limits with the icon check, global cap) plus a per-email cap; confirmation email with the ref and the private link - Chatbot: CANNED + systemPrompt know the help desk; answers that cannot help (or "talk to a human") offer "Send this to support", which files the last turns as a ticket (members: Help pane; signed out: email + the same guard) - Admin Support pane: open / waiting / closed / all, platform, category, search; open-count badge; ticket view with requester account info, internal notes, status/priority/category, saved replies (site setting supportTemplates); deep link /admin#support?t=<ref> - Notifications: new ticket / member reply -> Telegram to Marty's private chat only (supportTelegramChat, default 1289244227, site bot then Hermes fallback, never a group or the Discord relay) + email to ADMIN_EMAIL, max one per ticket per 10 min; Marty's reply -> email "[IAP-1042] subject" + a 'notice' inbox message for members, bursts batched - support* settings are kept out of /api/config; Support link in the site footer, home footer, member page foot, terms and privacy; "Contact support" errors point at /support - QA walk: member Help ticket flow, admin Support pane + deep link, internal-note leak check, public /support + private link + tampered token + form-age refusal - Cache tags: common.js 20261016a, chat.js 20261016a, my.js 20261016r, admin.js 20261016sp, support.js 20261016a Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+100
-4
@@ -44,16 +44,18 @@
|
||||
});
|
||||
|
||||
// ── panes ──
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', reports: 'Reports', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', gamepass: 'Game Pass', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, reports: loadReports, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, gamepass: loadGamePass, settings: loadSettings };
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', support: 'Support', reports: 'Reports', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', gamepass: 'Game Pass', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, support: loadSupport, reports: loadReports, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, gamepass: loadGamePass, settings: loadSettings };
|
||||
function setPane(name) {
|
||||
const paneQ = String(name || '').split('?')[1] || ''; name = String(name || '').split('?')[0]; // #support?t=IAP-1042 opens that ticket (links in the Telegram ping and admin email)
|
||||
if (!TITLES[name]) name = 'overview';
|
||||
document.querySelectorAll('.pane').forEach(p => { p.hidden = p.id !== 'pane-' + name; });
|
||||
document.querySelectorAll('.bo-menu [data-pane]').forEach(b => b.classList.toggle('on', b.dataset.pane === name));
|
||||
$('boTitle').textContent = TITLES[name];
|
||||
if (location.hash.slice(1) !== name) history.replaceState(null, '', '#' + name);
|
||||
const keepQ = name === 'support' && paneQ ? '?' + paneQ : '';
|
||||
if (location.hash.slice(1) !== name + keepQ) history.replaceState(null, '', '#' + name + keepQ);
|
||||
$('adminArea').classList.remove('side-open');
|
||||
loaders[name]().catch(e => IAP.status(e.message, 'bad'));
|
||||
return loaders[name](paneQ).catch(e => IAP.status(e.message, 'bad'));
|
||||
}
|
||||
document.querySelectorAll('.bo-menu [data-pane]').forEach(b => b.addEventListener('click', () => setPane(b.dataset.pane)));
|
||||
document.addEventListener('click', e => { const g = e.target.closest('[data-goto]'); if (g) setPane(g.dataset.goto); });
|
||||
@@ -72,6 +74,7 @@
|
||||
$('chainLine').textContent = c.chainName + (c.rehearsal ? ' · rehearsal' : '');
|
||||
} catch (e) {}
|
||||
setPane(location.hash.slice(1) || 'overview');
|
||||
supportBadge();
|
||||
}
|
||||
|
||||
// ── overview ──
|
||||
@@ -822,6 +825,99 @@
|
||||
} catch (e) { $('audSub').textContent = e.message; }
|
||||
}
|
||||
if ($('audRun')) $('audRun').addEventListener('click', busy($('audRun'), loadAudit));
|
||||
// ── help desk (2026-10-16): one shared desk (IAP now, LinkSpin later); newest activity first ──
|
||||
const SP_STATUS = { open: 'Open', waiting_on_member: 'Waiting on member', closed: 'Closed' };
|
||||
const SP_AUTHOR = { member: 'Member', admin: 'You', system: 'System' };
|
||||
const ctWhen = ts => ts ? new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : '';
|
||||
const spLink = s => esc(s).replace(/(https?:\/\/[^\s<]+[^\s<.,;:!?)\]])/g, '<a href="$1" target="_blank" rel="noopener nofollow">$1</a>');
|
||||
let spFilter = { status: 'open', platform: '', category: '', q: '' }, spTemplates = [], spCats = [];
|
||||
async function supportBadge() {
|
||||
try { const c = await api('/api/admin/support/counts'); $('supBadge').hidden = !c.open; $('supBadge').textContent = c.open > 99 ? '99+' : c.open; return c; } catch (e) { return null; }
|
||||
}
|
||||
async function loadSupport(q) {
|
||||
const ref = (/(?:^|&)t=((?:IAP|LS)-\d+)/.exec(q || '') || [])[1];
|
||||
if (ref) return openTicket(ref);
|
||||
$('spView').hidden = true; $('spList').hidden = false;
|
||||
const qs = new URLSearchParams(Object.entries(spFilter).filter(([, v]) => v)).toString();
|
||||
const [r, tp] = await Promise.all([api('/api/admin/support' + (qs ? '?' + qs : '')), spTemplates.length ? Promise.resolve({ templates: spTemplates }) : api('/api/admin/support/templates')]);
|
||||
spTemplates = tp.templates || []; spCats = r.categories || spCats;
|
||||
const c = r.counts || {};
|
||||
$('supBadge').hidden = !c.open; $('supBadge').textContent = c.open > 99 ? '99+' : (c.open || '');
|
||||
$('spSub').textContent = (c.open || 0) + ' open · ' + (c.waiting_on_member || 0) + ' waiting on member · ' + (c.unread || 0) + ' unread';
|
||||
const chip = (v, label, n) => '<button type="button" class="chip-t' + (spFilter.status === v ? ' on' : '') + '" data-spst="' + v + '">' + label + (n != null ? ' (' + n + ')' : '') + '</button>';
|
||||
$('spStatus').innerHTML = chip('open', 'Open', c.open || 0) + chip('waiting_on_member', 'Waiting on member', c.waiting_on_member || 0) + chip('closed', 'Closed', c.closed || 0) + chip('', 'All');
|
||||
if (!$('spCategory').options.length) $('spCategory').innerHTML = '<option value="">All categories</option>' + spCats.map(x => '<option>' + esc(x) + '</option>').join('');
|
||||
$('spTable').innerHTML = '<tr><th>Ticket</th><th>Subject</th><th>From</th><th>Category</th><th>Status</th><th>Last activity</th></tr>'
|
||||
+ (r.tickets.length ? r.tickets.map(t => '<tr data-spref="' + esc(t.ref) + '" style="cursor:pointer"><td class="mono small">' + (t.adminUnread ? '<b style="color:var(--amber,#ffb238)">●</b> ' : '') + esc(t.ref)
|
||||
+ (t.platform !== 'iap' ? ' <span class="small muted">' + esc(t.platform) + '</span>' : '') + (t.priority === 'high' ? ' <b style="color:var(--bad)">high</b>' : '') + '</td>'
|
||||
+ '<td>' + (t.adminUnread ? '<b>' + esc(t.subject) + '</b>' : esc(t.subject)) + '<div class="small muted">' + esc(t.source) + '</div></td>'
|
||||
+ '<td class="small">' + esc(t.name || '') + '<div class="muted">' + esc(t.email) + (t.username ? ' · @' + esc(t.username) : '') + '</div></td>'
|
||||
+ '<td class="small">' + esc(t.category) + '</td><td class="small">' + esc(SP_STATUS[t.status] || t.status) + '</td><td class="small muted" style="white-space:nowrap">' + esc(ctWhen(t.updated)) + '</td></tr>').join('')
|
||||
: '<tr><td colspan="6" class="muted">No tickets here.</td></tr>');
|
||||
drawTemplates();
|
||||
}
|
||||
$('spStatus').addEventListener('click', e => { const b = e.target.closest('[data-spst]'); if (!b) return; spFilter.status = b.dataset.spst; loadSupport('').catch(err => IAP.status(err.message, 'bad')); });
|
||||
$('spPlatform').addEventListener('change', () => { spFilter.platform = $('spPlatform').value; loadSupport('').catch(err => IAP.status(err.message, 'bad')); });
|
||||
$('spCategory').addEventListener('change', () => { spFilter.category = $('spCategory').value; loadSupport('').catch(err => IAP.status(err.message, 'bad')); });
|
||||
let spQT = null; $('spQ').addEventListener('input', () => { clearTimeout(spQT); spQT = setTimeout(() => { spFilter.q = $('spQ').value.trim(); loadSupport('').catch(err => IAP.status(err.message, 'bad')); }, 350); });
|
||||
$('spTable').addEventListener('click', e => { const tr = e.target.closest('[data-spref]'); if (tr) { history.replaceState(null, '', '#support?t=' + tr.dataset.spref); openTicket(tr.dataset.spref).catch(err => IAP.status(err.message, 'bad')); } });
|
||||
async function openTicket(ref) {
|
||||
const v = await api('/api/admin/support/' + encodeURIComponent(ref));
|
||||
if (!spTemplates.length) { try { spTemplates = (await api('/api/admin/support/templates')).templates || []; } catch (e) {} }
|
||||
if (!spCats.length) spCats = ['Account & sign-in', 'Wallet & payouts', 'Buying packages', 'Ads & campaigns', 'Earning credits & games', 'Team & referrals', 'Other'];
|
||||
drawTicket(v); supportBadge();
|
||||
}
|
||||
function drawTicket(v) {
|
||||
const t = v.ticket, rq = v.requester || {};
|
||||
$('spList').hidden = true; $('spView').hidden = false;
|
||||
const sel = (id, opts, cur) => '<select id="' + id + '" class="small">' + opts.map(o => '<option value="' + esc(o[0]) + '"' + (o[0] === cur ? ' selected' : '') + '>' + esc(o[1]) + '</option>').join('') + '</select>';
|
||||
const stOpts = Object.entries(SP_STATUS);
|
||||
$('spView').innerHTML = '<p style="margin:0 0 10px"><a href="#support" id="spBack">‹ All tickets</a></p>'
|
||||
+ '<div class="card"><div class="card-head" style="flex-wrap:wrap;gap:8px"><h3 style="margin:0">' + esc(t.subject) + '</h3><span class="sub mono">' + esc(t.ref) + ' · ' + esc(t.platform) + ' · via ' + esc(t.source) + ' · opened ' + esc(ctWhen(t.created)) + '</span></div>'
|
||||
+ '<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:6px 0 0"><label class="small muted">Status ' + sel('spSt', stOpts, t.status) + '</label>'
|
||||
+ '<label class="small muted">Priority ' + sel('spPr', [['normal', 'Normal'], ['high', 'High']], t.priority) + '</label>'
|
||||
+ '<label class="small muted">Category ' + sel('spCat', spCats.map(c => [c, c]), t.category) + '</label></div></div>'
|
||||
+ '<div class="card"><div class="card-head"><h3>Requester</h3><span class="sub">' + (rq.member ? 'member account' : 'no account with this email') + '</span></div>'
|
||||
+ kv([['Name', esc(t.name || '(not given)')], ['Email', esc(t.email)]].concat(rq.member ? [
|
||||
['Account', (rq.username ? '@' + esc(rq.username) : '(no username yet)') + (rq.memberId ? ' · member #' + rq.memberId : ' · free member') + ' · <a href="#" id="spMember" data-email="' + esc(rq.email) + '">open member card</a>'],
|
||||
['Wallet linked', rq.wallet ? 'yes' : 'no'], ['Joined', esc(ctWhen(rq.created))], ['Last seen', esc(ctWhen(rq.lastSeen) || 'never')]] : []).concat([['Private link', '<span class="mono small" style="word-break:break-all">' + esc(v.link) + '</span>']]))
|
||||
+ '</div>'
|
||||
+ '<div class="card"><div class="card-head"><h3>Thread</h3><span class="sub">' + v.messages.length + ' message' + (v.messages.length === 1 ? '' : 's') + '</span></div>'
|
||||
+ v.messages.map(m => '<div style="border:1px solid ' + (m.internal ? 'rgba(242,201,76,.55)' : m.author === 'admin' ? 'rgba(67,232,195,.45)' : 'var(--line)') + ';background:' + (m.internal ? 'rgba(242,201,76,.07)' : m.author === 'admin' ? 'rgba(67,232,195,.05)' : 'transparent') + ';border-radius:12px;padding:10px 14px;margin:8px 0">'
|
||||
+ '<div class="small muted" style="display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap"><b>' + esc(SP_AUTHOR[m.author] || m.author) + (m.internal ? ' · internal note' : '') + (m.via && m.via !== 'web' ? ' · via ' + esc(m.via) : '') + '</b><span>' + esc(ctWhen(m.created)) + '</span></div>'
|
||||
+ '<div style="white-space:pre-wrap;word-wrap:break-word;margin-top:6px">' + spLink(m.body) + '</div>'
|
||||
+ ((m.attachments || []).length ? '<div style="display:flex;gap:8px;margin-top:8px;flex-wrap:wrap">' + m.attachments.map(a => '<a href="' + esc(a) + '" target="_blank" rel="noopener"><img src="' + esc(a) + '" alt="attachment" style="max-width:180px;max-height:140px;border-radius:8px;border:1px solid var(--line)"></a>').join('') + '</div>' : '') + '</div>').join('')
|
||||
+ '</div>'
|
||||
+ '<div class="card"><div class="card-head"><h3>Reply</h3><span class="sub">emailed to the requester' + (rq.member ? ' and put in their Help tab and inbox' : '') + '</span></div>'
|
||||
+ '<p style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin:0 0 8px"><select id="spTpl" class="small"><option value="">Insert a saved reply…</option>' + spTemplates.map((x, i) => '<option value="' + i + '">' + esc(x.name) + '</option>').join('') + '</select></p>'
|
||||
+ '<textarea id="spBody" rows="7" style="width:100%" maxlength="5000" placeholder="Write your reply"></textarea>'
|
||||
+ '<p style="display:flex;gap:14px;flex-wrap:wrap;align-items:center;margin:10px 0 0"><label class="small"><input type="checkbox" id="spInternal"> Internal note (only you see it, nothing is sent)</label>'
|
||||
+ '<label class="small muted">Then set status ' + sel('spAfter', stOpts, 'waiting_on_member') + '</label>'
|
||||
+ '<button type="button" class="btn small" id="spSend">Send reply</button></p></div>';
|
||||
$('spBack').addEventListener('click', e => { e.preventDefault(); history.replaceState(null, '', '#support'); loadSupport('').catch(err => IAP.status(err.message, 'bad')); });
|
||||
const patch = async f => { try { drawTicket(await api('/api/admin/support/' + encodeURIComponent(t.ref), f, 'PATCH')); supportBadge(); IAP.status('Saved.', 'ok'); } catch (e) { IAP.status(e.message, 'bad'); } };
|
||||
$('spSt').addEventListener('change', () => patch({ status: $('spSt').value }));
|
||||
$('spPr').addEventListener('change', () => patch({ priority: $('spPr').value }));
|
||||
$('spCat').addEventListener('change', () => patch({ category: $('spCat').value }));
|
||||
if ($('spMember')) $('spMember').addEventListener('click', async e => { e.preventDefault(); await setPane('members'); openMember(e.target.dataset.email); });
|
||||
$('spTpl').addEventListener('change', () => { const x = spTemplates[Number($('spTpl').value)]; if (x) { const b = $('spBody'); b.value = (b.value ? b.value.replace(/\s+$/, '') + '\n\n' : '') + x.body; b.focus(); } $('spTpl').value = ''; });
|
||||
$('spInternal').addEventListener('change', () => { $('spAfter').value = $('spInternal').checked ? t.status : 'waiting_on_member'; $('spSend').textContent = $('spInternal').checked ? 'Save note' : 'Send reply'; });
|
||||
$('spSend').addEventListener('click', busy($('spSend'), async () => {
|
||||
const internal = $('spInternal').checked;
|
||||
if (!internal && !(await IAP.confirmBox('Send this reply to ' + t.email + '?', { ok: 'Send', cancel: 'Not yet' }))) return;
|
||||
drawTicket(await api('/api/admin/support/' + encodeURIComponent(t.ref) + '/reply', { body: $('spBody').value, internal, status: $('spAfter').value }));
|
||||
supportBadge(); IAP.status(internal ? 'Note saved.' : 'Reply sent.', 'ok');
|
||||
}));
|
||||
}
|
||||
function drawTemplates() {
|
||||
$('spTpls').innerHTML = spTemplates.map((x, i) => '<div class="sp-tpl" style="border:1px solid var(--line);border-radius:10px;padding:10px;margin:0 0 8px"><div style="display:flex;gap:8px"><input class="small" data-tn="' + i + '" value="' + esc(x.name) + '" placeholder="name" style="flex:1"><button type="button" class="btn small sec" data-tdel="' + i + '">Remove</button></div>'
|
||||
+ '<textarea class="small" data-tb="' + i + '" rows="3" style="width:100%;margin-top:6px">' + esc(x.body) + '</textarea></div>').join('') || '<p class="small muted">No saved replies. Add one below.</p>';
|
||||
}
|
||||
const readTemplates = () => [...document.querySelectorAll('#spTpls [data-tn]')].map(el => ({ name: el.value, body: document.querySelector('#spTpls [data-tb="' + el.dataset.tn + '"]').value }));
|
||||
$('spTpls').addEventListener('click', e => { const b = e.target.closest('[data-tdel]'); if (!b) return; spTemplates = readTemplates(); spTemplates.splice(Number(b.dataset.tdel), 1); drawTemplates(); });
|
||||
$('spTplAdd').addEventListener('click', () => { spTemplates = readTemplates(); spTemplates.push({ name: '', body: '' }); drawTemplates(); const n = document.querySelector('#spTpls [data-tn="' + (spTemplates.length - 1) + '"]'); if (n) n.focus(); });
|
||||
$('spTplSave').addEventListener('click', busy($('spTplSave'), async () => { const r = await api('/api/admin/support/templates', { templates: readTemplates() }, 'PUT'); spTemplates = r.templates || []; drawTemplates(); IAP.status('Saved replies saved.', 'ok'); }));
|
||||
|
||||
async function loadReports() {
|
||||
loadAudit();
|
||||
const [r, b] = await Promise.all([api('/api/admin/reports'), api('/api/admin/burns')]);
|
||||
|
||||
Reference in New Issue
Block a user