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:
martbost
2026-10-16 16:51:30 -05:00
parent f0c868ef23
commit 9be58bd5ef
35 changed files with 1078 additions and 59 deletions
+33
View File
@@ -332,6 +332,39 @@ async function bootstrap() {
await alterSafe('ALTER TABLE accounts ADD COLUMN joined_via VARCHAR(20) NULL'); // ?v= angle the lead came in on
await alterSafe('ALTER TABLE accounts ADD COLUMN joined_ref VARCHAR(80) NULL'); // referring domain of the first join-page visit
await alterSafe('ALTER TABLE accounts ADD COLUMN wall_offers VARCHAR(2000) NULL'); // JSON [{title,bannerUrl,targetUrl}] for wall positions 2-3 (unlock at 2 / 5 qualifying buyers)
// help desk (2026-10-16, tickets.js): one shared desk for IAP and, later, LinkSpin; email_message_id threads inbound mail
await q(`CREATE TABLE IF NOT EXISTS tickets (
id INT AUTO_INCREMENT PRIMARY KEY,
ref VARCHAR(20) NOT NULL UNIQUE,
platform VARCHAR(12) NOT NULL DEFAULT 'iap',
source VARCHAR(12) NOT NULL DEFAULT 'form',
email VARCHAR(190) NOT NULL,
name VARCHAR(80) NULL,
username VARCHAR(30) NULL,
subject VARCHAR(160) NOT NULL,
category VARCHAR(40) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'open',
priority VARCHAR(8) NOT NULL DEFAULT 'normal',
created BIGINT NOT NULL,
updated BIGINT NOT NULL,
last_member_at BIGINT NULL,
last_admin_at BIGINT NULL,
admin_unread TINYINT NOT NULL DEFAULT 0,
member_unread TINYINT NOT NULL DEFAULT 0,
INDEX (email), INDEX (status, updated), INDEX (platform, updated)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`);
await q(`CREATE TABLE IF NOT EXISTS ticket_messages (
id INT AUTO_INCREMENT PRIMARY KEY,
ticket_id INT NOT NULL,
author VARCHAR(8) NOT NULL,
body TEXT NOT NULL,
internal TINYINT NOT NULL DEFAULT 0,
attachments VARCHAR(400) NULL,
created BIGINT NOT NULL,
email_message_id VARCHAR(250) NULL,
via VARCHAR(12) NOT NULL DEFAULT 'web',
INDEX (ticket_id), INDEX (email_message_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`);
}
// one-time import: only when the tables are empty and JSON files exist