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:
@@ -108,7 +108,7 @@ function head(o) {
|
||||
+ '</head><body><div class="wrap bl">';
|
||||
}
|
||||
function tail() {
|
||||
return '</div><script src="/assets/common.js?v=20261015a"></script><script src="/assets/blog-page.js?v=20260921a"></script></body></html>';
|
||||
return '</div><script src="/assets/common.js?v=20261016a"></script><script src="/assets/blog-page.js?v=20260921a"></script></body></html>';
|
||||
}
|
||||
const authorBox = () => '<div class="author"><img src="/logo-icon.png" alt="InstantAdPay"><div><b>' + AUTHOR + '</b><span>Founder of InstantAdPay and the Crypto Team Build Network. Twenty-plus years of internet marketing, and a habit of writing down what actually worked.</span></div></div>';
|
||||
const cardHtml = p => '<a class="post-card" href="/blog/' + esc(p.slug) + '">' + (p.cover ? '<img src="' + esc(p.cover) + '" alt="" loading="lazy" style="width:100%;border-radius:10px;margin:0 0 12px">' : '') + '<h2>' + esc(p.title) + '</h2><p>' + esc(p.excerpt) + '</p><p class="meta">' + fmtDate(p.publishedAt || p.created) + ' · ' + readMinutes(p.body) + ' min read' + (p.tags.length ? ' · ' + p.tags.map(esc).join(', ') : '') + '</p></a>';
|
||||
|
||||
+13
-6
@@ -21,7 +21,10 @@ function enabled() { return !!key(); }
|
||||
|
||||
// ---- canned answers: instant, free, always in voice ----
|
||||
const KNOWLEDGE_DATE = '2026-10-16'; // bump whenever the canned answers / prompt are brought up to date
|
||||
const SUPPORT_RE = /(contact|reach|email|e-mail|message|talk to|speak (to|with)|get hold of) (the )?(support|admin|administrator|owner|marty|staff|team at instantadpay|someone|a (human|person|real person))|support (email|address|ticket|team|desk)|help ?desk|(open|send|file|submit|raise) (a )?(support )?ticket|\b(human|real person|live (agent|person|chat|support))\b|customer (service|support)|support@|how (do|can) i get (help|support)/i;
|
||||
const CANNED = [
|
||||
{ re: SUPPORT_RE, handoff: true,
|
||||
a: 'Open Help in your member dashboard (https://instantadpay.com/my#help) to send Marty a ticket, and his replies land right there and in your email. Not signed in or locked out? Use https://instantadpay.com/support, or email support@instantadpay.com. You can also tap "Send this to support" below and I will pass this chat along.' },
|
||||
{ re: /(game ?pass|pass tournament|daily (pol )?cap|pol cap|cap(ped|s)? (on|in|for) (the )?games?|hit (the|my|today.s) (free )?cap|carr(y|ied) (over|forward))/i,
|
||||
a: 'The Game Pass is $5 for 7 days and covers all nine games on your InstantAdPay account (linked positions included). Free play keeps paying real POL every day; the Pass plays more: higher daily POL caps across every game (1.50 POL a day on repeatable rewards instead of 0.30, and 5 POL a day in all instead of 2), a seat in the weekly Pass Tournament (POL prizes from 5% of pass sales, settled Mondays, top 3 posted to Game Achievements), extra plays or a perk in each game, and the Pass badge. Caps are account-wide and reset at midnight Central. A one-time progress reward (a boss, a chapter, a sector) is never lost: whatever is over the day\u2019s total carries to the next day until it is paid in full; repeatable daily play over the daily cap is simply not paid that day. The Pass never changes how much any reward pays, so it is more game, not more payback. Buy it in Members > Games > Game Pass: it costs 500 purchased credits (credits from a package you bought; earned credits do not count). If you have none, buy a $5 package and the pass starts the moment it settles, and you keep every credit of the package for your ads. Buying while a pass is active adds 7 days.' },
|
||||
{ re: /(road ?agent|night.?highway|fuel stop|weapons truck)/i,
|
||||
@@ -129,6 +132,7 @@ function systemPrompt() {
|
||||
|
||||
FACTS:
|
||||
- ROAD AGENT (LIVE 2026-10-15, https://roadagent.app): a night-highway shooter open to every member. Open the Games tab and tap Play on the Road Agent card, or go to roadagent.app and sign in with the InstantAdPay email. Drive the four-lane highway, shoot the hostiles (thug sedans, switchblades, gunner vans), spare the civilians, pull into the weapons truck for oil slicks, smoke and missiles. Clearing a sector for the first time pays POL to the wallet on the member's InstantAdPay account, plus a daily patrol reward; scrap buys garage upgrades. Fuel = a sponsor visit: before a run the player visits an advertiser's page (a FUEL STOP), which is a normal verified visit with the dwell timer and human check, charged to the advertiser like any visit; advertisers' existing visits campaigns are already in the rotation, nothing to set up; to get more traffic from the game, top up the visits campaign. Clickable Pause, Sound and Music buttons sit under the game (P / M / N keys also work), and the Run tab has an Invite a friend card with the member's roadagent.app/?ref=<username> link.
|
||||
- HELP DESK (LIVE 2026-10-16): members open Help in the dashboard (/my#help) to send Marty a support ticket (pick a category, a subject, the message, up to 2 screenshots), see each ticket's status (Open, Waiting on you, Closed) and read and answer his replies; a badge shows when he has replied, and replies also arrive by email. Anyone signed out or locked out uses the public form at https://instantadpay.com/support (name, email, category, subject, message) and gets an email with the ticket number (like IAP-1042) and a private link to view and reply, no sign-in needed. support@instantadpay.com also reaches Marty. Replying to a closed ticket opens it again. In this chat, "Send this to support" turns the conversation into a ticket. Only Marty answers, so replies are not instant; never promise a response time.
|
||||
- PRESENTATION (2026-10-15): instantadpay.com/presentation is a public page (no sign-in) with the narrated InstantAdPay presentation, about six minutes, Marty's voice, captions in 6 languages (English, Italiano, Français, Español, Deutsch, Português) chosen with pills under the player. Sixteen parts: the platform, ad reach, the nine games that pay POL, the $20 split ($10 / $4 / $2 / $4 platform, same transaction), three rules, packages, the 2-then-5 unlock, pass-up, wide versus narrow ($800 vs $36, an illustration), Qualified Start, the Pipeline, LinkSpin (pre-launch Nov 1), one wallet across the network, the first week, and 'the target is five'. Share link: Members > Promo tools > 'Share the presentation' copies instantadpay.com/presentation?ref=<username>; ?ref sets the same 30-day sponsor cookie as the invite link, the page shows 'Shared with you by @name' with avatar and a Join button to /join/<username>. It is in the site menu as 'Presentation'. BUILD WIDE VIDEO: first card in Promo tools > Videos ('Build wide: watch the payments flow'), matched link ?v=wide.
|
||||
- WIRED WEDNESDAY: every Wednesday, Central time (midnight to midnight), any ad package of $20 or more (Activation and up; no $10 pack exists) earns +25% bonus credits wired into the buyer's balance the moment the purchase settles, purchased-grade (usable on every format incl. login ads), credit log label "Wired Wednesday". First one: Wednesday 2026-09-30. Page: instantadpay.com/wednesday. Credits buy ad delivery, never money.
|
||||
- FIVE DOLLAR FRIDAY: every Friday, Central time, any ad package of $5 or more earns +20% bonus credits, credited the moment the purchase settles (credit log shows the label). First one: Friday 2026-09-25. Five Fridays in a row = the Five Fridays badge. The point: the whole network buys on the same day, every pack pays its sponsor line in the same transaction, so every line gets paid at once. No income promises.
|
||||
@@ -206,14 +210,15 @@ FACTS:
|
||||
- Transparency: live ledger at /ledger streams every chain event, and EVERY transaction row carries a clickable "verify" link — to the public block explorer when the chain has one, or to the built-in transaction viewer at /tx/<hash> (block, time, from/to, value, gas, decoded events, read live from the node). Plain-language contract review at /contract; the verified source is public.
|
||||
- The contract cannot be paused, upgraded, or drained. The operator can only manage the ad catalog ($1-$500 bounds, 24h price timelock) and rotate keys.
|
||||
|
||||
PAGES (the ONLY addresses that exist; never invent others): home https://instantadpay.com, member dashboard https://instantadpay.com/my with tabs as hashes: /my#overview, /my#line (My line, holding tank, prospects), /my#pipeline, /my#buy (Buy packages, Qualified Start, Buy POL with a card), /my#campaigns (New campaign, campaign rows, Credit activity), /my#earn (Watch ads, Watch videos, Verified visits, Inbox), /my#earnings (Trace a payment, payouts, referrals, purchases), /my#promo (Your links, Social posts, Text a friend, Email swipes, Banners, Wall, Objections, Videos, Toolkit), /my#training, /my#games (PolHunter, Drip Runner, Gem Kingdom, ClutterHunt, SpellWheel, PolyWarriors, PolyBreak, Spooky Doors in season), /games (public list of every game), /my#wallet, /my#profile. Public: /join/<username> (invite page, ?v=angle), /wall/<username>, /b/<username>/<badge>, /handout/<username>, /ledger, /tx/<hash>, /contract, /leaderboard, /whats-new, /blog, /plays, /wallets (members), /launch (members), /partners, /earning, /shorts, /terms, /privacy, /disclaimer, /from/faucetwave, /from/tieroneads and /from/socialpix.
|
||||
PAGES (the ONLY addresses that exist; never invent others): home https://instantadpay.com, member dashboard https://instantadpay.com/my with tabs as hashes: /my#overview, /my#line (My line, holding tank, prospects), /my#pipeline, /my#buy (Buy packages, Qualified Start, Buy POL with a card), /my#campaigns (New campaign, campaign rows, Credit activity), /my#earn (Watch ads, Watch videos, Verified visits, Inbox), /my#earnings (Trace a payment, payouts, referrals, purchases), /my#promo (Your links, Social posts, Text a friend, Email swipes, Banners, Wall, Objections, Videos, Toolkit), /my#training, /my#games (PolHunter, Drip Runner, Gem Kingdom, ClutterHunt, SpellWheel, PolyWarriors, PolyBreak, Spooky Doors in season), /games (public list of every game), /my#wallet, /my#profile, /my#help (Help: support tickets). Public: /support (contact form for anyone signed out or locked out; support@instantadpay.com also works), /join/<username> (invite page, ?v=angle), /wall/<username>, /b/<username>/<badge>, /handout/<username>, /ledger, /tx/<hash>, /contract, /leaderboard, /whats-new, /blog, /plays, /wallets (members), /launch (members), /partners, /earning, /shorts, /terms, /privacy, /disclaimer, /from/faucetwave, /from/tieroneads and /from/socialpix.
|
||||
|
||||
RULES:
|
||||
- 1 to 4 sentences, plain text, no markdown, include full URLs when pointing at a page, and only URLs from the PAGES list above.
|
||||
- Never send someone to a warning, notice, guide, document or page section that is not named above. Saying "read the full warning on your training page" invents something that does not exist and the member will go looking for it. If the answer is not on a page in the PAGES list, give the answer here or say you are not sure and point to /contract, the ledger, or their sponsor.
|
||||
- Plain ASCII only: a normal hyphen, never a non-breaking hyphen, and no smart quotes.
|
||||
- NEVER promise or estimate income. This is an advertising service with a referral program, never an investment. Be honest about risk: crypto transactions are irreversible, nobody earns unless real ad purchases happen.
|
||||
- No em dashes. If you do not know, say so and point to /contract or the ledger.`;
|
||||
- No em dashes. If you do not know, say so and point to /contract or the ledger.
|
||||
- Anything about one person's own account (a missing payout, a sign-in that will not work, a charge, a bug) you cannot look up: say so and point them to Help at https://instantadpay.com/my#help, or https://instantadpay.com/support when signed out.`;
|
||||
}
|
||||
|
||||
function askAI(message, historyText) {
|
||||
@@ -254,22 +259,24 @@ function askAI(message, historyText) {
|
||||
});
|
||||
}
|
||||
|
||||
const UNSURE_RE = /(not sure|do not know|don't know|cannot help|can't help|unable to help|no way for me|i (can|could) not (see|check|look)|contact support|reach support|support (ticket|desk)|\/support\b|my#help)/i;
|
||||
async function answer(message, historyText) {
|
||||
const msg = String(message || '').trim();
|
||||
if (!msg) return { error: 'Say something first.' };
|
||||
for (const c of CANNED) if (c.re.test(msg)) return { reply: c.a, canned: true };
|
||||
if (!enabled()) return { reply: 'Good question. The quick answers I have cover packages, payouts, qualification, and joining; for anything deeper, the plain-language contract review at https://instantadpay.com/contract covers most of it.' };
|
||||
for (const c of CANNED) if (c.re.test(msg)) return Object.assign({ reply: c.a, canned: true }, c.handoff ? { handoff: true } : {});
|
||||
if (!enabled()) return { reply: 'Good question. The quick answers I have cover packages, payouts, qualification, and joining; for anything deeper, the plain-language contract review at https://instantadpay.com/contract covers most of it, or tap "Send this to support" and Marty will answer.', handoff: true };
|
||||
// One retry: the usual failure is a single provider dropping the request, and asking
|
||||
// again almost always lands. Only after both fail do we admit defeat.
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
try { return { reply: await askAI(msg, historyText) }; }
|
||||
// handoff: the answer admits it cannot help, so the widget offers "Send this to support" (help desk, 2026-10-16)
|
||||
try { const reply = await askAI(msg, historyText); return Object.assign({ reply }, UNSURE_RE.test(reply) ? { handoff: true } : {}); }
|
||||
catch (e) {
|
||||
console.error('chat AI failed (attempt ' + (attempt + 1) + ')', e.message);
|
||||
if (attempt === 0) await new Promise(r => setTimeout(r, 700));
|
||||
}
|
||||
}
|
||||
// Never a dead end: say plainly that it was us, and offer a person.
|
||||
return { reply: 'That one did not come back to me just now, and that is our side, not your question. Ask me again in a moment and it should go through. If it is urgent, the plain-language contract review at https://instantadpay.com/contract and the live ledger at https://instantadpay.com/ledger cover most of the deep questions, and your sponsor can be reached from Members > My line.' };
|
||||
return { reply: 'That one did not come back to me just now, and that is our side, not your question. Ask me again in a moment and it should go through. If it is urgent, tap "Send this to support" and Marty will answer, or reach your sponsor from Members > My line.', handoff: true };
|
||||
}
|
||||
|
||||
module.exports = { init, answer, enabled, KNOWLEDGE_DATE };
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ async function renderPage() {
|
||||
const w = winners();
|
||||
if (w.length) h += '<h2 style="font-size:24px;margin:0 0 10px">Past winners</h2>' + w.slice(0, 12).map(x => '<div class="win"><b>' + (x.kind === 'week' ? 'Week of ' : 'Month of ') + fmtD(x.start) + '</b>: ' + (x.top[0] ? esc(x.top[0].name) + ' (' + x.top[0].sales + ' sold, $' + x.top[0].usd + ')' : 'no sales') + (x.granted && x.granted.length ? ' · awarded: ' + x.granted.map(g => esc(g.name) + ' +' + g.credits.toLocaleString()).join(', ') : (x.prize ? ' · prize ' + esc(x.prize) : '')) + '</div>').join('');
|
||||
h += '<p class="muted small" style="margin-top:30px">Sales are $ of packages bought by members you directly sponsor. Prizes are advertising credits or packages, never cash. No income is guaranteed.</p>';
|
||||
h += '</div><script src="/assets/common.js?v=20261015a"></script><script src="/assets/blog-page.js?v=20260914a"></script></body></html>';
|
||||
h += '</div><script src="/assets/common.js?v=20261016a"></script><script src="/assets/blog-page.js?v=20260914a"></script></body></html>';
|
||||
return h;
|
||||
}
|
||||
module.exports = { init, view, compute, renderPage, rolloverTick, winners, periodBounds };
|
||||
|
||||
+25
-2
@@ -96,6 +96,7 @@
|
||||
<button data-pane="house" type="button"><svg viewBox="0 0 24 24"><path d="M3 11l14-5v12L3 13v-2z"/><path d="M17 8a4 4 0 0 1 0 8M7 13v5a2 2 0 0 0 4 0v-3"/></svg>House ads</button>
|
||||
<button data-pane="campaigns" type="button"><svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h10"/></svg>All campaigns</button>
|
||||
<button data-pane="members" type="button"><svg viewBox="0 0 24 24"><circle cx="12" cy="7" r="3.2"/><circle cx="5" cy="17" r="2.6"/><circle cx="19" cy="17" r="2.6"/><path d="M12 10v3M12 13l-5 2M12 13l5 2"/></svg>Members</button>
|
||||
<button data-pane="support" type="button"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"/><path d="M9.6 9.4a2.5 2.5 0 0 1 4.8.9c0 1.7-2.4 2.1-2.4 3.7"/><path d="M12 17v.5"/></svg>Support<span class="pill" id="supBadge" hidden></span></button>
|
||||
<button data-pane="reports" type="button"><svg viewBox="0 0 24 24"><path d="M12 3l9 16H3z"/><path d="M12 10v4M12 17v.5"/></svg>Reports<span class="pill" id="repBadge" hidden></span></button>
|
||||
<button data-pane="traffic" type="button"><svg viewBox="0 0 24 24"><path d="M3 17l6-6 4 4 8-8"/><path d="M14 7h7v7"/></svg>Traffic</button>
|
||||
<button data-pane="blog" type="button"><svg viewBox="0 0 24 24"><path d="M4 4h12l4 4v12H4z"/><path d="M8 12h8M8 16h8M8 8h4"/></svg>Blog</button>
|
||||
@@ -272,6 +273,28 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-support" hidden>
|
||||
<div id="spList">
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Support desk</h3><span class="sub" id="spSub">tickets from Help, /support and the chatbot</span></div>
|
||||
<div class="chips" id="spStatus" style="margin-top:4px"></div>
|
||||
<p style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin:10px 0">
|
||||
<select id="spPlatform" class="small"><option value="">All platforms</option><option value="iap">InstantAdPay</option><option value="linkspin">LinkSpin</option></select>
|
||||
<select id="spCategory" class="small"></select>
|
||||
<input id="spQ" class="small" placeholder="Search ref, email, name, subject" style="flex:1;min-width:200px">
|
||||
</p>
|
||||
<div class="tablewrap"><table class="adm-table" id="spTable"></table></div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Saved replies</h3><span class="sub">insert them from any ticket's reply box</span></div>
|
||||
<div id="spTpls"></div>
|
||||
<p style="display:flex;gap:10px;flex-wrap:wrap;margin:10px 0 0"><button type="button" class="btn small sec" id="spTplAdd">+ Add a saved reply</button><button type="button" class="btn small" id="spTplSave">Save saved replies</button></p>
|
||||
</div>
|
||||
<p class="small muted">New tickets and member replies ping your private Telegram chat (site setting supportTelegramChat) and email ADMIN_EMAIL, at most one ping per ticket every 10 minutes. Your replies email the requester and, for members, land in their Help tab as a quiet inbox notice.</p>
|
||||
</div>
|
||||
<div id="spView" hidden></div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-reports" hidden>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Counters audit</h3><span class="sub" id="audSub">views vs delivery logs, charges vs shows</span></div>
|
||||
@@ -541,7 +564,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/admin.js?v=20261016gp"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/admin.js?v=20261016sp"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+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')]);
|
||||
|
||||
+62
-1
@@ -1,4 +1,6 @@
|
||||
// 24/7 assistant widget: floating bubble, slide-up panel, /api/chat.
|
||||
// Hand-off (help desk, 2026-10-16): when the answer cannot help, or they ask for a person, the widget offers
|
||||
// "Send this to support", which files the last few turns as a ticket (members: their Help pane; signed out: their email).
|
||||
(function () {
|
||||
const root = document.createElement('div');
|
||||
root.id = 'iapChat';
|
||||
@@ -11,6 +13,7 @@
|
||||
+ '</div>'
|
||||
+ '<div class="ch-input"><input id="iapChatIn" placeholder="Type your question…" maxlength="600">'
|
||||
+ '<button id="iapChatSend" type="button">Send</button></div>'
|
||||
+ '<div style="text-align:center;font-size:12px;padding:4px 0 8px"><a href="#" id="iapChatHuman" style="color:inherit;opacity:.75">Need a person? Send this to support</a></div>'
|
||||
+ '</div>';
|
||||
document.body.appendChild(root);
|
||||
|
||||
@@ -18,6 +21,7 @@
|
||||
const msgs = $('iapChatMsgs');
|
||||
const input = $('iapChatIn');
|
||||
let history = [];
|
||||
const turns = []; // { who: 'me' | 'bot', text } for the support hand-off
|
||||
|
||||
const add = (text, who) => {
|
||||
const d = document.createElement('div');
|
||||
@@ -29,11 +33,18 @@
|
||||
msgs.scrollTop = msgs.scrollHeight;
|
||||
return d;
|
||||
};
|
||||
function offerHandoff() {
|
||||
if (msgs.querySelector('.ch-handoff')) return;
|
||||
const d = document.createElement('div'); d.className = 'ch-m bot ch-handoff';
|
||||
d.innerHTML = '<button type="button" class="btn small" style="margin:0">Send this to support</button>';
|
||||
d.querySelector('button').addEventListener('click', handoff);
|
||||
msgs.appendChild(d); msgs.scrollTop = msgs.scrollHeight;
|
||||
}
|
||||
async function send() {
|
||||
const q = input.value.trim();
|
||||
if (!q) return;
|
||||
input.value = '';
|
||||
add(q, 'me');
|
||||
add(q, 'me'); turns.push({ who: 'me', text: q });
|
||||
const wait = add('…', 'bot');
|
||||
try {
|
||||
const r = await (await fetch('/api/chat', { method: 'POST',
|
||||
@@ -41,12 +52,61 @@
|
||||
body: JSON.stringify({ message: q, history: history.slice(-4).join(' | ') }) })).json();
|
||||
wait.remove();
|
||||
add(r.reply || r.error || 'No answer came back. Try again.', 'bot');
|
||||
if (r.reply) turns.push({ who: 'bot', text: r.reply });
|
||||
history.push('Q: ' + q, 'A: ' + (r.reply || ''));
|
||||
if (r.handoff) offerHandoff();
|
||||
} catch (e) {
|
||||
wait.remove();
|
||||
add('Connection hiccup. Try that again.', 'bot');
|
||||
offerHandoff();
|
||||
}
|
||||
}
|
||||
async function post(body) {
|
||||
const g = window.IAP && IAP.guard;
|
||||
if (g) await g.formSettled();
|
||||
return (await fetch('/api/support/chatbot', { method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(Object.assign({ transcript: turns.slice(-8), fts: g ? g.FORM_TS : 0, fage: g ? Date.now() - g.FORM_TS : 0 }, body)) })).json();
|
||||
}
|
||||
function done(r) {
|
||||
const old = msgs.querySelector('.ch-handoff'); if (old) old.remove();
|
||||
const f = msgs.querySelector('.ch-hform'); if (f) f.remove();
|
||||
add(r.member ? 'Sent to support as ticket ' + r.ref + '. Marty will reply in Help in your dashboard and by email: ' + location.origin + r.link
|
||||
: 'Sent to support as ticket ' + r.ref + '. We emailed you a private link to follow it, and Marty will reply there: ' + location.origin + r.link, 'bot');
|
||||
}
|
||||
async function handoff(e) {
|
||||
if (e && e.preventDefault) e.preventDefault();
|
||||
if (msgs.querySelector('.ch-hform')) return;
|
||||
let me = null; try { me = await (await fetch('/api/me')).json(); } catch (err) {}
|
||||
if (me && me.signedIn && me.email) {
|
||||
const ok = window.IAP && IAP.confirmBox ? await IAP.confirmBox('Send this chat to support as a ticket? Marty will reply in Help in your dashboard and by email.', { ok: 'Send it', cancel: 'Not now' }) : true;
|
||||
if (!ok) return;
|
||||
try { const r = await post({}); if (r.error) throw new Error(r.error); done(r); } catch (err) { add(err.message || 'Could not send it. Try the Help tab in your dashboard.', 'bot'); }
|
||||
return;
|
||||
}
|
||||
// signed out: an email so Marty can reply, plus the same invisible walls as sign-up
|
||||
const d = document.createElement('div'); d.className = 'ch-m bot ch-hform';
|
||||
d.innerHTML = 'Where should Marty reply?'
|
||||
+ '<input class="hp-field" type="text" tabindex="-1" aria-hidden="true" autocomplete="off" id="iapChatHp">'
|
||||
+ '<input id="iapChatEmail" type="email" placeholder="your email" maxlength="190" autocomplete="email" style="width:100%;margin-top:6px;box-sizing:border-box">'
|
||||
+ '<input id="iapChatNote" placeholder="anything to add (optional)" maxlength="600" style="width:100%;margin-top:6px;box-sizing:border-box">'
|
||||
+ '<div id="iapChatCheck" hidden style="margin-top:6px"></div>'
|
||||
+ '<button type="button" class="btn small" id="iapChatGo" style="margin-top:8px">Send to support</button> <span class="small" id="iapChatErr"></span>';
|
||||
msgs.appendChild(d); msgs.scrollTop = msgs.scrollHeight;
|
||||
$('iapChatEmail').focus();
|
||||
$('iapChatGo').addEventListener('click', async () => {
|
||||
const btn = $('iapChatGo'); if (btn.disabled) return; btn.disabled = true; $('iapChatErr').textContent = '';
|
||||
try {
|
||||
let pick = null, r = null;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
r = await post({ email: $('iapChatEmail').value.trim(), note: $('iapChatNote').value.trim(), hp_field_x9: window.IAP && IAP.guard ? IAP.guard.hpValue($('iapChatHp')) : '', pick });
|
||||
if (r.challenge && window.IAP && IAP.guard) { pick = await IAP.guard.iconCheck($('iapChatCheck'), r.challenge, r.error); continue; }
|
||||
break;
|
||||
}
|
||||
if (!r || r.error) throw new Error((r && r.error) || 'Could not send it.');
|
||||
done(r);
|
||||
} catch (err) { $('iapChatErr').textContent = err.message; btn.disabled = false; }
|
||||
});
|
||||
}
|
||||
$('iapChatBtn').addEventListener('click', () => {
|
||||
const p = $('iapChatPanel');
|
||||
p.hidden = !p.hidden;
|
||||
@@ -54,5 +114,6 @@
|
||||
});
|
||||
$('iapChatClose').addEventListener('click', () => { $('iapChatPanel').hidden = true; });
|
||||
$('iapChatSend').addEventListener('click', send);
|
||||
$('iapChatHuman').addEventListener('click', handoff);
|
||||
input.addEventListener('keydown', e => { if (e.key === 'Enter') send(); });
|
||||
})();
|
||||
|
||||
@@ -56,7 +56,7 @@ window.IAP = (function () {
|
||||
f.innerHTML = '<div>© ' + new Date().getFullYear() + ' InstantAdPay</div>'
|
||||
+ '<div style="margin-top:8px;display:flex;gap:16px;justify-content:center;flex-wrap:wrap">'
|
||||
+ '<a href="/">How it works</a><a href="/presentation">Presentation</a><a href="/ledger">Live ledger</a><a href="/contract">The contract</a><a href="/blog">Blog</a><a href="/leaderboard">Leaderboard</a><a href="/whats-new">What\'s new</a>'
|
||||
+ '<a href="/facts">Platform facts</a><a href="/terms">Terms</a><a href="/privacy">Privacy</a><a href="/disclaimer">Disclaimer</a></div>';
|
||||
+ '<a href="/facts">Platform facts</a><a href="/support">Support</a><a href="/terms">Terms</a><a href="/privacy">Privacy</a><a href="/disclaimer">Disclaimer</a></div>';
|
||||
document.body.appendChild(f);
|
||||
}
|
||||
async function refreshNavWallet() {
|
||||
@@ -263,7 +263,8 @@ window.IAP = (function () {
|
||||
}
|
||||
function ask(o) { return dialog(Object.assign({ type: 'text', value: '', placeholder: '' }, o || {})); }
|
||||
function confirmBox(text, o) { return dialog(Object.assign({ type: 'none', text, ok: 'Yes', cancel: 'No' }, o || {})); }
|
||||
return { getConfig, fmtPol, fmtUsd, status, renderNav, refreshNavWallet, describeEvent, feedRow, adSlot, reportAd, requestCode, launchChecks, launchToggle, ask, confirmBox, $ };
|
||||
return { getConfig, fmtPol, fmtUsd, status, renderNav, refreshNavWallet, describeEvent, feedRow, adSlot, reportAd, requestCode, launchChecks, launchToggle, ask, confirmBox, $,
|
||||
guard: { FORM_TS, iconCheck, hpValue, formSettled } }; // guard: the sign-up walls, reused by the support form and the chatbot hand-off
|
||||
})();
|
||||
// shown inside someone else's frame (traffic exchanges, 2026-10-03): sign-in, join and off-site links open in a new tab,
|
||||
// because browsers refuse our session cookie inside another site's frame
|
||||
|
||||
+6
-3
@@ -783,9 +783,9 @@
|
||||
}
|
||||
|
||||
// ── back-office menu: hash-routed panes ───────────────
|
||||
const PANES = ['overview', 'line', 'pipeline', 'buy', 'campaigns', 'earn', 'earnings', 'promo', 'training', 'games', 'wallet', 'profile'];
|
||||
const PANES = ['overview', 'line', 'pipeline', 'buy', 'campaigns', 'earn', 'earnings', 'promo', 'training', 'help', 'games', 'wallet', 'profile'];
|
||||
const TITLES = { overview: 'Overview', line: 'My line', pipeline: 'Pipeline', buy: 'Buy packages', campaigns: 'Campaigns',
|
||||
earn: 'Earn credits', earnings: 'Earnings', promo: 'Promo tools', training: 'Training', games: 'Games',
|
||||
earn: 'Earn credits', earnings: 'Earnings', promo: 'Promo tools', training: 'Training', help: 'Help and support', games: 'Games',
|
||||
wallet: 'Wallet & account', profile: 'Profile' };
|
||||
function setPane(name) {
|
||||
const paneQ = String(name || '').split('?')[1] || ''; name = String(name || '').split('?')[0]; // /my#games?pass=1 opens the Game Pass card (deep link from the games)
|
||||
@@ -808,8 +808,10 @@
|
||||
if (name === 'training') { if (/(^|&)g=leader/.test(paneQ)) loadTraining.filter = 'Leader tools'; loadTraining(); }
|
||||
if (name === 'pipeline') loadPipeline();
|
||||
if (name === 'games') loadGames(paneQ);
|
||||
if (name === 'help' && window.IAPSupport) IAPSupport.help(paneQ); // help desk tickets (2026-10-16)
|
||||
document.getElementById('memberArea').classList.remove('side-open'); // close mobile drawer
|
||||
if (location.hash !== '#' + name) history.replaceState(null, '', '#' + name);
|
||||
const keepQ = name === 'help' && paneQ ? '?' + paneQ : ''; // Help keeps ?t=<ref> so a reload reopens the ticket
|
||||
if (location.hash !== '#' + name + keepQ) history.replaceState(null, '', '#' + name + keepQ);
|
||||
}
|
||||
document.querySelectorAll('.bo-menu [data-pane]').forEach(b =>
|
||||
b.addEventListener('click', () => setPane(b.dataset.pane)));
|
||||
@@ -877,6 +879,7 @@
|
||||
$('earnGate').hidden = !!me.memberId;
|
||||
if (me.username && !me.address) { let shown = ''; try { shown = sessionStorage.getItem('iap.gs.walletHint'); sessionStorage.setItem('iap.gs.walletHint', '1'); } catch (e) {} if (shown !== '1') setTimeout(() => IAP.status('Next step when you are ready: link your wallet so your payouts have somewhere to land. The Getting started card at the top shows how.', 'ok'), 1200); }
|
||||
loadDashboard();
|
||||
if (window.IAPSupport) IAPSupport.badge(); // Help badge: Marty replied to a ticket
|
||||
|
||||
const who = [];
|
||||
if (me.email) who.push(me.email);
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
// Help desk front end (2026-10-16): the public /support form, the private ticket link page (/support/t/<token>)
|
||||
// and the member Help pane (/my#help). Server side: tickets.js + the /api/support, /api/my/support routes.
|
||||
// Times show in US Central, like the rest of the site's support copy.
|
||||
window.IAPSupport = (function () {
|
||||
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[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 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>');
|
||||
async function call(path, body, method) {
|
||||
const o = { method: method || (body === undefined ? 'GET' : 'POST'), headers: {} };
|
||||
if (body !== undefined) { o.headers['Content-Type'] = 'application/json'; o.body = JSON.stringify(body); }
|
||||
const r = await (await fetch(path, o)).json();
|
||||
if (r.error && !r.challenge) { const e = new Error(r.error); e.data = r; throw e; }
|
||||
return r;
|
||||
}
|
||||
(function css() {
|
||||
if (document.getElementById('supCss')) return;
|
||||
const st = document.createElement('style'); st.id = 'supCss';
|
||||
st.textContent = '.sup-form label{display:block;font-size:13px;color:var(--muted);margin:12px 0 4px}.sup-form input,.sup-form select,.sup-form textarea{width:100%;box-sizing:border-box}'
|
||||
+ '.sup-row{display:flex;gap:10px;align-items:center;justify-content:space-between;padding:12px 4px;border-bottom:1px solid var(--line);cursor:pointer}.sup-row:last-child{border-bottom:0}.sup-row:hover{background:rgba(67,232,195,.04)}'
|
||||
+ '.sup-row .sr-main{min-width:0;flex:1}.sup-row .sr-sub{font-weight:700;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sup-row .sr-meta{font-size:12px;color:var(--muted)}'
|
||||
+ '.sup-st{font-size:11.5px;font-weight:700;border-radius:999px;padding:2px 10px;border:1px solid var(--line-strong);white-space:nowrap}.sup-st.open{color:var(--mint);border-color:rgba(67,232,195,.5)}.sup-st.waiting_on_member{color:#f2c94c;border-color:rgba(242,201,76,.5)}.sup-st.closed{color:var(--muted)}'
|
||||
+ '.sup-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--amber,#ffb238);margin-right:6px;vertical-align:1px}'
|
||||
+ '.sup-msg{border:1px solid var(--line);border-radius:12px;padding:12px 14px;margin:10px 0;background:rgba(4,8,7,.35)}.sup-msg.admin{border-color:rgba(67,232,195,.45);background:rgba(67,232,195,.06)}.sup-msg.system{opacity:.8}'
|
||||
+ '.sup-msg .sm-head{font-size:12px;color:var(--muted);margin:0 0 6px;display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap}.sup-msg .sm-body{white-space:pre-wrap;word-wrap:break-word;font-size:15px;line-height:1.5}'
|
||||
+ '.sup-att{display:flex;gap:8px;margin-top:8px;flex-wrap:wrap}.sup-att img{max-width:160px;max-height:120px;border-radius:8px;border:1px solid var(--line)}'
|
||||
+ '.sup-actions{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-top:12px}';
|
||||
document.head.appendChild(st);
|
||||
})();
|
||||
const catOptions = sel => CATS.map(c => '<option' + (c === sel ? ' selected' : '') + '>' + esc(c) + '</option>').join('');
|
||||
const AUTHOR = { member: 'You', admin: 'Marty, InstantAdPay support', system: 'InstantAdPay' };
|
||||
function threadHtml(v) {
|
||||
const t = v.ticket;
|
||||
return '<div class="card-head" style="flex-wrap:wrap;gap:8px"><h3 style="margin:0">' + esc(t.subject) + '</h3><span class="sup-st ' + esc(t.status) + '">' + esc(STATUS[t.status] || t.status) + '</span></div>'
|
||||
+ '<p class="small muted" style="margin:4px 0 6px">' + esc(t.ref) + ' · ' + esc(t.category) + ' · opened ' + esc(when(t.created)) + '</p>'
|
||||
+ 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>'
|
||||
+ ((m.attachments || []).length ? '<div class="sup-att">' + m.attachments.map(a => '<a href="' + esc(a) + '" target="_blank" rel="noopener"><img src="' + esc(a) + '" alt="attachment"></a>').join('') + '</div>' : '') + '</div>').join('')
|
||||
+ (t.status === 'closed' ? '<p class="small muted" style="margin:14px 0 0">This ticket is closed. Write below and it opens again.</p>' : '');
|
||||
}
|
||||
function replyBox(id, withAttach) {
|
||||
return '<div class="sup-form"><label for="' + id + 'Body">Your reply</label><textarea id="' + id + 'Body" rows="4" maxlength="5000" placeholder="Add more detail or answer Marty here"></textarea>'
|
||||
+ (withAttach ? attachRow(id) : '')
|
||||
+ '<div class="sup-actions"><button class="btn small" type="button" id="' + id + 'Send">Send reply</button><span class="small muted" id="' + id + 'Msg"></span></div></div>';
|
||||
}
|
||||
// up to 2 screenshots per message, through the member upload path (signed-in only)
|
||||
const attachRow = id => '<label for="' + id + 'File">Screenshots (optional, up to 2 images)</label><input type="file" id="' + id + 'File" accept="image/png,image/jpeg,image/webp,image/gif" multiple><div class="sup-att" id="' + id + 'Att"></div>';
|
||||
function wireAttach(id) {
|
||||
const list = []; const inp = document.getElementById(id + 'File'); if (!inp) return () => [];
|
||||
const draw = () => { document.getElementById(id + 'Att').innerHTML = list.map(u => '<img src="' + esc(u) + '" alt="screenshot">').join(''); };
|
||||
inp.addEventListener('change', async () => {
|
||||
for (const f of [...inp.files]) {
|
||||
if (list.length >= 2) { IAP.status('Two images per message at most.', 'bad'); break; }
|
||||
try { const r = await (await fetch('/api/my/upload', { method: 'POST', headers: { 'Content-Type': f.type }, body: f })).json(); if (r.error) throw new Error(r.error); if (r.type !== 'image') throw new Error('Images only, please.'); list.push(r.url); draw(); }
|
||||
catch (e) { IAP.status(e.message || 'Upload failed.', 'bad'); }
|
||||
}
|
||||
inp.value = '';
|
||||
});
|
||||
return () => list.slice(); // read at send time
|
||||
}
|
||||
|
||||
// ── member Help pane ──
|
||||
let helpState = { open: null };
|
||||
async function badge() {
|
||||
try { const r = await call('/api/my/support'); const b = document.getElementById('helpBadge'); if (b) { b.hidden = !r.unread; b.textContent = r.unread > 9 ? '9+' : r.unread; } return r; } catch (e) { return null; }
|
||||
}
|
||||
async function help(paneQ) {
|
||||
const host = document.getElementById('helpBody'); if (!host) return;
|
||||
const want = (/(?:^|&)t=((?:IAP|LS)-\d+)/.exec(paneQ || '') || [])[1];
|
||||
if (want) return openMine(want);
|
||||
helpState.open = null;
|
||||
host.innerHTML = '<div class="card"><p class="muted small">Loading your tickets…</p></div>';
|
||||
let r; try { r = await call('/api/my/support'); } catch (e) { host.innerHTML = '<div class="card"><p class="small">Could not load your tickets. ' + esc(e.message) + '</p></div>'; return; }
|
||||
const b = document.getElementById('helpBadge'); if (b) { b.hidden = !r.unread; b.textContent = r.unread > 9 ? '9+' : r.unread; }
|
||||
host.innerHTML = '<div class="card"><div class="card-head"><h3>Help and support</h3><button class="btn small" type="button" id="helpNewBtn">New ticket</button></div>'
|
||||
+ '<p class="muted small" style="margin:6px 0 0">Stuck on something? Send Marty a ticket. He reads every one and replies here, and you get an email when he does. The quickest answers to common questions are in Training and the chat bubble.</p></div>'
|
||||
+ '<div class="card" id="helpNew" hidden></div>'
|
||||
+ '<div class="card"><div class="card-head"><h3>Your tickets</h3><span class="sub">' + r.tickets.length + '</span></div>'
|
||||
+ (r.tickets.length ? r.tickets.map(t => '<div class="sup-row" data-ref="' + esc(t.ref) + '"><div class="sr-main"><div class="sr-sub">' + (t.unread ? '<span class="sup-dot" title="New reply"></span>' : '') + esc(t.subject) + '</div>'
|
||||
+ '<div class="sr-meta">' + esc(t.ref) + ' · ' + esc(t.category) + ' · updated ' + esc(when(t.updated)) + '</div></div><span class="sup-st ' + esc(t.status) + '">' + esc(STATUS[t.status] || t.status) + '</span></div>').join('')
|
||||
: '<p class="muted small" id="helpEmpty">No tickets yet. When you send one, it shows up here with Marty\'s replies.</p>') + '</div>';
|
||||
host.querySelectorAll('.sup-row').forEach(el => el.addEventListener('click', () => { history.replaceState(null, '', '#help?t=' + el.dataset.ref); openMine(el.dataset.ref); }));
|
||||
document.getElementById('helpNewBtn').addEventListener('click', () => newForm());
|
||||
if (/(?:^|&)new=1/.test(paneQ || '')) newForm();
|
||||
}
|
||||
function newForm() {
|
||||
const box = document.getElementById('helpNew'); if (!box) return;
|
||||
box.hidden = false;
|
||||
box.innerHTML = '<h3 style="margin:0 0 4px">New ticket</h3><div class="sup-form">'
|
||||
+ '<label for="hnCat">What is it about?</label><select id="hnCat">' + catOptions('') + '</select>'
|
||||
+ '<label for="hnSubject">Subject</label><input id="hnSubject" maxlength="140" placeholder="A few words, like: my payout did not arrive">'
|
||||
+ '<label for="hnBody">Message</label><textarea 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>'
|
||||
+ attachRow('hn')
|
||||
+ '<div class="sup-actions"><button class="btn small" type="button" id="hnSend">Send to support</button><button class="btn small sec" type="button" id="hnCancel">Cancel</button><span class="small muted" id="hnMsg"></span></div></div>';
|
||||
const atts = wireAttach('hn');
|
||||
document.getElementById('hnCancel').addEventListener('click', () => { box.hidden = true; box.innerHTML = ''; });
|
||||
const send = document.getElementById('hnSend');
|
||||
send.addEventListener('click', async () => {
|
||||
if (send.disabled) return; send.disabled = true;
|
||||
try {
|
||||
const r = await call('/api/my/support', { category: document.getElementById('hnCat').value, subject: document.getElementById('hnSubject').value, body: document.getElementById('hnBody').value, attachments: atts() });
|
||||
IAP.status('Sent. Your ticket is ' + r.ref + '. Marty will reply here and by email.', 'ok');
|
||||
history.replaceState(null, '', '#help?t=' + r.ref); openMine(r.ref);
|
||||
} catch (e) { document.getElementById('hnMsg').textContent = e.message; }
|
||||
finally { send.disabled = false; }
|
||||
});
|
||||
document.getElementById('hnSubject').focus();
|
||||
}
|
||||
async function openMine(ref) {
|
||||
const host = document.getElementById('helpBody'); if (!host) return;
|
||||
helpState.open = ref;
|
||||
host.innerHTML = '<div class="card"><p class="muted small">Loading…</p></div>';
|
||||
let v; try { v = await call('/api/my/support/' + encodeURIComponent(ref)); } catch (e) { host.innerHTML = '<div class="card"><p class="small">' + esc(e.message) + '</p><p><a href="#help" id="helpBack">Back to your tickets</a></p></div>'; wireBack(); return; }
|
||||
drawMine(v);
|
||||
badge();
|
||||
}
|
||||
const wireBack = () => { const a = document.getElementById('helpBack'); if (a) a.addEventListener('click', e => { e.preventDefault(); history.replaceState(null, '', '#help'); help(''); }); };
|
||||
function drawMine(v) {
|
||||
const host = document.getElementById('helpBody');
|
||||
host.innerHTML = '<p style="margin:0 0 10px"><a href="#help" id="helpBack">‹ All your tickets</a></p><div class="card">' + threadHtml(v) + '</div><div class="card">' + replyBox('hr', true) + '</div>';
|
||||
wireBack();
|
||||
const atts = wireAttach('hr');
|
||||
const btn = document.getElementById('hrSend');
|
||||
btn.addEventListener('click', async () => {
|
||||
if (btn.disabled) return; btn.disabled = true;
|
||||
try { const nv = await call('/api/my/support/' + encodeURIComponent(v.ticket.ref) + '/reply', { body: document.getElementById('hrBody').value, attachments: atts() }); drawMine(nv); IAP.status('Reply sent.', 'ok'); }
|
||||
catch (e) { document.getElementById('hrMsg').textContent = e.message; }
|
||||
finally { btn.disabled = false; }
|
||||
});
|
||||
}
|
||||
|
||||
// ── public /support page and the private ticket link ──
|
||||
async function page() {
|
||||
const host = document.getElementById('supMain'); if (!host) return;
|
||||
const m = /^\/support\/t\/([A-Za-z0-9_.-]{20,80})$/.exec(location.pathname);
|
||||
if (m) return tokenPage(host, m[1]);
|
||||
let me = null; try { me = await (await fetch('/api/me')).json(); } catch (e) {}
|
||||
const signedIn = !!(me && me.signedIn && me.email);
|
||||
host.innerHTML = (signedIn ? '<div class="card" style="border-color:rgba(67,232,195,.45)"><p class="small" style="margin:0">You are signed in as <b>' + esc(me.username ? '@' + me.username : me.email) + '</b>. Your tickets and Marty\'s replies live in <a href="/my#help">Help in your dashboard</a>, which is the easiest place to follow up. This form works too and files the ticket under your account.</p></div>' : '')
|
||||
+ '<div class="card"><form class="sup-form" 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 for="supName">Your name</label><input id="supName" maxlength="80" autocomplete="name">'
|
||||
+ '<label for="supEmail">Your email (replies go here)</label><input id="supEmail" type="email" maxlength="190" autocomplete="email" required>')
|
||||
+ '<label for="supCat">What is it about?</label><select id="supCat">' + catOptions('') + '</select>'
|
||||
+ '<label for="supSubject">Subject</label><input id="supSubject" maxlength="140" placeholder="A few words, like: my sign-in code does not arrive">'
|
||||
+ '<label for="supBody">Message</label><textarea 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>'
|
||||
+ '<div id="supCheck" hidden style="margin-top:12px"></div>'
|
||||
+ '<div class="sup-actions"><button class="btn" type="submit" id="supSend">Send to support</button><span class="small muted" id="supMsg"></span></div>'
|
||||
+ '</form></div>';
|
||||
const f = document.getElementById('supForm');
|
||||
f.addEventListener('submit', async e => {
|
||||
e.preventDefault();
|
||||
const btn = document.getElementById('supSend'); if (btn.disabled) return; btn.disabled = true;
|
||||
const msg = document.getElementById('supMsg'); msg.textContent = 'Sending…';
|
||||
const val = id => { const el = document.getElementById(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, fage: Date.now() - g.FORM_TS, hp_field_x9: g.hpValue(document.getElementById('supHp')), pick });
|
||||
if (r.challenge) { msg.textContent = ''; pick = await g.iconCheck(document.getElementById('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 = '<div class="card"><h3 style="margin:0 0 6px">Got it. Your ticket is ' + esc(r.ref) + '.</h3>'
|
||||
+ '<p class="muted small">Marty reads every ticket and replies as soon as he can. ' + (r.member ? 'His reply shows up in Help in your dashboard 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.') + '</p>'
|
||||
+ '<p class="sup-actions">' + (r.member ? '<a class="btn small" href="/my#help?t=' + esc(r.ref) + '">Open it in Help</a>' : '<a class="btn small" href="/support/t/' + esc(r.token) + '">View your ticket</a>') + '<a class="btn small sec" href="/">Back to InstantAdPay</a></p></div>';
|
||||
window.scrollTo(0, 0);
|
||||
} catch (err) { msg.textContent = err.message; }
|
||||
finally { btn.disabled = false; }
|
||||
});
|
||||
}
|
||||
async function tokenPage(host, tok) {
|
||||
const h = document.querySelector('.sectionhead h2'); if (h) h.innerHTML = 'Your support <em>ticket</em>';
|
||||
host.innerHTML = '<div class="card"><p class="muted small">Loading your ticket…</p></div>';
|
||||
let v; try { v = await call('/api/support/t/' + encodeURIComponent(tok)); } catch (e) { host.innerHTML = '<div class="card"><p>' + esc(e.message) + '</p><p><a class="btn small" href="/support">Send a new ticket</a></p></div>'; return; }
|
||||
const draw = v2 => {
|
||||
host.innerHTML = '<div class="card">' + threadHtml(v2) + '</div><div class="card">' + replyBox('tk', false)
|
||||
+ '<p class="small muted" style="margin:10px 0 0">Keep this link private: anyone with it can read and answer this ticket. Members can also follow up from <a href="/my#help">Help in the dashboard</a>, where screenshots can be attached.</p></div>';
|
||||
const btn = document.getElementById('tkSend');
|
||||
btn.addEventListener('click', async () => {
|
||||
if (btn.disabled) return; btn.disabled = true;
|
||||
try { const nv = await call('/api/support/t/' + encodeURIComponent(tok) + '/reply', { body: document.getElementById('tkBody').value }); draw(nv); IAP.status('Reply sent. Marty will see it.', 'ok'); }
|
||||
catch (e) { document.getElementById('tkMsg').textContent = e.message; }
|
||||
finally { btn.disabled = false; }
|
||||
});
|
||||
};
|
||||
draw(v);
|
||||
}
|
||||
return { help, badge, page, CATS, STATUS, when, esc, linkify };
|
||||
})();
|
||||
if (document.getElementById('supMain')) IAPSupport.page();
|
||||
@@ -142,8 +142,8 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/contract.js?v=20260908p"></script>
|
||||
<script src="/assets/chat.js?v=20260906m"></script>
|
||||
<script src="/assets/chat.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<p class="muted small">You decide whether, and how much, to spend. Never spend more than you can afford to lose.</p>
|
||||
</div>
|
||||
</div></section>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/legal.js?v=20260908a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -84,6 +84,6 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div></section>
|
||||
<script src="/assets/common.js?v=20261015a"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script>
|
||||
<script src="/assets/legal.js?v=20260908a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -71,6 +71,6 @@
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/friday.js?v=20260925a"></script>
|
||||
<script src="/assets/common.js?v=20261015a"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -78,6 +78,6 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/games-page.js?v=20261012b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/games-page.js?v=20261012b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+3
-3
@@ -492,7 +492,7 @@
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div>InstantAdPay · every payment verifiable on-chain · <a href="/ledger">live ledger</a> · <a id="contractLink" href="#" target="_blank" rel="noopener">view the contract ↗</a></div>
|
||||
<div>InstantAdPay · every payment verifiable on-chain · <a href="/ledger">live ledger</a> · <a id="contractLink" href="#" target="_blank" rel="noopener">view the contract ↗</a> · <a href="/support">support</a></div>
|
||||
<div class="small">InstantAdPay is the Polygon hub of the <a href="https://cryptoteambuild.com" target="_blank" rel="noopener">Crypto Team Build Network</a>.</div>
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
|
||||
<div class="ghost" aria-hidden="true">InstantAdPay</div>
|
||||
@@ -500,9 +500,9 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallet.js?v=20260909c"></script>
|
||||
<script src="/assets/home.js?v=20261016p"></script>
|
||||
<script src="/assets/chat.js?v=20260906m"></script>
|
||||
<script src="/assets/chat.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@
|
||||
InstantAdPay · <a href="/contract">Contract</a> · <a href="/terms">Terms</a> · <a href="/privacy">Privacy</a> · <a href="/disclaimer">Disclaimer</a>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/join.js?v=20261016p"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/launch.js?v=20260915b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -40,9 +40,9 @@
|
||||
<div class="small">InstantAdPay is the Polygon hub of the <a href="https://cryptoteambuild.com" target="_blank" rel="noopener">Crypto Team Build Network</a>.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/ledger.js?v=20260906m"></script>
|
||||
<script src="https://polhunter.com/embed.js" data-slots="1" async></script>
|
||||
<script src="/assets/chat.js?v=20260906m"></script>
|
||||
<script src="/assets/chat.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+11
-3
@@ -143,6 +143,7 @@
|
||||
<button data-pane="earnings" type="button"><svg viewBox="0 0 24 24"><path d="M4 17l5-5 4 3 7-8"/><path d="M14 7h6v6"/></svg>Earnings</button>
|
||||
<button data-pane="promo" type="button"><svg viewBox="0 0 24 24"><path d="M7 10s5-1 9-5v14c-4-4-9-5-9-5H5a2 2 0 0 1-2-2v0a2 2 0 0 1 2-2h2z"/><path d="M8 15l1 5h2l-1-5"/></svg>Promo tools</button>
|
||||
<button data-pane="training" type="button"><svg viewBox="0 0 24 24"><path d="M3 5l9-2 9 2v11l-9 2-9-2z"/><path d="M12 3v13"/><path d="M9 11l3 2 3-2"/></svg>Training</button>
|
||||
<button data-pane="help" type="button"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"/><path d="M9.6 9.4a2.5 2.5 0 0 1 4.8.9c0 1.7-2.4 2.1-2.4 3.7"/><path d="M12 17v.5"/></svg>Help<span class="pill" id="helpBadge" hidden></span></button>
|
||||
<button data-pane="games" id="gamesNav" type="button" hidden><svg viewBox="0 0 24 24"><rect x="2.5" y="7" width="19" height="11" rx="5.5"/><path d="M7 11v3M5.5 12.5h3"/><circle cx="15.5" cy="11.5" r="1.1"/><circle cx="18" cy="13.5" r="1.1"/></svg>Games</button>
|
||||
<button data-pane="wallet" type="button"><svg viewBox="0 0 24 24"><rect x="3" y="6" width="18" height="13" rx="2"/><path d="M3 10h18"/><circle cx="16.5" cy="14.5" r="1.4"/></svg>Wallet</button>
|
||||
<button data-pane="profile" type="button"><svg viewBox="0 0 24 24"><circle cx="12" cy="8.5" r="3.6"/><path d="M4.5 20c1.6-3.6 4.2-5.2 7.5-5.2s5.9 1.6 7.5 5.2"/></svg>Profile</button>
|
||||
@@ -1072,6 +1073,11 @@
|
||||
<div class="card ad-foot" id="adSlotPane-training" hidden></div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-help" hidden>
|
||||
<div id="helpBody"><div class="card"><p class="muted small">Loading your tickets…</p></div></div>
|
||||
<div class="card ad-foot" id="adSlotPane-help" hidden></div>
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-games" hidden>
|
||||
<div class="card"><h3>Games</h3><p class="muted small">Games in the InstantAdPay network, the Polygon wing of the <a href="https://cryptoteambuild.com" target="_blank" rel="noopener">Crypto Team Build Network</a>. They pay in POL to the wallet on your InstantAdPay account, and one tap signs you in.</p></div>
|
||||
<div class="card" id="gpCard" hidden></div>
|
||||
@@ -1144,6 +1150,7 @@
|
||||
<a href="/">Ad packages</a>
|
||||
<a href="/ledger">Live ledger</a>
|
||||
<a href="/contract">The contract</a>
|
||||
<a href="#help">Support</a>
|
||||
<a href="https://cryptoteambuild.com" target="_blank" rel="noopener">Crypto Team Build Network</a>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -1168,10 +1175,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20261016p"></script>
|
||||
<script src="/assets/my.js?v=20261016q"></script>
|
||||
<script src="/assets/chat.js?v=20260907l"></script>
|
||||
<script src="/assets/support.js?v=20261016a"></script>
|
||||
<script src="/assets/my.js?v=20261016r"></script>
|
||||
<script src="/assets/chat.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford to lose.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/partners.js?v=20260914a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/plays.js?v=20260910b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -86,6 +86,6 @@
|
||||
<div class="small">InstantAdPay is the Polygon hub of the <a href="https://cryptoteambuild.com" target="_blank" rel="noopener">Crypto Team Build Network</a>.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/presentation.js?v=20261015b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/presentation.js?v=20261015b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -24,12 +24,12 @@
|
||||
<h3>Sharing</h3>
|
||||
<p class="muted small">Your username, public profile, and public wall are visible to others by design, and on-chain transactions are public by nature. We share data with infrastructure providers (hosting, email delivery) only as needed to operate the service, and when required by law.</p>
|
||||
<h3>Your choices</h3>
|
||||
<p class="muted small">You can edit your profile, adjust notification and chat settings, and request account deletion by contacting us. Note that on-chain records cannot be deleted by anyone.</p>
|
||||
<p class="muted small">You can edit your profile, adjust notification and chat settings, and request account deletion by contacting us through the <a href="/support">support page</a> or at <a href="mailto:support@instantadpay.com">support@instantadpay.com</a>. Note that on-chain records cannot be deleted by anyone.</p>
|
||||
<h3>Security</h3>
|
||||
<p class="muted small">We use reasonable safeguards, but no system is perfectly secure. Protect your email and your wallet.</p>
|
||||
</div>
|
||||
</div></section>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/legal.js?v=20260908a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Support | InstantAdPay</title>
|
||||
<meta name="description" content="Ask InstantAdPay for help: send a support ticket and get a reply by email. Members can also use Help in the dashboard.">
|
||||
<meta name="theme-color" content="#043b2f">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=20260910h">
|
||||
</head>
|
||||
<body>
|
||||
<section><div class="wrap" style="max-width:720px">
|
||||
<div class="sectionhead" style="text-align:left">
|
||||
<p class="eyebrow">Support</p>
|
||||
<h2>Ask for <em>help</em></h2>
|
||||
<p class="muted small">Tell us what is going on and Marty will reply by email. Members can also open <a href="/my#help">Help in the dashboard</a>, and you can email <a href="mailto:support@instantadpay.com">support@instantadpay.com</a>. Quick answers to common questions are in the chat bubble and on the <a href="/facts">platform facts</a> page.</p>
|
||||
</div>
|
||||
<div id="supMain"><div class="card"><p class="muted small">Loading…</p></div></div>
|
||||
<p class="small muted">We will never ask for your recovery phrase or private key, and nobody from InstantAdPay will message you first asking for money or wallet access.</p>
|
||||
</div></section>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/legal.js?v=20260908a"></script>
|
||||
<script src="/assets/support.js?v=20261016a"></script>
|
||||
<script src="/assets/chat.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
+2
-2
@@ -35,10 +35,10 @@
|
||||
<p class="muted small">To the fullest extent permitted by law, InstantAdPay and its operators are not liable for indirect, incidental, or consequential damages, or for losses arising from crypto volatility, irreversible transactions, third-party sites, or your own decisions.</p>
|
||||
<h3>10. Changes and termination</h3>
|
||||
<p class="muted small">We may update these Terms and the Platform, and continued use means you accept the changes. We may discontinue features. The immutable contract's rules cannot be changed by anyone, including us.</p>
|
||||
<p class="muted small" style="margin-top:18px">See also the <a href="/disclaimer">Disclaimer</a> and <a href="/privacy">Privacy Policy</a>.</p>
|
||||
<p class="muted small" style="margin-top:18px">See also the <a href="/disclaimer">Disclaimer</a> and <a href="/privacy">Privacy Policy</a>. Questions: the <a href="/support">support page</a> or <a href="mailto:support@instantadpay.com">support@instantadpay.com</a>.</p>
|
||||
</div>
|
||||
</div></section>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/legal.js?v=20260908a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
<p><a href="/ledger">← Back to the live ledger</a> · <a href="/contract">Read the contract review</a></p>
|
||||
</div>
|
||||
</section>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/tx.js?v=20260906m"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wall.js?v=20260911v"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@
|
||||
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never share your recovery phrase.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261015a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallets.js?v=20260911b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -64,6 +64,6 @@
|
||||
</footer>
|
||||
</div>
|
||||
<script src="/assets/wednesday.js?v=20260929c"></script>
|
||||
<script src="/assets/common.js?v=20261015a"></script>
|
||||
<script src="/assets/common.js?v=20261016a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+95
-3
@@ -61,7 +61,7 @@ if (MODE === 'public' || MODE === 'all') {
|
||||
const page = await ctx.newPage(); const bag = watch(page, LIVE);
|
||||
const PUBLIC = ['/', '/ledger', '/contract', '/terms', '/privacy', '/disclaimer', '/wall/martbost', '/join/martbost',
|
||||
'/join/martbost?v=instant', '/join/martbost?v=adspend', '/join/martbost?v=free', '/join/martbost?v=ledger', '/join/martbost?v=two',
|
||||
'/admin', '/my', '/shorts', '/presentation', '/presentation?ref=martbost', '/nope-404'];
|
||||
'/admin', '/my', '/shorts', '/presentation', '/presentation?ref=martbost', '/support', '/nope-404'];
|
||||
for (const p of PUBLIC) {
|
||||
const label = 'LIVE ' + p;
|
||||
try {
|
||||
@@ -101,7 +101,7 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
await page.waitForSelector('#mcVerifyBtn:not([hidden])'); await page.click('#mcVerifyBtn'); await page.waitForTimeout(2000);
|
||||
if (await page.$('#onboardModal:not([hidden])')) { await page.fill('#obUsername', 'qawalker'); await page.click('#obSave'); await page.waitForTimeout(1200); }
|
||||
await hide(page); flush(bag, L + 'sign-in');
|
||||
const PANES = ['overview', 'line', 'pipeline', 'buy', 'campaigns', 'earn', 'earnings', 'promo', 'training', 'games', 'wallet', 'profile'];
|
||||
const PANES = ['overview', 'line', 'pipeline', 'buy', 'campaigns', 'earn', 'earnings', 'promo', 'training', 'help', 'games', 'wallet', 'profile'];
|
||||
for (const pn of PANES) {
|
||||
const label = L + 'my#' + pn;
|
||||
await page.click('.bo-menu [data-pane="' + pn + '"]'); await page.waitForTimeout(1200); await hide(page);
|
||||
@@ -147,6 +147,29 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
const rj = await page.request.get(LOCAL + '/join/' + tok + '?ref=' + tok, { maxRedirects: 0 });
|
||||
if (rj.status() !== 200) note('bug', L + 'viral/join', '/join keeps its own ?ref handling, got ' + rj.status());
|
||||
console.log('ok viral links: builder + redirect + cookie');
|
||||
// help desk (2026-10-16): Help pane -> new ticket -> thread -> reply; the ref is reused by the admin Support walk below
|
||||
let helpRef = '';
|
||||
await page.click('.bo-menu [data-pane="help"]'); await page.waitForTimeout(800); await hide(page);
|
||||
await page.click('#helpNewBtn').catch(() => note('bug', L + 'my#help', 'no New ticket button'));
|
||||
await page.waitForTimeout(300);
|
||||
await page.click('#hnSend'); await page.waitForTimeout(600);
|
||||
if (!(await page.$eval('#hnMsg', e => e.textContent.trim()).catch(() => ''))) note('warn', L + 'my#help', 'empty ticket showed no validation message');
|
||||
await page.selectOption('#hnCat', 'Wallet & payouts').catch(() => {});
|
||||
await page.fill('#hnSubject', 'QA walk: payout question');
|
||||
await page.fill('#hnBody', 'This is the QA walk testing the help desk. Line two.\nhttps://instantadpay.com/ledger');
|
||||
await page.click('#hnSend'); await page.waitForTimeout(1500); await hide(page);
|
||||
helpRef = (/#help\?t=((?:IAP|LS)-\d+)/.exec(page.url()) || [])[1] || '';
|
||||
if (!helpRef || !(await page.$('#hrSend'))) note('bug', L + 'my#help', 'new ticket did not open its thread: ' + page.url());
|
||||
else {
|
||||
await page.fill('#hrBody', 'QA walk follow-up reply.'); await page.click('#hrSend'); await page.waitForTimeout(1200);
|
||||
const n = await page.$$eval('#helpBody .sup-msg', els => els.length).catch(() => 0);
|
||||
if (n < 2) note('bug', L + 'my#help', 'reply did not show in the thread (' + n + ' messages)');
|
||||
await page.click('#helpBack'); await page.waitForTimeout(900);
|
||||
if (!(await page.$('#helpBody .sup-row[data-ref="' + helpRef + '"]'))) note('bug', L + 'my#help', 'ticket missing from the list');
|
||||
await domChecks(page, L + 'my#help (ticket)'); console.log('ok Help pane ticket', helpRef);
|
||||
}
|
||||
flush(bag, L + 'my#help (ticket)');
|
||||
await page.screenshot({ path: OUT + '/my-help-ticket.png' }).catch(() => {});
|
||||
const chat = await page.$('#chatMenuBtn'); if (chat) { await chat.click(); await page.waitForTimeout(800); await domChecks(page, L + 'messages'); flush(bag, L + 'messages'); }
|
||||
const lo = await page.$('#logoutLink'); if (lo) { await lo.click(); await page.waitForTimeout(1000); }
|
||||
if (!(await page.$('#authArea:not([hidden])'))) note('bug', L + 'logout', 'auth card not shown after log out');
|
||||
@@ -154,7 +177,7 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
// admin
|
||||
await page.goto(LOCAL + '/admin', { waitUntil: 'networkidle' });
|
||||
await page.fill('#adEmail', process.env.ADMIN_EMAIL || 'martybostick@gmail.com'); await page.click('#adSend'); await page.waitForSelector('#adVerify:not([hidden])'); await page.click('#adVerify'); await page.waitForTimeout(1200);
|
||||
for (const pn of ['overview', 'house', 'campaigns', 'members', 'reports', 'traffic', 'blog', 'releases', 'pnl', 'gamepass', 'settings']) {
|
||||
for (const pn of ['overview', 'house', 'campaigns', 'members', 'support', 'reports', 'traffic', 'blog', 'releases', 'pnl', 'gamepass', 'settings']) {
|
||||
const label = L + 'admin#' + pn;
|
||||
await page.click('.bo-menu [data-pane="' + pn + '"]'); await page.waitForTimeout(1200);
|
||||
const vis = await page.evaluate(id => { const el = document.getElementById('pane-' + id); return el && !el.hidden && el.offsetHeight > 40; }, pn);
|
||||
@@ -163,11 +186,80 @@ if (MODE === 'member' || MODE === 'all') {
|
||||
await page.screenshot({ path: OUT + '/admin-' + pn + '.png' }).catch(() => {});
|
||||
console.log('ok', label);
|
||||
}
|
||||
// admin Support pane: the member's ticket is listed, opens, takes an internal note and a reply; the member then sees the reply and an unread badge
|
||||
if (helpRef) {
|
||||
await page.click('.bo-menu [data-pane="support"]'); await page.waitForTimeout(1000);
|
||||
if (!(await page.$('#spTable [data-spref="' + helpRef + '"]'))) note('bug', L + 'admin#support', 'ticket ' + helpRef + ' not in the open list');
|
||||
const badge = await page.$eval('#supBadge', e => e.hidden ? '' : e.textContent).catch(() => '');
|
||||
if (!badge) note('bug', L + 'admin#support', 'no open-count badge in the menu');
|
||||
await page.click('#spTable [data-spref="' + helpRef + '"]').catch(() => {}); await page.waitForTimeout(1000);
|
||||
if (!(await page.$('#spBody'))) note('bug', L + 'admin#support', 'ticket view did not open');
|
||||
else {
|
||||
if (!/member account/.test(await page.$eval('#spView', e => e.textContent))) note('bug', L + 'admin#support', 'requester not recognised as a member');
|
||||
await page.check('#spInternal'); await page.fill('#spBody', 'QA internal note, never shown to the member.'); await page.click('#spSend'); await page.waitForTimeout(1000);
|
||||
await page.selectOption('#spTpl', '0').catch(() => {}); await page.waitForTimeout(200);
|
||||
if (!(await page.$eval('#spBody', e => e.value).catch(() => ''))) note('bug', L + 'admin#support', 'saved reply did not insert');
|
||||
await page.click('#spSend'); await page.waitForTimeout(400);
|
||||
const ok = await page.$('#dlgOk'); if (ok) await ok.click(); else note('bug', L + 'admin#support', 'no in-page confirm before sending');
|
||||
await page.waitForTimeout(1200);
|
||||
const txt = await page.$eval('#spView', e => e.textContent).catch(() => '');
|
||||
if (!/internal note/.test(txt) || !/Waiting on member/.test(await page.$eval('#spSt', e => e.selectedOptions[0].textContent).catch(() => ''))) note('bug', L + 'admin#support', 'note/reply/status not reflected');
|
||||
await page.selectOption('#spPr', 'high'); await page.waitForTimeout(800);
|
||||
await domChecks(page, L + 'admin#support (ticket)'); console.log('ok admin Support ticket', helpRef);
|
||||
}
|
||||
flush(bag, L + 'admin#support (ticket)');
|
||||
await page.screenshot({ path: OUT + '/admin-support-ticket.png' }).catch(() => {});
|
||||
await page.goto(LOCAL + '/admin#support?t=' + helpRef, { waitUntil: 'networkidle' }); await page.waitForTimeout(1000);
|
||||
if (!(await page.$('#spBody'))) note('bug', L + 'admin#support', 'deep link #support?t=<ref> did not open the ticket');
|
||||
flush(bag, L + 'admin#support (deep link)');
|
||||
}
|
||||
await page.click('.bo-menu [data-pane="house"]'); await page.waitForTimeout(500);
|
||||
for (const t of ['banner', 'text', 'login', 'solo', 'video', 'featured', 'visits']) { await page.selectOption('#hType', t); await page.waitForTimeout(120); }
|
||||
await page.selectOption('#hType', 'text'); await page.click('#hCreate'); await page.waitForTimeout(800);
|
||||
if (!(await page.$('#hErr:not([hidden])'))) note('warn', L + 'admin house form', 'empty submit showed no validation message');
|
||||
flush(bag, L + 'admin house form');
|
||||
// member sees Marty's reply: badge, thread without the internal note
|
||||
if (helpRef) {
|
||||
await page.goto(LOCAL + '/my', { waitUntil: 'networkidle' });
|
||||
if (await page.$('#mcEmail:not([hidden])') && await page.$('#authArea:not([hidden])')) {
|
||||
await page.fill('#mcEmail', 'qa-walk@example.com'); await page.click('#mcSendBtn'); await page.waitForSelector('#mcVerifyBtn:not([hidden])'); await page.click('#mcVerifyBtn'); await page.waitForTimeout(2000);
|
||||
}
|
||||
await hide(page); await page.waitForTimeout(800);
|
||||
if (!(await page.$eval('#helpBadge', e => !e.hidden).catch(() => false))) note('bug', L + 'my#help', 'no unread badge after the admin replied');
|
||||
await page.waitForTimeout(1500); await page.goto(LOCAL + '/my#help?t=' + helpRef); await page.waitForTimeout(1500); // same document: the hash change opens the ticket await hide(page);
|
||||
const th = await page.$eval('#helpBody', e => e.textContent).catch(() => '');
|
||||
if (!/Marty, InstantAdPay support/.test(th)) note('bug', L + 'my#help', 'admin reply not shown to the member');
|
||||
if (/QA internal note/.test(th)) note('bug', L + 'my#help', 'INTERNAL NOTE LEAKED to the member');
|
||||
flush(bag, L + 'my#help (reply seen)'); console.log('ok member sees reply, no internal note');
|
||||
}
|
||||
// public /support (signed out): the form, the guard, the private ticket link
|
||||
{
|
||||
const pctx = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true });
|
||||
await pctx.addInitScript(() => { try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} });
|
||||
const pp = await pctx.newPage(); const pbag = watch(pp, LOCAL);
|
||||
await pp.goto(LOCAL + '/support', { waitUntil: 'networkidle' }); await pp.waitForTimeout(800);
|
||||
await domChecks(pp, L + '/support');
|
||||
if (!(await pp.$('#supForm'))) note('bug', L + '/support', 'form did not render');
|
||||
else {
|
||||
await pp.fill('#supName', 'QA Visitor'); await pp.fill('#supEmail', 'qa-visitor@example.com');
|
||||
await pp.fill('#supSubject', 'QA: cannot sign in'); await pp.fill('#supBody', 'The sign-in code never arrives. QA walk.');
|
||||
await pp.click('#supSend'); await pp.waitForTimeout(3500);
|
||||
const tl = await pp.$eval('#supMain a.btn[href^="/support/t/"]', e => e.getAttribute('href')).catch(() => '');
|
||||
if (!tl) note('bug', L + '/support', 'no confirmation with a private ticket link: ' + (await pp.$eval('#supMsg', e => e.textContent).catch(() => '')));
|
||||
else {
|
||||
await pp.goto(LOCAL + tl, { waitUntil: 'networkidle' }); await pp.waitForTimeout(800);
|
||||
if (!(await pp.$('#tkSend'))) note('bug', L + '/support/t', 'private ticket page did not render');
|
||||
else { await pp.fill('#tkBody', 'Adding one more detail.'); await pp.click('#tkSend'); await pp.waitForTimeout(1000); if ((await pp.$$('.sup-msg')).length < 2) note('bug', L + '/support/t', 'reply on the private link did not show'); }
|
||||
await domChecks(pp, L + '/support/t'); console.log('ok /support + private link');
|
||||
const bad = await pp.request.get(LOCAL + '/api/support/t/' + tl.split('/').pop().slice(0, -4) + 'AAAA');
|
||||
if (bad.status() !== 404) note('bug', L + '/support/t', 'a tampered token was accepted: ' + bad.status());
|
||||
}
|
||||
const bot = await pp.request.post(LOCAL + '/api/support', { data: { email: 'qa-bot@example.com', subject: 'x bot', body: 'bot body here', fts: Date.now(), fage: 10 } });
|
||||
if (bot.status() !== 400) note('bug', L + '/api/support', 'instant (form-age 10ms) post was not refused: ' + bot.status());
|
||||
}
|
||||
await pp.screenshot({ path: OUT + '/support-public.png' }).catch(() => {});
|
||||
flush(pbag, L + '/support'); await pctx.close();
|
||||
}
|
||||
await ctx.close();
|
||||
}
|
||||
await browser.close();
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ function renderPage() {
|
||||
h += '<h2 style="font-size:24px;margin:10px 0 16px">Release notes</h2>';
|
||||
h += v.notes.length ? v.notes.map(n => '<article class="note" id="' + esc(n.id) + '"><h2>' + esc(n.title) + n.tags.map(tagChip).join('') + '</h2><p class="when">' + fmt(n.date) + '</p>' + bodyHtml(n.body) + '</article>').join('') : '<p class="muted">No notes yet.</p>';
|
||||
h += '<p class="muted small" style="margin-top:30px">Suggestions and bug reports: the chat bubble on any page, or the InstantAdPay Telegram group.</p>';
|
||||
h += '</div><script src="/assets/common.js?v=20261015a"></script><script src="/assets/blog-page.js?v=20260914a"></script></body></html>';
|
||||
h += '</div><script src="/assets/common.js?v=20261016a"></script><script src="/assets/blog-page.js?v=20260914a"></script></body></html>';
|
||||
return h;
|
||||
}
|
||||
module.exports = { init, notes, roadmap, saveNote, saveRoadmap, remove, publicView, renderPage, bodyHtml, TAGS, STATUSES };
|
||||
|
||||
@@ -59,9 +59,10 @@ const fridaybank = require('./fridaybank'); // Friday Bonus Hunts: days banked S
|
||||
const refill = require('./refill');
|
||||
const pdsync = require('./pdsync'); // PassiveDrip PTC bridge: our visit campaigns on their paid-to-click page (2026-09-30) // campaign running-low / ran-out notices, and what came of them // Five Dollar Friday: +20% credits on Friday packs, the wave, the badge (Marty, 2026-09-20)
|
||||
const snapshot = require('./snapshot'); // daily growth snapshot -> Telegram payments feed (Marty, 2026-09-15)
|
||||
const tickets = require('./tickets'); // help desk: member Help pane, public /support, chatbot hand-off, admin Support pane (Marty, 2026-10-16)
|
||||
const pipeline = require('./pipeline'); // sponsor follow-up board (coming soon until site setting pipelineMode = on) (Marty, 2026-09-15)
|
||||
const videomaker = require('./videomaker'); // Circuit tool: promo videos with the member's own end card (ffmpeg in the image) // badge-gated promo toolkit + AI Copy Engine (Surge and up) (Marty, 2026-09-14) // referral contest: /leaderboard, Overview card, weekly + monthly winners (Marty, 2026-09-14) // release notes + roadmap: /whats-new, Overview card, Admin > Releases (Marty, 2026-09-14) // blog -> Blotato -> X + Instagram on publish (Marty, 2026-09-13) // admin member card: search, drilldown, edits (Marty, 2026-09-13) // admin-written coaching articles, server-rendered public /blog with SEO metadata (Marty, 2026-09-12)
|
||||
const TRAFFIC_PAGES = new Set(['/', '/ledger', '/contract', '/shorts', '/plays', '/wallets', '/launch', '/partners', '/earning', '/games', '/blog', '/whats-new', '/leaderboard', '/friday', '/wednesday', '/presentation']);
|
||||
const TRAFFIC_PAGES = new Set(['/', '/ledger', '/contract', '/shorts', '/plays', '/wallets', '/launch', '/partners', '/earning', '/games', '/blog', '/whats-new', '/leaderboard', '/friday', '/wednesday', '/presentation', '/support']);
|
||||
let tankWaitCache = null; // dashboard: who is waiting for a sponsor (refreshed every minute)
|
||||
const geo = require('./geo'); // viewer country -> tier (DB-IP lite), for campaign targeting
|
||||
const burner = require('./burner'); // automatic on-chain credit burns (inert without ENGINE_KEY)
|
||||
@@ -530,6 +531,7 @@ async function boot() {
|
||||
// follow-up email sequence: send whatever came due (every 10 min, first pass shortly after boot)
|
||||
coach.init({ dataDir: DATA_DIR, chain, accounts, mailer, ads, tank, lb: () => leaderboard, siteConfig });
|
||||
pipeline.init({ dataDir: DATA_DIR, accounts, coach, chain });
|
||||
tickets.init({ dataDir: DATA_DIR, mailer, messages, accounts, adminEmail: ADMIN_EMAIL, telegram: supportTelegram });
|
||||
badge.init({ publicDir: PUBLIC_DIR });
|
||||
gamestats.init({ dataDir: DATA_DIR });
|
||||
snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, publicDir: PUBLIC_DIR, games: gamestats, launchesToday: () => GAMES().filter(g => (g.soon && g.soon.opens === todayCT()) || (g.season && g.season.start === todayCT())).map(g => g.name),
|
||||
@@ -703,6 +705,8 @@ function siteConfig() {
|
||||
geoTier2: '', // empty = built-in default (rest of Western/Central Europe, JP, KR, SG, HK, TW, IL, Gulf, ZA, BR, MX, AR, CL, CO ...); tier 3 = everything else
|
||||
// Game Pass (2026-10-16, docs/GAME-PASS.md): off until Marty flips it; caps apply from capsStartDate (Central), before it polgrant allows everything and only records
|
||||
gamePassEnabled: '0', gamePassPriceCredits: 500, gamePassDays: 7, capFreeDaily: 0.30, capFreeTotal: 2.0, capPassDaily: 1.50, capPassTotal: 5.0, capsStartDate: '', passTournamentPct: 5,
|
||||
supportTelegramChat: '1289244227', // help desk pings: Marty's PRIVATE chat only (a positive user id; group/channel ids are refused). Sent with telegramBotToken, Hermes bot as fallback
|
||||
supportTemplates: '', // help desk saved replies, JSON [{name, body}] (Admin > Support > Saved replies); empty = the built-in set
|
||||
telegramGamesChatId: '', telegramGamesTopicId: '661565', // Game Achievements topic for the weekly Pass Tournament post (chat blank = the shared echo chat)
|
||||
pnlFixedMonthlyUsd: 0
|
||||
}, saved);
|
||||
@@ -990,6 +994,55 @@ function tgSendAs(token, chatId, text, threadId) {
|
||||
rq.end(body);
|
||||
});
|
||||
}
|
||||
// Help desk pings (2026-10-16): Marty's PRIVATE Telegram chat only, never a group, topic or feed. tgSendAs skips the
|
||||
// Discord relay entirely. Site bot (telegramBotToken) first, Marty's Hermes bot if that one cannot reach him.
|
||||
async function supportTelegram(text) {
|
||||
const sc = siteConfig();
|
||||
const chat = String(sc.supportTelegramChat || '1289244227').trim();
|
||||
if (!/^\d{4,15}$/.test(chat)) { console.error('support ping refused: supportTelegramChat must be a private chat id (positive number), not', chat); return false; }
|
||||
let ok = false;
|
||||
const site = String(sc.telegramBotToken || '').trim(), hermes = String(process.env.HERMES_BOT_TOKEN || '').trim();
|
||||
if (site) ok = await tgSendAs(site, chat, text);
|
||||
if (!ok && hermes) ok = await tgSendAs(hermes, chat, text);
|
||||
if (!ok) console.error('support ping not delivered (chat ' + chat + ', site bot ' + (site ? 'set' : 'missing') + ', hermes ' + (hermes ? 'set' : 'missing') + ')');
|
||||
return ok;
|
||||
}
|
||||
// Public support form + signed-out chatbot hand-off: the sign-up guard's walls (honeypot, form age, per-IP limits with the
|
||||
// icon check once tripped, a global cap) plus a hard per-email cap. Returns null to allow, or { status, body }.
|
||||
const SUPPORT_LIMITS = { ipHour: 5, ipDay: 15, emailHour: 3, emailDay: 8, globalPerMin: 20, minFormMs: 2000 };
|
||||
const supportHits = new Map(); // 'ip:<ip>' | 'em:<email>' | 'tk:<ticket id>' -> [timestamps, 24h]
|
||||
const supportChal = new Map(); // ip -> { chal, passUntil }
|
||||
const supportGlobal = { minute: 0, n: 0 };
|
||||
const supportRecent = (k, ms) => { const now = Date.now(); const t = (supportHits.get(k) || []).filter(ts => now - ts < 86400000); supportHits.set(k, t); return t.filter(ts => now - ts < ms).length; };
|
||||
const supportMark = k => { const t = supportHits.get(k) || []; t.push(Date.now()); supportHits.set(k, t); if (supportHits.size > 5000) for (const [kk, v] of supportHits) if (!v.length || Date.now() - v[v.length - 1] > 86400000) supportHits.delete(kk); };
|
||||
const supportFlood = (k, n, ms) => { if (supportRecent(k, ms) >= n) return true; supportMark(k); return false; }; // signed-in and private-link replies: a plain cap
|
||||
function supportGuard(req, b, email) {
|
||||
const now = Date.now();
|
||||
const hpRaw = String(b.hp_field_x9 || '').trim();
|
||||
const hp = !!hpRaw && hpRaw.toLowerCase() !== email; // own email = phone autofill, not a bot
|
||||
const fts = Number(b.fts) || 0;
|
||||
const fage = (b.fage !== undefined && b.fage !== null && b.fage !== '' && Number.isFinite(Number(b.fage))) ? Number(b.fage) : (fts ? now - fts : -1);
|
||||
if (fage < SUPPORT_LIMITS.minFormMs) { guardLog(req, 'support form-age', b); return { status: 400, body: { error: 'Give the page a few seconds, then send again.' } }; }
|
||||
if (fage > 12 * 3600 * 1000) { guardLog(req, 'support form-stale', b); return { status: 400, body: { error: 'This page has been open a long time. Refresh it, then send again.' } }; }
|
||||
const minute = Math.floor(now / 60000);
|
||||
if (supportGlobal.minute !== minute) { supportGlobal.minute = minute; supportGlobal.n = 0; }
|
||||
if (supportGlobal.n >= SUPPORT_LIMITS.globalPerMin) { guardLog(req, 'support global-limit', b); return { status: 429, body: { error: 'Busy right now. Try again in a minute.' } }; }
|
||||
if (supportRecent('em:' + email, 3600000) >= SUPPORT_LIMITS.emailHour || supportRecent('em:' + email, 86400000) >= SUPPORT_LIMITS.emailDay) {
|
||||
guardLog(req, 'support email-limit', b);
|
||||
return { status: 429, body: { error: 'You have sent several tickets already. Reply on the one you have open (the link is in your confirmation email) and Marty will see it there.' } };
|
||||
}
|
||||
const ip = clientIp(req);
|
||||
const limited = hp || supportRecent('ip:' + ip, 3600000) >= SUPPORT_LIMITS.ipHour || supportRecent('ip:' + ip, 86400000) >= SUPPORT_LIMITS.ipDay;
|
||||
const rec = supportChal.get(ip) || { chal: null, passUntil: 0 };
|
||||
if (limited && now >= rec.passUntil) {
|
||||
const pick = String(b.pick || '');
|
||||
if (pick && rec.chal && rec.chal.exp > now && pick === rec.chal.answer) { rec.passUntil = now + CODE_LIMITS.passMs; rec.chal = null; }
|
||||
else { guardLog(req, pick ? 'support wrong-pick' : hp ? 'support honeypot-challenge' : 'support ip-limit', b); const challenge = codeChallenge(rec); supportChal.set(ip, rec); if (supportChal.size > 5000) supportChal.clear(); return { status: 429, body: { error: pick ? 'That was not it. Try once more.' : 'Quick check before we send it.', challenge } }; }
|
||||
supportChal.set(ip, rec);
|
||||
}
|
||||
supportGlobal.n += 1; supportMark('ip:' + ip); supportMark('em:' + email);
|
||||
return null;
|
||||
}
|
||||
function fraudAlert(email, fc, spAcct, blocked) {
|
||||
try {
|
||||
const sc = siteConfig();
|
||||
@@ -1911,7 +1964,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const c = chain.getConfig();
|
||||
// public copy of the site settings: never anything that looks like a credential
|
||||
const pubSite = {};
|
||||
for (const [k, v] of Object.entries(siteConfig())) if (!/secret|token|password|private|apikey|api_key/i.test(k)) pubSite[k] = v;
|
||||
for (const [k, v] of Object.entries(siteConfig())) if (!/secret|token|password|private|apikey|api_key/i.test(k) && !/^support/.test(k)) pubSite[k] = v; // support* = help desk internals (Marty's chat id, saved replies)
|
||||
return json(res, 200, Object.assign({ contract: c.contract, chainId: c.chainId,
|
||||
chainName: c.chainName, explorer: c.explorer, rpc: c.rpcs[0],
|
||||
emailAuth: mailer.hasKey() || !IS_PROD }, pubSite));
|
||||
@@ -2043,6 +2096,48 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
|
||||
// -- help desk, public side (2026-10-16, tickets.js): /support form, the private no-login ticket link, the chatbot hand-off
|
||||
if (p === '/api/support' && req.method === 'POST') {
|
||||
const b = await readBody(req);
|
||||
const s = await auth.fromRequest(req);
|
||||
const acct = s && s.email ? await accounts.byEmail(s.email) : null; // signed in: the ticket is theirs, whatever was typed
|
||||
const email = acct ? acct.email : String(b.email || '').trim().toLowerCase();
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'That email address does not look right.' });
|
||||
const guard = supportGuard(req, b, email);
|
||||
if (guard) return json(res, guard.status, guard.body);
|
||||
const r = await tickets.create({ source: 'public', email, name: b.name || (acct && acct.username) || '', username: acct && acct.username, subject: b.subject, category: b.category, body: b.body });
|
||||
if (r.error) return json(res, 400, r);
|
||||
return json(res, 200, { ok: true, ref: r.ticket.ref, token: r.token, member: !!acct });
|
||||
}
|
||||
m = /^\/api\/support\/t\/([A-Za-z0-9_.-]{20,80})(\/reply)?$/.exec(p);
|
||||
if (m && (req.method === 'GET' || (m[2] && req.method === 'POST'))) {
|
||||
const t = await tickets.byToken(m[1]);
|
||||
if (!t) return json(res, 404, { error: 'This ticket link is not valid. Open the newest email about your ticket, or send a new one.' });
|
||||
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.' });
|
||||
const r = await tickets.addMessage(t.id, { author: 'member', body: b.body, via: 'link' });
|
||||
return json(res, r.error ? 400 : 200, r.error ? r : await tickets.memberView(r.ticket));
|
||||
}
|
||||
if (p === '/api/support/chatbot' && req.method === 'POST') {
|
||||
const b = await readBody(req);
|
||||
const s = await auth.fromRequest(req);
|
||||
const acct = s && s.email ? await accounts.byEmail(s.email) : null;
|
||||
const email = acct ? acct.email : String(b.email || '').trim().toLowerCase();
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'Add your email so Marty can reply.', needEmail: true });
|
||||
if (acct) { if (supportFlood('em:' + email, 5, 3600000)) return json(res, 429, { error: 'You have sent several tickets in the last hour. Open Help in your dashboard to add to one.' }); }
|
||||
else { const guard = supportGuard(req, b, email); if (guard) return json(res, guard.status, guard.body); }
|
||||
const tr = Array.isArray(b.transcript) ? b.transcript : [];
|
||||
const turns = tr.slice(-8).map(x => ((x && x.who === 'me') ? 'Me: ' : 'Assistant: ') + String((x && x.text) || '').replace(/\s+/g, ' ').trim().slice(0, 600)).filter(x => x.length > 6);
|
||||
const firstQ = tr.find(x => x && x.who === 'me' && String(x.text || '').trim());
|
||||
const note = String(b.note || '').trim().slice(0, 2000);
|
||||
const body = (note ? note + '\n\n' : '') + (turns.length ? 'From the chat assistant:\n' + turns.join('\n') : '(sent from the chat assistant)');
|
||||
const r = await tickets.create({ source: 'chatbot', email, name: b.name || (acct && acct.username) || '', username: acct && acct.username, category: 'Other',
|
||||
subject: 'Chat: ' + (firstQ ? String(firstQ.text).replace(/\s+/g, ' ').trim().slice(0, 100) : 'question for support'), body });
|
||||
if (r.error) return json(res, 400, r);
|
||||
return json(res, 200, { ok: true, ref: r.ticket.ref, member: !!acct, link: acct ? '/my#help?t=' + r.ticket.ref : '/support/t/' + r.token });
|
||||
}
|
||||
|
||||
// -- accounts: email + password is the normal join path (wallet comes
|
||||
// out only at purchase / payout-activation time and gets linked then)
|
||||
if (p === '/api/signup' && req.method === 'POST') {
|
||||
@@ -2108,7 +2203,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const via = parseCookies(req)['iap.angle'] || (pend && pend.via) || '';
|
||||
const joinedRef = decodeURIComponent(parseCookies(req)['iap.ref'] || '') || (pend && pend.joinedRef) || null;
|
||||
if (ref && !parseCookies(req)['iap.sponsor']) console.log('sponsor recovered without cookie', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'ref', ref, pageTok(b.ref) ? '(page token)' : '(remembered from the code request)');
|
||||
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support.' });
|
||||
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support at instantadpay.com/support.' });
|
||||
let fraudFlags = [];
|
||||
const existing = await accounts.byEmail(e);
|
||||
const claim = accounts.isUnclaimedShell(existing); // a waiting LinkSpin account: this sign-in is its owner's real sign-up
|
||||
@@ -2198,7 +2293,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (rec.tries > 6) { emailCodes.delete(e); return json(res, 400, { error: 'Too many tries. Request a fresh code.' }, cors); }
|
||||
if (String(b.code || '').trim() !== rec.code) return json(res, 400, { error: 'That code does not match.' }, cors);
|
||||
emailCodes.delete(e);
|
||||
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support.' }, cors);
|
||||
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support at instantadpay.com/support.' }, cors);
|
||||
const pend = pendingSponsor.get(e);
|
||||
const ref = pageTok(b.ref) || (pend && pend.ref) || '';
|
||||
const via = String(b.game); const srcTag = String(b.src || '').toLowerCase().replace(/[^a-z0-9_.-]/g, '').slice(0, 30);
|
||||
@@ -2812,7 +2907,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 b = await readBody(req);
|
||||
if (fraud.excluded(s.email)) return json(res, 403, { error: 'Adoptions are not available on this account. Contact support.' });
|
||||
if (fraud.excluded(s.email)) return json(res, 403, { error: 'Adoptions are not available on this account. Contact support at instantadpay.com/support.' });
|
||||
const r = await tank.adopt(s.email, b.who, b.note);
|
||||
if (r.ok) { // tell the payments topic who picked whom up (Marty, 2026-09-12)
|
||||
pushFeed({ type: 'Adopted', sponsor: r.adopterName, member: r.adopteeName, ts: Date.now() });
|
||||
@@ -2959,7 +3054,7 @@ const server = http.createServer(async (req, res) => {
|
||||
// a username is permanent once set: the invite link, the public wall and every
|
||||
// banner already printed carry it (Marty, 2026-09-10)
|
||||
if (before && before.username && String(b.username || '').trim().toLowerCase() !== String(before.username).toLowerCase())
|
||||
return json(res, 400, { error: 'Your username is locked. Your invite link, your public page and any banners you shared all carry @' + before.username + '. Contact support if it truly has to change.' });
|
||||
return json(res, 400, { error: 'Your username is locked. Your invite link, your public page and any banners you shared all carry @' + before.username + '. Contact support (instantadpay.com/support) if it truly has to change.' });
|
||||
const r = await accounts.setUsername(s.email, b.username);
|
||||
// First time a username is set (onboarding): now there's a real name to
|
||||
// show, so notify the sponsor here rather than at signup (where it'd just
|
||||
@@ -3794,6 +3889,29 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
return json(res, 200, { ok: true, sent: recipients.length });
|
||||
}
|
||||
// -- help desk, member side (2026-10-16): the Help pane lists, opens and answers this member's tickets
|
||||
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 });
|
||||
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);
|
||||
const r = await tickets.create({ source: 'form', email: s.email, name: (a && a.username) || '', username: a && a.username, subject: b.subject, category: b.category, body: b.body, attachments: b.attachments });
|
||||
return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, ref: r.ticket.ref });
|
||||
}
|
||||
m = /^\/api\/my\/support\/((?:IAP|LS)-\d{4,9})(\/reply)?$/.exec(p);
|
||||
if (m && (req.method === 'GET' || (m[2] && req.method === 'POST'))) {
|
||||
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 (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.' });
|
||||
const r = await tickets.addMessage(t.id, { author: 'member', body: b.body, attachments: b.attachments });
|
||||
return json(res, r.error ? 400 : 200, r.error ? r : await tickets.memberView(r.ticket));
|
||||
}
|
||||
// -- sponsor messages: this member's inbox from their upline
|
||||
if (p === '/api/my/messages' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
@@ -4421,6 +4539,38 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!isAdmin(req)) return json(res, 200, { admin: false });
|
||||
return json(res, 200, { admin: true, email: ADMIN_EMAIL });
|
||||
}
|
||||
// -- help desk, admin side (2026-10-16): the Support pane
|
||||
if (p === '/api/admin/support' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, Object.assign(await tickets.adminList({ status: u.searchParams.get('status'), platform: u.searchParams.get('platform'), category: u.searchParams.get('category'), q: u.searchParams.get('q') }),
|
||||
{ categories: tickets.CATEGORIES, platforms: tickets.PLATFORMS }));
|
||||
}
|
||||
if (p === '/api/admin/support/counts' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, await tickets.counts());
|
||||
}
|
||||
if (p === '/api/admin/support/templates' && (req.method === 'GET' || req.method === 'PUT')) {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const read = () => { const v = siteConfig().supportTemplates; let a = v; if (typeof v === 'string') { try { a = JSON.parse(v); } catch (e) { a = null; } } return Array.isArray(a) && a.length ? a : tickets.DEFAULT_TEMPLATES; };
|
||||
if (req.method === 'GET') return json(res, 200, { templates: read() });
|
||||
const b = await readBody(req);
|
||||
const list = (Array.isArray(b.templates) ? b.templates : []).map(t => ({ name: String((t && t.name) || '').trim().slice(0, 60), body: String((t && t.body) || '').trim().slice(0, 3000) })).filter(t => t.name && t.body).slice(0, 30);
|
||||
const cur = siteConfig(); cur.supportTemplates = list; fs.writeFileSync(SITE_FILE, JSON.stringify(cur, null, 2));
|
||||
return json(res, 200, { ok: true, templates: read() });
|
||||
}
|
||||
m = /^\/api\/admin\/support\/((?:IAP|LS)-\d{4,9})(\/reply)?$/.exec(p);
|
||||
if (m) {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const t = await tickets.byRef(m[1]);
|
||||
if (!t) return json(res, 404, { error: 'Ticket not found.' });
|
||||
if (m[2] && req.method === 'POST') { const b = await readBody(req); const r = await tickets.addMessage(t.id, { author: 'admin', body: b.body, internal: !!b.internal, status: b.status, attachments: b.attachments }); if (r.error) return json(res, 400, r); }
|
||||
else if (!m[2] && req.method === 'PATCH') { const r = await tickets.setFields(t.id, await readBody(req)); if (r.error) return json(res, 400, r); }
|
||||
else if (m[2] || req.method !== 'GET') return json(res, 405, { error: 'method' });
|
||||
const v = await tickets.adminView(t.id);
|
||||
const a = await accounts.byEmail(v.ticket.email);
|
||||
v.requester = a ? { member: true, email: a.email, username: a.username || '', memberId: a.memberId || 0, wallet: !!a.address, created: a.created || 0, lastSeen: a.lastSeen || 0 } : { member: false, email: v.ticket.email };
|
||||
return json(res, 200, v);
|
||||
}
|
||||
if (p === '/api/admin/refill' && req.method === 'GET') { // who was told their ads ran out, and what they did next
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, refill.stats());
|
||||
@@ -4842,7 +4992,7 @@ const server = http.createServer(async (req, res) => {
|
||||
+ '<style>.bp{max-width:560px;text-align:center;padding:40px 16px 60px}.bp img{width:100%;max-width:520px;border-radius:18px;border:1px solid var(--line);box-shadow:0 20px 60px rgba(0,0,0,.45)}.bp h1{font-size:clamp(24px,5vw,34px);margin:22px 0 8px}.bp p{color:var(--muted);max-width:44ch;margin:0 auto 20px}</style></head>'
|
||||
+ '<body><div class="wrap bp"><img src="' + img + '" alt="' + esc(label) + ' badge for @' + esc(un) + '"><h1>@' + esc(un) + ' unlocked <em>' + label + '</em></h1><p>' + esc(sub.charAt(0).toUpperCase() + sub.slice(1)) + '. On InstantAdPay every ad package that sells pays the sponsor in the same transaction, straight to their wallet, on-chain.</p>'
|
||||
+ '<a class="btn" href="/join/' + esc(un) + '">Join @' + esc(un) + '\u2019s line free</a><p class="small" style="margin-top:26px">Advertising with a performance referral program. Not an investment; no income is guaranteed.</p></div>'
|
||||
+ '<script src="/assets/common.js?v=20261015a"></script><script src="/assets/blog-page.js?v=20260921a"></script></body></html>';
|
||||
+ '<script src="/assets/common.js?v=20261016a"></script><script src="/assets/blog-page.js?v=20260921a"></script></body></html>';
|
||||
res.writeHead(200, baseHeaders({ 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'public, max-age=300' }));
|
||||
return res.end(html);
|
||||
}
|
||||
@@ -4872,6 +5022,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return res.end(blog.renderPost(post, related));
|
||||
}
|
||||
if (p === '/wallets') return sendFile(res, path.join(PUBLIC_DIR, 'wallets.html'));
|
||||
if (p === '/support' || /^\/support\/t\/[A-Za-z0-9_.-]{20,80}$/.test(p)) return sendFile(res, path.join(PUBLIC_DIR, 'support.html')); // help desk (2026-10-16): the form, and the private ticket link
|
||||
if (p === '/friday') return sendFile(res, path.join(PUBLIC_DIR, 'friday.html'));
|
||||
if (p === '/wednesday') return sendFile(res, path.join(PUBLIC_DIR, 'wednesday.html'));
|
||||
if (p === '/refuel') return sendFile(res, path.join(PUBLIC_DIR, 'refuel.html')); // Drip Runner refuel visit (2026-09-30)
|
||||
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
// 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.
|
||||
//
|
||||
// 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
|
||||
// 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,
|
||||
// inReplyTo, references }): it threads by stored Message-ID first, then by the [IAP-1042] ref in the
|
||||
// subject (only when the sender matches the ticket's email), else opens a new ticket (source 'email').
|
||||
//
|
||||
// Dual-mode store like the other modules (MySQL when DATABASE_URL is set, JSON on the volume).
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const db = require('./db');
|
||||
|
||||
let DATA_DIR = null, deps = {};
|
||||
const SITE = 'https://instantadpay.com';
|
||||
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'];
|
||||
const PLATFORMS = ['iap', 'linkspin'];
|
||||
const SOURCES = ['form', 'public', 'chatbot', 'email'];
|
||||
const PREFIX = { iap: 'IAP', linkspin: 'LS' };
|
||||
const REF_BASE = 1000;
|
||||
const DEFAULT_TEMPLATES = [
|
||||
{ name: 'Thanks, looking into it', body: 'Thanks for writing in. I am looking into this now and will reply here as soon as I have an answer.\n\nMarty' },
|
||||
{ name: 'Sign-in code help', body: 'Sign-in codes come from no-reply@instantadpay.com and work for 15 minutes. If one does not arrive, check your spam or promotions folder, then request a fresh code at https://instantadpay.com/my. Each code replaces the one before it, so use the newest.\n\nMarty' },
|
||||
{ name: 'Payouts are on-chain', body: 'Every payout is paid by the contract in the same transaction as the purchase, straight to the wallet on your account, and you can check each one on the live ledger: https://instantadpay.com/ledger. If a payout passed you by, it is usually because payouts were not switched on yet or a level was not open. Your Earnings tab shows the trace for each purchase.\n\nMarty' },
|
||||
{ name: 'Solved, closing', body: 'Glad that is sorted. I will close this ticket now. If anything else comes up, reply here and it opens again.\n\nMarty' }
|
||||
];
|
||||
|
||||
const refOf = (id, platform) => (PREFIX[platform] || 'IAP') + '-' + (REF_BASE + Number(id));
|
||||
function parseRef(s) {
|
||||
const m = /\b(IAP|LS)-(\d{4,9})\b/i.exec(String(s || ''));
|
||||
if (!m) return null;
|
||||
const id = Number(m[2]) - REF_BASE;
|
||||
return id > 0 ? { ref: m[1].toUpperCase() + '-' + m[2], id } : null;
|
||||
}
|
||||
const clean = (s, n) => String(s == null ? '' : s).replace(/\r\n?/g, '\n').replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, '').trim().slice(0, n);
|
||||
const oneLine = (s, n) => clean(s, 2000).replace(/\s+/g, ' ').slice(0, n);
|
||||
const ATT_RE = /^\/uploads\/[a-z0-9]{24}\.(?:png|jpg|webp|gif)$/;
|
||||
const atts = a => (Array.isArray(a) ? a : []).map(String).filter(x => ATT_RE.test(x)).slice(0, 2);
|
||||
const lc = e => String(e || '').trim().toLowerCase();
|
||||
|
||||
// ---- signed private link ----
|
||||
let SECRET = '';
|
||||
function secret() {
|
||||
if (process.env.SUPPORT_SECRET && process.env.SUPPORT_SECRET.length >= 32) return process.env.SUPPORT_SECRET;
|
||||
if (SECRET) return SECRET;
|
||||
const f = path.join(DATA_DIR, 'support.key');
|
||||
try { SECRET = fs.readFileSync(f, 'utf8').trim(); } catch (e) {}
|
||||
if (SECRET.length < 32) {
|
||||
const s = crypto.randomBytes(32).toString('hex');
|
||||
try { fs.writeFileSync(f, s, { flag: 'wx', mode: 0o600 }); SECRET = s; } // wx: the other copy during a deploy overlap may have written it first
|
||||
catch (e) { try { SECRET = fs.readFileSync(f, 'utf8').trim(); } catch (e2) { SECRET = s; } }
|
||||
}
|
||||
return 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 TOKEN_RE = /^((?:IAP|LS)-\d{4,9})\.([A-Za-z0-9_-]{32})$/;
|
||||
|
||||
// ---- stores ----
|
||||
const J = {
|
||||
db: null,
|
||||
FILE: () => path.join(DATA_DIR, 'support.json'),
|
||||
load() { try { this.db = JSON.parse(fs.readFileSync(this.FILE(), 'utf8')); } catch (e) { this.db = { nextId: 1, nextMsg: 1, tickets: [], messages: [] }; } },
|
||||
save() { try { fs.writeFileSync(this.FILE(), JSON.stringify(this.db)); } catch (e) {} },
|
||||
d() { if (!this.db) this.load(); return this.db; },
|
||||
async insertTicket(t) { const d = this.d(); const id = d.nextId++; d.tickets.push(Object.assign({}, t, { id, ref: refOf(id, t.platform) })); this.save(); return id; },
|
||||
async updateTicket(id, f) { const t = this.d().tickets.find(x => x.id === Number(id)); if (t) { Object.assign(t, f); this.save(); } },
|
||||
async getTicket(id) { const t = this.d().tickets.find(x => x.id === Number(id)); return t ? Object.assign({}, t) : null; },
|
||||
async list(f) {
|
||||
let rows = this.d().tickets.slice();
|
||||
if (f.email) rows = rows.filter(t => t.email === f.email);
|
||||
if (f.status) rows = rows.filter(t => t.status === f.status);
|
||||
if (f.platform) rows = rows.filter(t => t.platform === f.platform);
|
||||
if (f.category) rows = rows.filter(t => t.category === f.category);
|
||||
if (f.q) { const q = f.q.toLowerCase(); rows = rows.filter(t => [t.ref, t.email, t.name, t.username, t.subject].some(v => String(v || '').toLowerCase().includes(q))); }
|
||||
return rows.sort((a, b) => b.updated - a.updated).slice(0, f.limit || 200).map(t => Object.assign({}, t));
|
||||
},
|
||||
async insertMessage(m) { const d = this.d(); const id = d.nextMsg++; d.messages.push(Object.assign({}, m, { id })); this.save(); return id; },
|
||||
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; }
|
||||
};
|
||||
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),
|
||||
lastMemberAt: Number(r.last_member_at || 0), lastAdminAt: Number(r.last_admin_at || 0), adminUnread: !!r.admin_unread, memberUnread: !!r.member_unread }) : null;
|
||||
const mRow = r => ({ id: r.id, ticketId: r.ticket_id, author: r.author, body: r.body || '', internal: !!r.internal, attachments: (() => { try { return JSON.parse(r.attachments || '[]'); } catch (e) { return []; } })(),
|
||||
created: Number(r.created), emailMessageId: r.email_message_id || null, via: r.via || 'web' });
|
||||
const COLS = { platform: 'platform', source: 'source', email: 'email', name: 'name', username: 'username', subject: 'subject', category: 'category', status: 'status', priority: 'priority',
|
||||
created: 'created', updated: 'updated', lastMemberAt: 'last_member_at', lastAdminAt: 'last_admin_at', adminUnread: 'admin_unread', memberUnread: 'member_unread' };
|
||||
const D = {
|
||||
async insertTicket(t) {
|
||||
const r = await db.q('INSERT INTO tickets (ref,platform,source,email,name,username,subject,category,status,priority,created,updated,last_member_at,last_admin_at,admin_unread,member_unread) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
|
||||
['pending-' + crypto.randomBytes(5).toString('hex'), t.platform, t.source, t.email, t.name || null, t.username || null, t.subject, t.category, t.status, t.priority, t.created, t.updated, t.lastMemberAt || null, t.lastAdminAt || null, t.adminUnread ? 1 : 0, t.memberUnread ? 1 : 0]);
|
||||
await db.q('UPDATE tickets SET ref=? WHERE id=?', [refOf(r.insertId, t.platform), r.insertId]);
|
||||
return r.insertId;
|
||||
},
|
||||
async updateTicket(id, f) {
|
||||
const sets = [], vals = [];
|
||||
for (const [k, v] of Object.entries(f)) if (COLS[k]) { sets.push(COLS[k] + '=?'); vals.push(typeof v === 'boolean' ? (v ? 1 : 0) : v); }
|
||||
if (sets.length) await db.q('UPDATE tickets SET ' + sets.join(',') + ' WHERE id=?', vals.concat([Number(id)]));
|
||||
},
|
||||
async getTicket(id) { return tRow((await db.q('SELECT * FROM tickets WHERE id=?', [Number(id)]))[0]); },
|
||||
async list(f) {
|
||||
const w = [], v = [];
|
||||
if (f.email) { w.push('email=?'); v.push(f.email); }
|
||||
if (f.status) { w.push('status=?'); v.push(f.status); }
|
||||
if (f.platform) { w.push('platform=?'); v.push(f.platform); }
|
||||
if (f.category) { w.push('category=?'); v.push(f.category); }
|
||||
if (f.q) { w.push('(ref LIKE ? OR email LIKE ? OR name LIKE ? OR username LIKE ? OR subject LIKE ?)'); const l = '%' + f.q + '%'; v.push(l, l, l, l, l); }
|
||||
return (await db.q('SELECT * FROM tickets' + (w.length ? ' WHERE ' + w.join(' AND ') : '') + ' ORDER BY updated DESC LIMIT ?', v.concat([f.limit || 200]))).map(tRow);
|
||||
},
|
||||
async insertMessage(m) {
|
||||
const r = await db.q('INSERT INTO ticket_messages (ticket_id,author,body,internal,attachments,created,email_message_id,via) VALUES (?,?,?,?,?,?,?,?)',
|
||||
[m.ticketId, m.author, m.body, m.internal ? 1 : 0, m.attachments && m.attachments.length ? JSON.stringify(m.attachments) : null, m.created, m.emailMessageId || null, m.via || 'web']);
|
||||
return r.insertId;
|
||||
},
|
||||
async messages(ticketId, internal) { return (await db.q('SELECT * FROM ticket_messages WHERE ticket_id=?' + (internal ? '' : ' AND internal=0') + ' ORDER BY id ASC', [Number(ticketId)])).map(mRow); },
|
||||
async byMessageId(mids) { if (!mids.length) return 0; const r = await db.q('SELECT ticket_id FROM ticket_messages WHERE email_message_id IN (?) LIMIT 1', [mids]); return r.length ? r[0].ticket_id : 0; },
|
||||
async counts() {
|
||||
const out = { open: 0, waiting_on_member: 0, closed: 0, unread: 0 };
|
||||
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); }
|
||||
};
|
||||
const impl = () => db.enabled() ? D : J;
|
||||
|
||||
// deps: { mailer, messages, accounts, telegram(text) -> Promise, adminEmail }
|
||||
function init(opts) { DATA_DIR = opts.dataDir; deps = opts; }
|
||||
|
||||
// ---- notifications, throttled: the first event in a window goes out at once, the rest of the
|
||||
// window's events are batched into one send at its end, so a burst of replies is one ping ----
|
||||
const windows = new Map();
|
||||
function throttled(key, ms, item, flush) {
|
||||
const now = Date.now(); let w = windows.get(key);
|
||||
if (!w || (now >= w.until && !w.timer)) {
|
||||
windows.set(key, { until: now + ms, pending: [], timer: null });
|
||||
if (windows.size > 2000) for (const [k, v] of windows) if (v.until < now && !v.timer) windows.delete(k);
|
||||
return void Promise.resolve().then(() => flush([item])).catch(e => console.error('support notify', e.message));
|
||||
}
|
||||
w.pending.push(item);
|
||||
if (!w.timer) {
|
||||
w.timer = setTimeout(() => {
|
||||
const items = w.pending.splice(0); w.timer = null; w.until = Date.now() + ms;
|
||||
if (items.length) Promise.resolve().then(() => flush(items)).catch(e => console.error('support notify', e.message));
|
||||
}, Math.max(0, w.until - now));
|
||||
if (w.timer.unref) w.timer.unref();
|
||||
}
|
||||
}
|
||||
const newPings = { hour: 0, n: 0, skipped: 0 }; // new-ticket pings: at most 20 an hour, the rest summed into the next one
|
||||
const escH = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
const who = t => (t.name ? t.name + ' ' : '') + '<' + t.email + '>' + (t.username ? ' @' + t.username : '');
|
||||
const adminLink = t => SITE + '/admin#support?t=' + t.ref;
|
||||
const firstLine = s => oneLine(String(s || '').split('\n').find(l => l.trim()) || '', 140);
|
||||
|
||||
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');
|
||||
let extra = '';
|
||||
if (kind === 'new') {
|
||||
const h = Math.floor(Date.now() / 3600000);
|
||||
if (newPings.hour !== h) { newPings.hour = h; newPings.n = 0; }
|
||||
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;
|
||||
if (deps.telegram) deps.telegram(text).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));
|
||||
}
|
||||
};
|
||||
if (kind === 'new') return send([m]);
|
||||
throttled('admin:' + t.id, 10 * 60 * 1000, m, send);
|
||||
}
|
||||
function htmlMail(intro, blocks, link, linkLabel) {
|
||||
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>';
|
||||
}
|
||||
function confirmRequester(t, m) {
|
||||
if (!deps.mailer || !deps.mailer.hasKey()) return;
|
||||
const link = linkFor(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 })
|
||||
.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 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 })
|
||||
.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
|
||||
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),
|
||||
'<p>Marty replied to your support ticket <b>' + escH(cur.ref) + '</b>.</p><p style="white-space:pre-wrap">' + escH(bodies[bodies.length - 1].slice(0, 600)) + '</p><p><a href="/my#help?t=' + escH(cur.ref) + '">Open it in Help</a></p>', 'notice');
|
||||
} catch (e) { console.error('support notice', e.message); }
|
||||
});
|
||||
}
|
||||
|
||||
// ---- the desk ----
|
||||
function validate(o) {
|
||||
const subject = oneLine(o.subject, 140), body = clean(o.body, 5000);
|
||||
if (subject.length < 3) return { error: 'Add a short subject.' };
|
||||
if (body.length < 5) return { error: 'Tell us a little more in the message.' };
|
||||
return { subject, body };
|
||||
}
|
||||
// create a ticket and its first message. o: { platform, source, email, name, username, subject, category, body,
|
||||
// attachments, priority, emailMessageId, via, confirm (default true except source 'email'), notify (default true) }
|
||||
async function create(o) {
|
||||
const email = lc(o.email);
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email) || email.length > 190) return { error: 'That email address does not look right.' };
|
||||
const v = validate(o); if (v.error) return v;
|
||||
const now = Date.now();
|
||||
const t = { platform: PLATFORMS.includes(o.platform) ? o.platform : 'iap', source: SOURCES.includes(o.source) ? o.source : 'form', email,
|
||||
name: oneLine(o.name, 80), username: oneLine(o.username, 30), subject: v.subject, category: CATEGORIES.includes(o.category) ? o.category : 'Other',
|
||||
status: 'open', priority: PRIORITIES.includes(o.priority) ? o.priority : 'normal', created: now, updated: now, lastMemberAt: now, lastAdminAt: 0, adminUnread: true, memberUnread: false };
|
||||
const id = await impl().insertTicket(t);
|
||||
const m = { ticketId: id, author: 'member', body: v.body, internal: false, attachments: atts(o.attachments), created: now, emailMessageId: o.emailMessageId ? String(o.emailMessageId).slice(0, 250) : null, via: o.via || (t.source === 'email' ? 'email' : 'web') };
|
||||
m.id = await impl().insertMessage(m);
|
||||
const ticket = await impl().getTicket(id);
|
||||
if (o.notify !== false) pingAdmin('new', ticket, m);
|
||||
if (o.confirm !== undefined ? o.confirm : t.source !== 'email') confirmRequester(ticket, m);
|
||||
return { ok: true, ticket, message: m, token: tokenFor(ticket), link: linkFor(ticket) };
|
||||
}
|
||||
// add a message. o: { author 'member'|'admin'|'system', body, internal, attachments, status (admin: status after sending),
|
||||
// emailMessageId, via }. A member reply reopens a closed or waiting ticket; an admin reply defaults to waiting_on_member.
|
||||
async function addMessage(ticketId, o) {
|
||||
const t = await impl().getTicket(ticketId);
|
||||
if (!t) return { error: 'Ticket not found.' };
|
||||
const author = ['member', 'admin', 'system'].includes(o.author) ? o.author : 'member';
|
||||
const body = clean(o.body, 5000);
|
||||
if (body.length < 1) return { error: 'Write a message first.' };
|
||||
const internal = author === 'admin' && !!o.internal;
|
||||
const now = Date.now();
|
||||
const m = { ticketId: t.id, author, body, internal, attachments: atts(o.attachments), created: now, emailMessageId: o.emailMessageId ? String(o.emailMessageId).slice(0, 250) : null, via: o.via || 'web' };
|
||||
m.id = await impl().insertMessage(m);
|
||||
const f = { updated: now };
|
||||
if (author === 'member') Object.assign(f, { lastMemberAt: now, adminUnread: true, status: 'open' });
|
||||
if (author === 'admin' && !internal) Object.assign(f, { lastAdminAt: now, memberUnread: true, status: STATUSES.includes(o.status) ? o.status : 'waiting_on_member' });
|
||||
if (author === 'admin' && internal && STATUSES.includes(o.status)) f.status = o.status;
|
||||
await impl().updateTicket(t.id, f);
|
||||
const cur = await impl().getTicket(t.id);
|
||||
if (author === 'member' && o.notify !== false) pingAdmin('reply', cur, m);
|
||||
if (author === 'admin' && !internal && o.notify !== false) notifyRequester(cur, m);
|
||||
return { ok: true, ticket: cur, message: m };
|
||||
}
|
||||
async function setFields(ticketId, f) {
|
||||
const t = await impl().getTicket(ticketId); if (!t) return { error: 'Ticket not found.' };
|
||||
const up = {};
|
||||
if (STATUSES.includes(f.status)) up.status = f.status;
|
||||
if (PRIORITIES.includes(f.priority)) up.priority = f.priority;
|
||||
if (CATEGORIES.includes(f.category)) up.category = f.category;
|
||||
if (PLATFORMS.includes(f.platform)) up.platform = f.platform;
|
||||
if (!Object.keys(up).length) return { error: 'Nothing to change.' };
|
||||
up.updated = Date.now();
|
||||
await impl().updateTicket(t.id, up);
|
||||
return { ok: true, ticket: await impl().getTicket(t.id) };
|
||||
}
|
||||
const byRef = async ref => { const r = parseRef(ref); if (!r) return null; const t = await impl().getTicket(r.id); return t && t.ref === r.ref ? t : null; };
|
||||
async function byToken(tok) {
|
||||
const m = TOKEN_RE.exec(String(tok || '')); if (!m) return null;
|
||||
const t = await byRef(m[1]); if (!t) return null;
|
||||
const want = sig(t);
|
||||
return want.length === m[2].length && crypto.timingSafeEqual(Buffer.from(want), Buffer.from(m[2])) ? t : null;
|
||||
}
|
||||
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)); }
|
||||
// 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 });
|
||||
return { ticket: Object.assign(pubTicket(t), { unread: false, name: t.name }), messages: (await impl().messages(t.id, false)).map(pubMsg) };
|
||||
}
|
||||
async function adminList(f) {
|
||||
const q = { status: STATUSES.includes(f.status) ? f.status : '', platform: PLATFORMS.includes(f.platform) ? f.platform : '', category: CATEGORIES.includes(f.category) ? f.category : '', q: oneLine(f.q, 80), limit: 300 };
|
||||
return { tickets: await impl().list(q), counts: await impl().counts() };
|
||||
}
|
||||
async function adminView(id) {
|
||||
const t = await impl().getTicket(id); if (!t) return null;
|
||||
if (t.adminUnread) await impl().updateTicket(t.id, { adminUnread: false });
|
||||
return { ticket: Object.assign(t, { adminUnread: false }), messages: await impl().messages(t.id, true), link: linkFor(t) };
|
||||
}
|
||||
const counts = () => impl().counts();
|
||||
|
||||
// inbound mail (next step): thread a reply or open a ticket. Returns { ok, ticket, message, created }.
|
||||
async function ingestEmail(e) {
|
||||
const from = lc(e.from);
|
||||
const mid = e.messageId ? String(e.messageId).trim().slice(0, 250) : null;
|
||||
const refs = [e.inReplyTo].concat(String(e.references || '').split(/\s+/)).map(x => String(x || '').trim()).filter(Boolean);
|
||||
let ticketId = refs.length ? await impl().byMessageId(refs) : 0;
|
||||
if (!ticketId) { const r = parseRef(e.subject); if (r) { const t = await byRef(r.ref); if (t && t.email === from) ticketId = t.id; } }
|
||||
const body = clean(e.text, 5000);
|
||||
if (ticketId) { const r = await addMessage(ticketId, { author: 'member', body, emailMessageId: mid, via: 'email' }); return Object.assign(r, { created: false }); }
|
||||
const r = await create({ platform: e.platform || 'iap', source: 'email', email: from, name: e.name, subject: oneLine(e.subject, 140) || '(no subject)', category: 'Other', body, emailMessageId: mid, via: 'email', confirm: !!e.confirm });
|
||||
return Object.assign(r, { created: true });
|
||||
}
|
||||
|
||||
module.exports = { init, CATEGORIES, STATUSES, PRIORITIES, PLATFORMS, SOURCES, DEFAULT_TEMPLATES, refOf, parseRef, tokenFor, linkFor,
|
||||
create, addMessage, setFields, byRef, byToken, memberList, memberUnread, memberView, adminList, adminView, counts, ingestEmail };
|
||||
Reference in New Issue
Block a user