Site assistant (Marty 2026-11-15): chat widget in the Downline Banners ultraviolet + lime look on every page, CANNED + FACTS from this repo's code and the BannerLine contract ($5 spot, 300 views in 30 days, 30% sponsor + 55% as $0.275 x 10 + 10% company + 5% momentum fund, fund buys after 4 h quiet, max 12 a day, 7-day gift cooldown, look-around tour, buy for someone, refuel spots, 468x60 up to 150 KB), retrieval over the shared network knowledge base on the hub (netkb.js, home entries boosted, another site named = its answer), reasoning off, account problems hand off to network support. Chat admin routes use a constant-time ADMIN_TOKEN check. chatbot.test 165, smoke 131/131
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ const refuelspots = require('./refuelspots'); // refuel spots: $50+ Monthly Refu
|
||||
const netsites = require('./netsites'); // footer network list from the hub (trust pack 2026-11-14)
|
||||
const tgproof = require('./tgproof'); // payment proof in the Telegram payments topic, one message per spot sale (2026-11-13)
|
||||
const hubreport = require('./hubreport'); // network hub, shadow mode: members reported by wallet (2026-11-13), off unless HUB_ENABLED
|
||||
const chatbot = require('./chatbot'); // the site assistant (2026-11-15): chatcore.js + kb.js + the network knowledge base (netkb.js)
|
||||
const promokit = require('./promokit'); // promo kit feed /api/promo-kit, the /promote page, /art/kit/* creatives (2026-11-14)
|
||||
const networksso = require('./networksso'); // network sign-in: arrive signed in from InstantAdPay or LinkSpin (2026-11-13), see networksso.js
|
||||
const SEL = { buy: iface.getFunction('buy').selector, buyFor: iface.getFunction('buyFor').selector }; // the browser builds calldata from these (ABI stays in abi.js)
|
||||
@@ -60,6 +61,9 @@ function readRaw(req, max) {
|
||||
req.on('data', c => { n += c.length; if (n > max * 8) { req.destroy(); return; } if (n <= max) ch.push(c); });
|
||||
req.on('end', () => n > max ? reject(new Error('too big')) : resolve(Buffer.concat(ch))); req.on('error', reject); });
|
||||
}
|
||||
// the chat knowledge-base admin routes: the same ADMIN_TOKEN header as the other admin routes, compared in constant time
|
||||
const chatAdmin = req => { const t = String(process.env.ADMIN_TOKEN || ''); const g = String(req.headers['x-admin-token'] || '');
|
||||
return t.length >= 8 && g.length === t.length && require('crypto').timingSafeEqual(Buffer.from(g), Buffer.from(t)); };
|
||||
async function readBody(req) { const b = await readRaw(req, 32 * 1024); try { return b.length ? JSON.parse(b.toString('utf8')) : {}; } catch (e) { return {}; } }
|
||||
function cookies(req) { const o = {}; for (const p of (req.headers.cookie || '').split(';')) { const i = p.indexOf('='); if (i > 0) { try { o[p.slice(0, i).trim()] = decodeURIComponent(p.slice(i + 1).trim()); } catch (e) {} } } return o; }
|
||||
function cookie(name, val, maxAgeSec, httpOnly) { return name + '=' + encodeURIComponent(val) + '; Path=/; SameSite=Lax; Max-Age=' + maxAgeSec + (httpOnly ? '; HttpOnly' : '') + (C.isProd ? '; Secure' : ''); }
|
||||
@@ -277,6 +281,7 @@ const server = http.createServer(async (req, res) => {
|
||||
// -- network sign-in (2026-11-13): /sso/start, /sso/in, /api/sso/status
|
||||
if (req.method === 'GET' && (p.startsWith('/sso/') || p === '/api/sso/status') && await networksso.handle(req, res, u)) return;
|
||||
if ((p === '/api/promo-kit' || p === '/promote' || p.startsWith('/art/kit/')) && promokit.handle(req, res, u, sendFile)) return;
|
||||
if ((p.startsWith('/api/chat') || p.startsWith('/api/admin/kb')) && await chatbot.handle(req, res, p, u, { json, readBody, isAdmin: chatAdmin })) return;
|
||||
|
||||
// -- pages
|
||||
if (req.method === 'GET' || req.method === 'HEAD') {
|
||||
@@ -595,6 +600,7 @@ function weekLine() {
|
||||
board.setMemberSpins(out);
|
||||
};
|
||||
setTimeout(() => refreshSpins().catch(() => {}), 20000); setInterval(() => refreshSpins().catch(() => {}), 10 * 60000).unref();
|
||||
chatbot.init(); // after docstore.init: kb.json is a MySQL document
|
||||
server.listen(C.port, () => console.log('Downline Banners on :' + C.port + ' chain ' + C.chainName + ' (' + C.chainId + ') contract ' + (C.contract || '(not set)') + ' store: ' + (docstore.isOn() ? 'MySQL documents' : 'volume JSON')));
|
||||
})().catch(e => { console.error('start failed:', e.message); process.exit(1); });
|
||||
process.on('SIGTERM', () => { store.flush(); process.exit(0); });
|
||||
|
||||
Reference in New Issue
Block a user