Help desk email intake: SendGrid Inbound Parse -> /api/inbound/email (secret key) creates tickets or threads replies; robots, bounces, auto-replies and our own mail dropped; ticket mail carries reply+<ref>@ reply-to and Auto-Submitted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-16 18:10:53 -05:00
parent 524ce843dc
commit ad17017250
4 changed files with 86 additions and 2 deletions
+11
View File
@@ -59,6 +59,7 @@ 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 inbound = require('./inbound'); // help desk email intake: SendGrid Inbound Parse -> tickets (2026-10-16)
const supportbot = require('./supportbot'); // @CTBTickets_bot: ticket pings with buttons + answering from Telegram (2026-10-16)
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)
@@ -533,6 +534,7 @@ async function 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 });
inbound.init({ tickets });
supportbot.init({ tickets, chatId: () => String(siteConfig().supportTelegramChat || '1289244227').trim(), site: 'https://instantadpay.com' });
badge.init({ publicDir: PUBLIC_DIR });
gamestats.init({ dataDir: DATA_DIR });
@@ -2112,6 +2114,15 @@ const server = http.createServer(async (req, res) => {
}
// -- help desk, public side (2026-10-16, tickets.js): /support form, the private no-login ticket link, the chatbot hand-off
if (p === '/api/inbound/email' && req.method === 'POST') { // SendGrid Inbound Parse: secret key in the URL, always 200 once it matches
const k = inbound.key();
if (!k || u.searchParams.get('k') !== k) { req.resume(); return json(res, 403, { error: 'forbidden' }); }
const chunks = []; let n = 0, tooBig = false;
await new Promise(done => { req.on('data', c => { n += c.length; if (n > 12e6) tooBig = true; else chunks.push(c); }); req.on('end', done); req.on('error', done); });
if (tooBig) { console.log('inbound email: too big, dropped'); return json(res, 200, { ok: true }); }
try { console.log('inbound email:', await inbound.handle(Buffer.concat(chunks), req.headers['content-type'])); } catch (e) { console.error('inbound email', e.message); }
return json(res, 200, { ok: true });
}
if (p === '/api/telegram/support' && req.method === 'POST') { // the support bot's webhook: secret header checked inside, always 200
let b = {}; try { b = await readBody(req); } catch (e) {}
try { await supportbot.handle(req, b); } catch (e) { console.error('supportbot', e.message); }