Help desk: signed partner API for LinkSpin tickets (LS- refs on the one shared desk)

POST /api/partner/support/{create,list,view,reply,token,token-reply}, signed exactly
like the registry rows (LS_SYNC_SECRET, X-LS-Ts + X-LS-Sig, now one readLsSigned helper
shared with /api/partner/registry). Only platform 'linkspin' tickets are reachable there.

LinkSpin tickets: requester mail, links and footer say LinkSpin support and point at
LS_URL (/support/t/<token>, /help#t=<ref>); no InstantAdPay in-app notice is sent for
them. Telegram ping, admin mail and the support bot's thread/list views mark them
LinkSpin. The member Help pane here lists InstantAdPay tickets only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-16 18:04:52 -05:00
parent 80885705d2
commit 524ce843dc
3 changed files with 81 additions and 35 deletions
+40 -9
View File
@@ -1047,6 +1047,17 @@ function supportGuard(req, b, email) {
supportGlobal.n += 1; supportMark('ip:' + ip); supportMark('em:' + email);
return null;
}
// LinkSpin partner calls (registry rows, help desk): one secret both ways, LS_SYNC_SECRET, as X-LS-Ts (ms) + X-LS-Sig =
// hex HMAC-SHA256(ts + newline + raw body), 10-minute window. Resolves { body } or { status, error }.
async function readLsSigned(req, maxBytes) {
const secret = String(process.env.LS_SYNC_SECRET || '').trim(); if (secret.length < 32) return { status: 503, error: 'sync not configured' };
const raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > maxBytes) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); });
const ts = String(req.headers['x-ls-ts'] || ''), sig = String(req.headers['x-ls-sig'] || '');
if (!/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 10 * 60000) return { status: 401, error: 'stale' };
const want = crypto.createHmac('sha256', secret).update(ts + '\n' + raw).digest('hex');
if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return { status: 401, error: 'bad signature' };
try { return { body: JSON.parse(raw || '{}') }; } catch (e) { return { status: 400, error: 'bad json' }; }
}
function fraudAlert(email, fc, spAcct, blocked) {
try {
const sc = siteConfig();
@@ -2968,16 +2979,36 @@ const server = http.createServer(async (req, res) => {
// over ts + newline + raw body, 10-minute window). New people become waiting accounts with their LinkSpin line; existing
// accounts keep their sponsor and only get empty fields filled. No mail, no notices, no chain (lsinbound.js).
if (p === '/api/partner/registry' && req.method === 'POST') {
const secret = String(process.env.LS_SYNC_SECRET || '').trim(); if (secret.length < 32) return json(res, 503, { error: 'sync not configured' });
const raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > 2e6) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); });
const ts = String(req.headers['x-ls-ts'] || ''), sig = String(req.headers['x-ls-sig'] || '');
if (!/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 10 * 60000) return json(res, 401, { error: 'stale' });
const want = crypto.createHmac('sha256', secret).update(ts + '\n' + raw).digest('hex');
if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return json(res, 401, { error: 'bad signature' });
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); }
const sg = await readLsSigned(req, 2e6); if (!sg.body) return json(res, sg.status, { error: sg.error });
const b = sg.body;
const rows = Array.isArray(b.rows) ? b.rows.slice(0, 500) : [];
return json(res, 200, Object.assign({ ok: true }, await lsinbound.receive(rows)));
}
// -- help desk for LinkSpin (2026-10-16): LinkSpin has no desk of its own; its Help screen, /support page, private ticket
// link and chat hand-off all proxy here, signed like the registry rows. LinkSpin runs the person-facing guards (sign-in,
// honeypot, form age, icon check) and vouches for the email; this side only ever touches platform 'linkspin' tickets
// (LS- refs). Replies to the requester point at LinkSpin (tickets.js BRAND), never an InstantAdPay notice.
m = /^\/api\/partner\/support\/(create|list|view|reply|token|token-reply)$/.exec(p);
if (m && req.method === 'POST') {
const sg = await readLsSigned(req, 64000); if (!sg.body) return json(res, sg.status, { error: sg.error });
const b = sg.body, op = m[1];
const email = String(b.email || '').trim().toLowerCase();
const mine = async () => { const t = await tickets.byRef(b.ref); return t && t.platform === 'linkspin' && t.email === email ? t : null; };
const byTok = async () => { const t = await tickets.byToken(b.token); return t && t.platform === 'linkspin' ? t : null; };
if (op === 'create') {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'That email address does not look right.' });
if (supportFlood('ls:' + email, 8, 3600000)) return json(res, 429, { error: 'You have sent several tickets in the last hour. Add to one of those instead.' }); // backstop behind LinkSpin's own limits
const r = await tickets.create({ platform: 'linkspin', source: ['form', 'public', 'chatbot'].includes(b.source) ? b.source : 'public', email, name: b.name, username: b.username, subject: b.subject, category: b.category, body: b.body });
return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, ref: r.ticket.ref, token: r.token });
}
if (op === 'list') return json(res, 200, { tickets: await tickets.memberList(email, 'linkspin'), unread: await tickets.memberUnread(email, 'linkspin'), categories: tickets.CATEGORIES });
const t = op === 'view' || op === 'reply' ? await mine() : await byTok();
if (!t) return json(res, 404, { error: op.startsWith('token') ? 'This ticket link is not valid. Open the newest email about your ticket, or send a new one.' : 'Ticket not found.' });
if (op === 'view' || op === 'token') return json(res, 200, await tickets.memberView(t));
if (supportFlood('tk:' + t.id, 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 tickets.addMessage(t.id, { author: 'member', body: b.body, via: op === 'token-reply' ? 'link' : 'web' });
return json(res, r.error ? 400 : 200, r.error ? r : await tickets.memberView(r.ticket));
}
if (p === '/api/admin/lssync/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); return json(res, 200, await lssync.tick(!!(b && b.force))); }
if (p === '/api/admin/walletnudge/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await walletnudge.tick()); }
if (p === '/api/admin/tank' && req.method === 'GET') {
@@ -3902,7 +3933,7 @@ const server = http.createServer(async (req, res) => {
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.' });
if (req.method === 'GET') return json(res, 200, { tickets: await tickets.memberList(s.email), unread: await tickets.memberUnread(s.email), categories: tickets.CATEGORIES });
if (req.method === 'GET') return json(res, 200, { tickets: await tickets.memberList(s.email, 'iap'), unread: await tickets.memberUnread(s.email, 'iap'), categories: tickets.CATEGORIES }); // LinkSpin tickets live in LinkSpin's Help
const b = await readBody(req);
if (supportFlood('em:' + String(s.email).toLowerCase(), 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(s.email);
@@ -3914,7 +3945,7 @@ const server = http.createServer(async (req, res) => {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const t = await tickets.byRef(m[1]);
if (!t || t.email !== String(s.email).toLowerCase()) return json(res, 404, { error: 'Ticket not found.' });
if (!t || t.email !== String(s.email).toLowerCase() || t.platform !== 'iap') return json(res, 404, { error: 'Ticket not found.' });
if (req.method === 'GET') return json(res, 200, await tickets.memberView(t));
const b = await readBody(req);
if (supportFlood('tk:' + t.id, 20, 3600000)) return json(res, 429, { error: 'That is a lot of messages in an hour. Give Marty a moment to catch up.' });
+4 -4
View File
@@ -1,8 +1,8 @@
// Help desk in Telegram (Marty, 2026-10-16): @CTBTickets_bot pings Marty's PRIVATE chat for every new ticket and member
// reply, with buttons (Close, Waiting, High, Open in admin), and takes his answers back: reply to a ticket message and
// the text goes to the requester exactly as an admin reply would; start it with /note to keep it internal. /tickets
// lists what is open, /t IAP-1042 shows a thread. Updates arrive on a webhook guarded by a secret header, and only
// the configured private chat is obeyed. Token: env SUPPORT_BOT_TOKEN; webhook secret: env SUPPORT_TG_SECRET.
// lists what is open, /t IAP-1042 shows a thread (LS- refs are LinkSpin tickets, marked 🔗). Updates arrive on a webhook
// guarded by a secret header, and only the configured private chat is obeyed. Token: env SUPPORT_BOT_TOKEN; webhook secret: env SUPPORT_TG_SECRET.
'use strict';
const https = require('https');
@@ -60,14 +60,14 @@ async function sendList(which) {
const { title, rows } = await fetchList(which);
if (!rows.length) return say(title + ': none right now.', { reply_markup: MENU });
const shown = rows.slice(0, 20);
const buttons = shown.map(t => [{ text: (t.priority === 'high' ? '🔥 ' : '') + t.ref + ' · ' + String(t.subject).slice(0, 40), callback_data: 'tv|' + t.ref }]);
const buttons = shown.map(t => [{ text: (t.priority === 'high' ? '🔥 ' : '') + (t.platform === 'linkspin' ? '🔗 ' : '') + t.ref + ' · ' + String(t.subject).slice(0, 40), callback_data: 'tv|' + t.ref }]);
return say('<b>' + title + '</b> (' + rows.length + ')' + (rows.length > shown.length ? ', newest 20 shown' : '') + '\nTap one to open it.', { reply_markup: { inline_keyboard: buttons } });
}
async function showThread(ref) {
const t = await deps.tickets.byRef(ref); if (!t) return say('No ticket ' + escH(ref) + '.');
const v = await deps.tickets.adminView(t.id);
const msgs = (v.messages || []).slice(-6).map(m => (m.internal ? '📝 note' : m.author === 'admin' ? '↩️ you' : '👤 ' + escH(t.name || t.email)) + ': ' + escH(String(m.body).slice(0, 500)));
return say('<b>' + t.ref + '</b> · ' + STATUS_WORD[t.status] + ' · ' + escH(t.platform) + ' · ' + escH(t.category) + '\n' + escH(t.email) + '\n<b>' + escH(t.subject) + '</b>\n\n' + msgs.join('\n\n'), { reply_markup: keyboard(t.ref) });
return say('<b>' + t.ref + '</b> · ' + STATUS_WORD[t.status] + ' · ' + (t.platform === 'linkspin' ? '🔗 <b>LinkSpin</b>' : escH((deps.tickets.PLATFORM_NAME || {})[t.platform] || t.platform)) + ' · ' + escH(t.category) + '\n' + escH(t.email) + '\n<b>' + escH(t.subject) + '</b>\n\n' + msgs.join('\n\n'), { reply_markup: keyboard(t.ref) });
}
// webhook: returns nothing; the caller always answers 200 so Telegram does not retry forever
+37 -22
View File
@@ -1,11 +1,14 @@
// Help desk (Marty, 2026-10-16): one shared support desk in the IAP admin portal. A member emailed
// support@instantadpay.com when it did not exist, so nobody had a way to ask for help. Tickets come in
// from the member Help pane ('form'), the public /support page ('public'), the chatbot hand-off
// ('chatbot') and, in a later step, inbound mail to support@ ('email'). LinkSpin tickets will land on
// this same desk later (platform 'linkspin'). Only Marty answers for now, from his admin login.
// ('chatbot') and, in a later step, inbound mail to support@ ('email'). LinkSpin tickets land on this
// same desk through the signed partner API (server.js /api/partner/support/*, LS_SYNC_SECRET), as
// platform 'linkspin': their links, emails and copy point at LinkSpin (LS_URL), and a LinkSpin ticket
// never sends an InstantAdPay in-app notice (LinkSpin shows its own unread badge). Only Marty answers,
// from his admin login or Telegram.
//
// Refs: IAP-<1000 + id> (LS-<1000 + id> for LinkSpin), one id sequence for the whole desk, so a ref
// always names one ticket. The private no-login link is /support/t/<ref>.<32-char HMAC>, signed over
// always names one ticket. The private no-login link is <site>/support/t/<ref>.<32-char HMAC>, signed over
// the ticket id and requester email (DATA_DIR/support.key, or SUPPORT_SECRET), nothing stored.
//
// Email intake (next step) plugs in through ingestEmail({ from, name, subject, text, messageId,
@@ -20,6 +23,13 @@ const db = require('./db');
let DATA_DIR = null, deps = {};
const SITE = 'https://instantadpay.com';
// per-platform face of the desk: where the requester's links point and whose name signs the mail
const BRAND = {
iap: { site: () => SITE, name: 'InstantAdPay', help: ref => SITE + '/my#help?t=' + ref, footer: 'Reply on the page above, or email support@instantadpay.com and keep the ticket number in the subject.' },
linkspin: { site: () => String(process.env.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''), name: 'LinkSpin', help: ref => BRAND.linkspin.site() + '/help#t=' + ref, footer: 'Reply on the page above, or from Help in your LinkSpin Control Room.' }
};
const brandOf = t => BRAND[t && t.platform] || BRAND.iap;
const PLATFORM_NAME = { iap: 'InstantAdPay', linkspin: 'LinkSpin' };
const CATEGORIES = ['Account & sign-in', 'Wallet & payouts', 'Buying packages', 'Ads & campaigns', 'Earning credits & games', 'Team & referrals', 'Other'];
const STATUSES = ['open', 'waiting_on_member', 'closed'];
const PRIORITIES = ['normal', 'high'];
@@ -63,7 +73,7 @@ function secret() {
}
const sig = t => crypto.createHmac('sha256', secret()).update('support:' + t.id + ':' + lc(t.email)).digest('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '').slice(0, 32);
const tokenFor = t => t.ref + '.' + sig(t);
const linkFor = t => SITE + '/support/t/' + tokenFor(t);
const linkFor = t => brandOf(t).site() + '/support/t/' + tokenFor(t);
const TOKEN_RE = /^((?:IAP|LS)-\d{4,9})\.([A-Za-z0-9_-]{32})$/;
// ---- stores ----
@@ -89,7 +99,7 @@ const J = {
async messages(ticketId, internal) { return this.d().messages.filter(m => m.ticketId === Number(ticketId) && (internal || !m.internal)).sort((a, b) => a.id - b.id).map(m => Object.assign({}, m)); },
async byMessageId(mids) { const s = new Set(mids); const m = this.d().messages.find(x => x.emailMessageId && s.has(x.emailMessageId)); return m ? m.ticketId : 0; },
async counts() { const out = { open: 0, waiting_on_member: 0, closed: 0, unread: 0 }; for (const t of this.d().tickets) { out[t.status] = (out[t.status] || 0) + 1; if (t.adminUnread) out.unread++; } return out; },
async memberUnread(email) { return this.d().tickets.filter(t => t.email === email && t.memberUnread).length; }
async memberUnread(email, platform) { return this.d().tickets.filter(t => t.email === email && t.memberUnread && (!platform || t.platform === platform)).length; }
};
const tRow = r => r ? ({ id: r.id, ref: r.ref, platform: r.platform, source: r.source, email: r.email, name: r.name || '', username: r.username || '',
subject: r.subject, category: r.category, status: r.status, priority: r.priority, created: Number(r.created), updated: Number(r.updated),
@@ -132,7 +142,7 @@ const D = {
for (const r of await db.q('SELECT status, COUNT(*) n, SUM(admin_unread) u FROM tickets GROUP BY status')) { out[r.status] = Number(r.n); out.unread += Number(r.u || 0); }
return out;
},
async memberUnread(email) { return Number((await db.q('SELECT COUNT(*) n FROM tickets WHERE email=? AND member_unread=1', [email]))[0].n); }
async memberUnread(email, platform) { return Number((await db.q('SELECT COUNT(*) n FROM tickets WHERE email=? AND member_unread=1' + (platform ? ' AND platform=?' : ''), platform ? [email, platform] : [email]))[0].n); }
};
const impl = () => db.enabled() ? D : J;
@@ -167,7 +177,8 @@ const firstLine = s => oneLine(String(s || '').split('\n').find(l => l.trim()) |
function pingAdmin(kind, t, m) {
const send = items => {
const last = items[items.length - 1];
const head = kind === 'new' ? '\u{1F3AB} <b>' + t.ref + '</b> new ticket' : '\u{1F4AC} <b>' + t.ref + '</b> ' + (items.length > 1 ? items.length + ' member replies' : 'member reply');
const ls = t.platform === 'linkspin'; // LinkSpin tickets say so up front, so Marty knows which site the person is on
const head = (kind === 'new' ? '\u{1F3AB} <b>' + t.ref + '</b> new ' + (ls ? '\u{1F517} <b>LinkSpin</b> ' : '') + 'ticket' : '\u{1F4AC} <b>' + t.ref + '</b> ' + (ls ? '\u{1F517} <b>LinkSpin</b> ' : '') + (items.length > 1 ? items.length + ' member replies' : 'member reply'));
let extra = '';
if (kind === 'new') {
const h = Math.floor(Date.now() / 3600000);
@@ -175,43 +186,46 @@ function pingAdmin(kind, t, m) {
if (++newPings.n > 20) { newPings.skipped++; return; }
if (newPings.skipped) { extra = '\n(+' + newPings.skipped + ' more new tickets earlier were not pinged)'; newPings.skipped = 0; }
}
const text = head + ' · ' + t.platform + ' · ' + escH(t.category) + '\n' + escH(who(t)) + '\n' + escH(t.subject) + '\n“' + escH(firstLine(last.body)) + '”\n' + adminLink(t) + extra;
const text = head + ' · ' + (ls ? '' : (PLATFORM_NAME[t.platform] || t.platform) + ' · ') + escH(t.category) + '\n' + escH(who(t)) + '\n' + escH(t.subject) + '\n“' + escH(firstLine(last.body)) + '”\n' + adminLink(t) + extra;
if (deps.telegram) deps.telegram(text, t.ref).catch(() => {});
if (deps.adminEmail && deps.mailer && deps.mailer.hasKey()) {
const body = items.map(i => i.body).join('\n\n---\n\n');
deps.mailer.send(deps.adminEmail, '[' + t.ref + '] ' + (kind === 'new' ? 'New ticket: ' : 'Reply: ') + t.subject,
(kind === 'new' ? 'New support ticket' : 'Member reply') + ' on ' + t.platform + ' (' + t.category + ')\nFrom: ' + who(t) + '\nSource: ' + t.source + '\n\n' + body + '\n\nAnswer it in the desk: ' + adminLink(t), null, { transactional: true }).catch(e => console.error('support admin mail', e.message));
deps.mailer.send(deps.adminEmail, '[' + t.ref + '] ' + (kind === 'new' ? 'New ' + (t.platform === 'linkspin' ? 'LinkSpin ' : '') + 'ticket: ' : 'Reply: ') + t.subject,
(kind === 'new' ? 'New support ticket' : 'Member reply') + ' on ' + (PLATFORM_NAME[t.platform] || t.platform) + ' (' + t.category + ')\nFrom: ' + who(t) + '\nSource: ' + t.source + '\n\n' + body + '\n\nAnswer it in the desk: ' + adminLink(t), null, { transactional: true }).catch(e => console.error('support admin mail', e.message));
}
};
if (kind === 'new') return send([m]);
throttled('admin:' + t.id, 10 * 60 * 1000, m, send);
}
function htmlMail(intro, blocks, link, linkLabel) {
function htmlMail(intro, blocks, link, linkLabel, brand) {
const b = brand || BRAND.iap;
return '<div style="font-family:Arial,sans-serif;font-size:15px;line-height:1.5;color:#1d2420;max-width:560px">'
+ '<p>' + escH(intro) + '</p>' + blocks.map(b => '<div style="border-left:3px solid #43e8c3;padding:6px 12px;margin:12px 0;white-space:pre-wrap">' + escH(b) + '</div>').join('')
+ '<p><a href="' + link + '" style="display:inline-block;background:#043b2f;color:#fff;padding:10px 16px;border-radius:8px;text-decoration:none">' + escH(linkLabel) + '</a></p>'
+ '<p style="font-size:12px;color:#777">InstantAdPay support. Reply on the page above, or email support@instantadpay.com and keep the ticket number in the subject.</p></div>';
+ '<p style="font-size:12px;color:#777">' + escH(b.name) + ' support. ' + escH(b.footer) + '</p></div>';
}
function confirmRequester(t, m) {
if (!deps.mailer || !deps.mailer.hasKey()) return;
const link = linkFor(t);
const link = linkFor(t), b = brandOf(t);
const text = 'Hi' + (t.name ? ' ' + t.name : '') + ',\n\nWe got your message and opened ticket ' + t.ref + '. Marty reads every one and will reply as soon as he can.\n\n'
+ 'Subject: ' + t.subject + '\n\n' + m.body + '\n\nView the ticket or add more detail here (no sign-in needed):\n' + link + '\n\nInstantAdPay support';
deps.mailer.send(t.email, '[' + t.ref + '] ' + t.subject, text, htmlMail('We got your message and opened ticket ' + t.ref + '. Marty reads every one and will reply as soon as he can.', [m.body], link, 'View your ticket'), { transactional: true })
+ 'Subject: ' + t.subject + '\n\n' + m.body + '\n\nView the ticket or add more detail here (no sign-in needed):\n' + link + '\n\n' + b.name + ' support';
deps.mailer.send(t.email, '[' + t.ref + '] ' + t.subject, text, htmlMail('We got your message and opened ticket ' + t.ref + '. Marty reads every one and will reply as soon as he can.', [m.body], link, 'View your ticket', b), { transactional: true })
.catch(e => console.error('support confirm mail', e.message));
}
function notifyRequester(t, m) {
throttled('member:' + t.id, 2 * 60 * 1000, m, async items => {
const cur = (await impl().getTicket(t.id)) || t;
const link = linkFor(cur);
const link = linkFor(cur), b = brandOf(cur);
const bodies = items.map(i => i.body);
if (deps.mailer && deps.mailer.hasKey()) {
const text = 'Hi' + (cur.name ? ' ' + cur.name : '') + ',\n\nMarty replied to your support ticket ' + cur.ref + ':\n\n' + bodies.join('\n\n---\n\n')
+ '\n\nRead the whole thread and reply here:\n' + link + '\n\nInstantAdPay support';
deps.mailer.send(cur.email, '[' + cur.ref + '] ' + cur.subject, text, htmlMail('Marty replied to your support ticket ' + cur.ref + ':', bodies, link, 'Read and reply'), { transactional: true })
+ '\n\nRead the whole thread and reply here:\n' + link + (cur.platform === 'linkspin' ? '\n\nOr open Help in your LinkSpin Control Room: ' + b.help(cur.ref) : '') + '\n\n' + b.name + ' support';
deps.mailer.send(cur.email, '[' + cur.ref + '] ' + cur.subject, text, htmlMail('Marty replied to your support ticket ' + cur.ref + ':', bodies, link, 'Read and reply', b), { transactional: true })
.catch(e => console.error('support reply mail', e.message));
}
// members also get it in their on-site inbox, as a notice: it never pops the sign-in modal
// members also get it in their on-site inbox, as a notice: it never pops the sign-in modal. InstantAdPay tickets only:
// a LinkSpin ticket is followed on LinkSpin (its Help badge), and its requester may have no real account here at all
if (cur.platform !== 'iap') return;
try {
const acct = deps.accounts && await deps.accounts.byEmail(cur.email);
if (acct && deps.messages) await deps.messages.deliver(1, deps.adminEmail || 'house@instantadpay.com', [cur.email], 'Support replied: [' + cur.ref + '] ' + cur.subject.slice(0, 110),
@@ -288,8 +302,9 @@ async function byToken(tok) {
}
const pubMsg = m => ({ id: m.id, author: m.author, body: m.body, attachments: m.attachments, created: m.created });
const pubTicket = t => ({ ref: t.ref, platform: t.platform, subject: t.subject, category: t.category, status: t.status, created: t.created, updated: t.updated, unread: t.memberUnread });
async function memberList(email) { return (await impl().list({ email: lc(email), limit: 100 })).map(pubTicket); }
async function memberUnread(email) { return impl().memberUnread(lc(email)); }
// platform: only that site's tickets (each site's Help pane shows its own); omitted = all of them
async function memberList(email, platform) { return (await impl().list({ email: lc(email), platform: PLATFORMS.includes(platform) ? platform : '', limit: 100 })).map(pubTicket); }
async function memberUnread(email, platform) { return impl().memberUnread(lc(email), PLATFORMS.includes(platform) ? platform : ''); }
// the requester's view of one ticket (no internal notes); opening it clears their unread flag
async function memberView(t) {
if (t.memberUnread) await impl().updateTicket(t.id, { memberUnread: false });
@@ -319,5 +334,5 @@ async function ingestEmail(e) {
return Object.assign(r, { created: true });
}
module.exports = { init, CATEGORIES, STATUSES, PRIORITIES, PLATFORMS, SOURCES, DEFAULT_TEMPLATES, refOf, parseRef, tokenFor, linkFor,
module.exports = { init, PLATFORM_NAME, CATEGORIES, STATUSES, PRIORITIES, PLATFORMS, SOURCES, DEFAULT_TEMPLATES, refOf, parseRef, tokenFor, linkFor,
create, addMessage, setFields, byRef, byToken, memberList, memberUnread, memberView, adminList, adminView, counts, ingestEmail };