Files
linkspin/chatbot.js
T

238 lines
50 KiB
JavaScript

// 24/7 site assistant: canned answers first for the questions everyone asks, OpenRouter AI for everything else,
// hard honesty rules baked into the system prompt.
//
// Rewritten for LinkSpin 2026-10-10 (the earlier copy still described InstantAdPay: holding-tank rescue, surf earn tab,
// Five Dollar Friday, the $25 ladder). Every fact below was checked against this repo: rotator.js, pages.js,
// pagestyle.js, zones.js, audiences.js, ads.js, registry.js, carry.js, the Control Room screens and the public pages.
//
// HOUSE RULE: whenever a site feature changes, update BOTH the CANNED answers and FACTS below in the same commit.
// Plain words, no em dashes, never a promise of income.
//
// KNOWLEDGE BASE (2026-10-20, kb.js): CANNED below and kb-seed.js SEED the knowledge base, which is the one
// source the assistant answers from. Each CANNED regex becomes its entry's instant-answer pattern (same order,
// first match wins), and for everything else the best-matching entries go into the system prompt. Admin >
// Knowledge base edits entries; an edited entry is no longer refreshed from the code. If the KB store fails,
// the in-code CANNED list still answers.
const { SITE_HOST, SITE_URL } = require('./host');
const fs = require('fs');
const path = require('path');
const https = require('https');
const http = require('http');
const kb = require('./kb');
const kbSeed = require('./kb-seed');
let DATA_DIR = null;
let chain = null;
const MODEL = process.env.OPENROUTER_MODEL || 'deepseek/deepseek-v4-flash:nitro';
const CONTRACT = '0x26Bdc556b94399bEdd69ae3ACA5aA6c54D946e8b';
// TODO(level-4 override, 2026-10-23): at go-live add the CANNED entry + FACTS line drafted in D:/tmp/override-copy/linkspin-override-copy.md (section 2), and bump KNOWLEDGE_DATE only in that deploy.
const KNOWLEDGE_DATE = '2026-10-23'; // the day the CANNED answers and FACTS below were last checked against the site
function init(opts) { DATA_DIR = opts.dataDir; chain = opts.chain; return kb.init({ dataDir: DATA_DIR, seeds: seeds() }); }
function key() {
if (process.env.OPENROUTER_API_KEY) return process.env.OPENROUTER_API_KEY.trim();
try { return fs.readFileSync(path.join(DATA_DIR, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; }
}
function enabled() { return !!key(); }
// ---- canned answers: instant, free, always in voice. Order matters: the first regex that matches wins. ----
// handoff: true makes the widget offer "Send this to support" under the answer (help desk, 2026-10-16)
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 linkspin|someone|a (human|person|real person))|support (email|address|ticket|team|desk|page)|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 = [
{ id: 'support', title: 'Contact support or open a ticket', q: ['How do I contact support?', 'How do I talk to a real person?', 'How do I open a ticket?'], tags: ['support', 'help', 'ticket', 'contact'],
re: SUPPORT_RE, handoff: true,
a: 'Open Help in your Control Room (' + SITE_URL + '/help) to send Marty a ticket, and his replies land right there and in your email. Not signed in or locked out? Use ' + SITE_URL + '/support. You can also tap "Send this to support" below and I will pass this chat along.' },
// Banner Spin (2026-10-20), ahead of the ad-editing and spin-link answers, which also match "banner" and "rotate"
{ id: 'banner-spin', title: 'Banner Spin: one image link that rotates your banners', q: ['What is Banner Spin?', 'How do I rotate several banners in one ad slot?', 'Who gets Banner Spin?'], tags: ['banner spin', 'banners', 'rotator', 'traffic exchange'],
re: /banner ?spins?\b|rotat\w* (my |several |multiple |many |a few |\d+ )?banners|banners? rotat|(one|single) (image|banner) (url|address|link)/i,
a: 'Banner Spin gives you one image address and one click address that rotate up to 25 banners, each with its own target page or spin link, so one banner slot on a traffic exchange, safelist, forum or your own site carries a whole campaign. It is a free add-on that opens with your own package of $25 or more: Starter holds 2 Banner Spins of 5 banners, Builder (level 2 open, 2 qualifying buyers) 5 of 15, Leader (level 3 open, 5 qualifying buyers) 10 of 25. Build it under Links, Banner Spins (' + SITE_URL + '/links#b) and copy one of four embeds: the image + click pair for exchanges and safelists, the HTML snippet for your site, the script tag (it writes the banner and its own link, so every click matches exactly) or the forum code. A click goes to the banner that visitor saw; one we cannot match goes to your fallback. It will not rotate inside paid ad networks (they copy the image when you upload a creative) or in Gmail (its image proxy keeps one copy), so use a single-banner Banner Spin for email. The Stats tab and Reports show views, clicks, CTR, match rate and conversions per banner and per placement, a WINNER badge once two banners have 1,000 views each, and a CACHED flag on sites that copy banners. Every live banner is checked every 30 minutes and paused after three failed checks, never the last live one.' },
{ id: 'edit-ad', title: 'Edit an ad: link, image or text', q: ['How do I change the link on my ad?', 'Can I fix a typo in my ad?', 'How do I replace my banner image?'], tags: ['ads', 'edit', 'banner', 'campaign'],
re: /\b(fix|change|edit|update|correct|replace|wrong|broken|typo)\b.{0,40}\b(link|url|image|banner|picture|headline|text|name)\b.{0,30}\b(ad|ads|campaign|campaigns|banner)\b|\b(edit|fix|change|update) (my |an |the |this )?(ad|ads|campaign|banner|login ad|text ad)\b/i,
a: 'Open Ads in your Control Room (' + SITE_URL + '/ads) and press Edit on the ad. You can change where the click goes, the banner image (upload a new one or paste a link), the headline and line of a text ad, and the ad name. A login ad shows your page itself, so its link is the whole ad. The first edit of every ad is free, your one correction; each edit after that costs a small credit fee (100 credits at the moment, shown before you save), taken from earned credits first. The type, size, budget, countries, schedule and audience stay as they are; for those, start a new ad. A new link is checked the same way as a new ad, so it has to load and, for banner and text ads, allow framing.' },
{ id: 'login-ads', title: 'Login ad slots', q: ['How do login ads work?', 'How do I book a login ad?'], tags: ['login ad', 'slot', 'purchased credits'],
re: /(log ?-?in|sign ?-?in) (ad|ads|spot|sponsor|slot|slots)|(ad|sponsor) (on|at) (the )?(log ?-?in|sign ?-?in)/i,
a: 'A login ad is a slot: 1,000 purchased credits buys 30 days of your page, full screen, to every member right after they sign in, with unlimited sign-in impressions and nothing charged per day. At most 6 member slots run at once because they share the same sign-ins. When all 6 are taken you can reserve the next one from the same place: you pay the 1,000 purchased credits now to get your place in line, first paid first served, and your 30 days start the moment a slot frees up (we tell you on the site and by email). The Ads screen shows your place and an estimated start date, which is only an estimate. While you wait you can edit the ad for free, and if you cancel before it starts you get the full 1,000 credits back. A paused slot can only resume when nobody is waiting, because a freed slot goes to the line first. Login ads spend purchased credits only, so earned credits go to banner and text ads instead. Buy or reserve one from Ads, New ad, Login ad.' },
{ id: 'vs-iap', title: 'LinkSpin and InstantAdPay: the difference', q: ['What is the difference between LinkSpin and InstantAdPay?', 'Is this the same as InstantAdPay?', 'Why another site?'], tags: ['instantadpay', 'iap', 'sister site', 'network'],
re: /(instant ?ad ?pay|[^a-z]iap[^a-z]|differen|same as|another (site|program|property)|why (two|another)|sister (site|property)|which (one|site) (should|do))/i,
a: 'InstantAdPay is the ad marketplace: you buy ad packages there, earn credits by viewing ads, and get paid when your line buys. LinkSpin is the tool side of the same network: a link rotator, a page builder and ad zones for your own sites, free with an email address. Its packages buy ad delivery across the LinkSpin viewer, every member zone and the partner network, and they pay your sponsor line the same way, inside the purchase transaction. Same people above and below you, same wallet, and your InstantAdPay username and profile carry over when you sign in with the same email.' },
{ id: 'pyramid', title: 'Is this a pyramid or a scam?', q: ['Is this a pyramid scheme?', 'Is LinkSpin legit?', 'Is this an MLM?'], tags: ['pyramid', 'scam', 'legit', 'mlm'],
re: /(pyramid|ponzi|scam|scheme|mlm|legit)/i,
a: 'Fair question. A pyramid pays for recruiting with no product. LinkSpin sells advertising: an ad package buys real ad delivery (banner, text and login ads across the ad viewer, every member zone and the partner network), and the free tools, spin links, pages and zones, work with no purchase at all. The referral split is a fixed rule in a verified contract on Polygon, 50 percent to the direct sponsor, 20 to level 2, 10 to level 3 and 10 plus 10 to two admin wallets, paid in the same transaction as the purchase. Nobody is paid for recruiting without a sale, nothing is held, and no income is promised. Read the code and every payout yourself at ' + SITE_URL + '/contract and ' + SITE_URL + '/ledger.' },
{ id: 'withdraw', title: 'Withdrawals and cash out', q: ['How do I withdraw?', 'Where is my pending payout?', 'How do I cash out?'], tags: ['withdraw', 'cash out', 'payout'],
re: /(withdraw|cash ?out|payout request|minimum payout|pending (payment|payout|commission))/i,
a: 'There are no withdrawals here, ever. When someone in your line buys a package, the contract pays your share straight to your own wallet in the same transaction as the purchase, so there is nothing to request and nothing pending. Credits are the other thing you can have, and they never cash out: they only buy ad delivery.' },
{ id: 'split', title: 'How payouts work: the split', q: ['How do payouts work?', 'How much do I earn?', 'Where does the money go?'], tags: ['payout', 'split', 'commission', 'levels'],
re: /(how (do|does) (the )?payouts? work|how (much|do i|does one|can i) (earn|get paid|make)|commission|percent(age)?|the split|split (the|a) (package|purchase)|who gets paid|where does the money go)/i,
a: 'Every package splits the same way, in the same Polygon transaction it sells in: 50 percent to the direct sponsor, 20 percent to level 2, 10 percent to level 3, and 10 plus 10 percent to the two admin wallets. Level 1 pays you from your referral\'s very first qualifying purchase once your payouts are switched on. Level 2 opens after two of your people buy a qualifying package ($25 or larger; the $10 door does not count), level 3 after five. A level with no qualified member passes up the line to the next qualified person, then to the platform; nothing waits in a balance. Those numbers are constants in the verified contract at ' + SITE_URL + '/contract. No income is promised: nobody earns unless real ad buying happens in their line.' },
{ id: 'free-account', title: 'What a free account gets', q: ['What do free members get?', 'Is it free?', 'Do I have to buy anything?'], tags: ['free account', 'tools', 'credits'],
re: /(free member|free account|for free|without (a )?(wallet|buying|purchase)|do i (have|need) to (buy|pay|purchase)|what do (i|free members|members) get|what is free|is it free|costs? nothing)/i,
a: 'A free account gets the whole toolset: spin links (one short link that rotates every page you promote, with weights, a fallback and a report by source), the page builder (bridge, review and squeeze pages from a scan of any offer, leads to your own list), zones (an ad slot on your own site that pays ad credits per viewable impression), audiences (first-party retargeting), reports, promo tools and the blog. Free members earn ad credits by running zones, viewing the daily ad set, watching videos, making verified visits and signing in daily. Credits buy your own banner and text ads at one cent each and never cash out. POL, the real crypto, only ever reaches a wallet through the contract split when a package sells in your line, and you can switch payouts on without buying anything.' },
{ id: 'qualification', title: 'Qualification: levels 2 and 3', q: ['How do I unlock level 2?', 'How does qualification work?', 'What is a pass-up?'], tags: ['qualification', 'level 2', 'level 3', 'pass-up'],
re: /(qualif|unlock level|open level|level ?2|level ?3|pass.?up|two buyers|five buyers)/i,
a: 'Level 1, half of every package your direct referrals buy, pays from their first qualifying purchase once your payouts are on. Level 2 (20 percent) opens after two of your people buy a qualifying package, $25 or larger. Level 3 (10 percent) opens after five. The $10 door package is for trying the ads and does not count toward opening levels. Until a level opens, its share passes up the line to the next qualified member, then to the platform, and it never comes back, so leaders qualify before their teams\' teams buy. Qualification is counted by the contract, never expires and cannot be bought.' },
{ id: 'zones', title: 'Ad zones on your own site', q: ['What is an ad zone?', 'How do I put ads on my website?', 'What sizes are the zones?'], tags: ['zones', 'publisher', 'embed', 'website'],
re: /(what('s| is) (a |an )?(ad )?zone|zones?\b|embed|script tag|publisher|site owner|my (own )?(web)?site|ad slot|viewable)/i,
a: 'A zone is an ad slot on your own site: one script tag, nine standard sizes (728x90, 468x60, 300x250, 336x280, 250x250, 125x125, 160x600, 120x600, 320x50). Each load shows a LinkSpin member campaign first, then a network ad, then our house banner if nothing paid fits. You earn ad credits per viewable impression (half the banner on screen for one second, bots never, 50 credited views per visitor per zone per day): 1 credit per 5 viewable member-ad views and 1 per 10 network-ad views, or 1 per 8 on a Verified zone the admin has reviewed. A new zone earns after its first 100 on-site views with at least 40 percent viewable, and paid ads serve only on the site you declared, so copying the tag elsewhere earns nothing. Everything is explained at ' + SITE_URL + '/publishers and you add zones under Zones in your Control Room.' },
{ id: 'sources', title: 'Traffic sources and postbacks', q: ['How do I track traffic I buy?', 'How do postbacks work?', 'Can I use PropellerAds or Zeropark?'], tags: ['sources', 'postback', 'paid traffic', 'ad network'],
re: /(traffic ?sources?|postback|macros?|propeller ?ads|zeropark|adsterra|exoclick|hilltop ?ads|rich ?ads|traffic ?stars|pop ?ads|campaign url|buy(ing)? traffic|paid traffic|ad network|s2s|conversion (pixel|tracking))/i,
a: 'Sources, in your Control Room, is for traffic you buy on networks like PropellerAds, Zeropark, Adsterra or ExoClick. Pick the network from the catalog (or define your own), fill in your account details, and the source remembers that network\'s macros and conversion postback. Point a spin link at it and the Share kit gives you the exact campaign URL to paste into the network, macros included. When a click from that source joins, leaves a lead, links a wallet or buys, LinkSpin fires the network\'s own postback with its click id, so the network learns what converts, and Reports breaks clicks and conversions down by source and by the zone or placement the macro carried. The older account-level Postbacks on the Links screen still work for your tracker.' },
{ id: 'spin-links', title: 'Spin links (the rotator)', q: ['What is a spin link?', 'How do weights and the fallback work?', 'How do I rotate my links?'], tags: ['spin link', 'rotator', 'short link', 'weights'],
re: /(spin ?link|rotat|short link|one link|weights?|fallback|split test|sub ?id|click ?id|daypart|health check|dead link|redirect)/i,
a: 'A spin link is one short link that rotates between every page you promote. Behind it you set destinations with weights, pause any of them, and name a fallback for when everything else is off. Every click is recorded in one hop with the day, country, source and device, bots are filtered on the server, and click ids and sub ids (clickid, subid, s1 to s4 and the usual tracker names) ride through to the destination, so you can split-test by tagging the same link with different sub ids. Reports show it per link and across all of them. Set the hours of the day and week a spin or a destination runs (the local time of your visitor by default), and automatic health checks pause a dead or parked destination for you. You can try a spin with no account on the home page.' },
{ id: 'pages', title: 'The page builder', q: ['How do I build a bridge page?', 'Can I make a squeeze page?', 'Where do my leads go?'], tags: ['pages', 'page builder', 'bridge page', 'leads'],
re: /(page builder|bridge page|squeeze page|review page|sales page|advertorial|press release|landing page|build (a|me a) page|my pages?|lead capture|leads?\b)/i,
a: 'Pages is the built-in page builder. Paste the address of any offer you promote, LinkSpin scans its headline and points, you add your angle, and you get a bridge, review or squeeze page with your own leads list (CSV or webhook), published on LinkSpin\'s pages domain, lookfirst.page. Pick a design, palette and layout, or a niche preset that sets them for you with a matching hero image. Put the page behind a spin link to send traffic by weight. Sales, advertorial and press-release layouts are on the way. Open Pages in your Control Room; it is free.' },
{ id: 'audiences', title: 'Audiences and retargeting', q: ['How does retargeting work?', 'What is the pixel?', 'Can I show ads only to my visitors?'], tags: ['audiences', 'retargeting', 'pixel'],
re: /(audience|retarget|pixel|p\.js|my visitors|show only to|never show to)/i,
a: 'Audiences is first-party retargeting. Everyone who views your LinkSpin pages or your zones lands in "My visitors" for 30 days with no setup, and for any other site you control you paste a small pixel tag (/p.js). Then, on any banner or text campaign, choose "show only to" or "never show to" an audience. The match uses a LinkSpin cookie with a 24-hour fallback where browsers block cross-site cookies, and nothing personal is stored. It lives on the Zones screen.' },
{ id: 'promo-tools', title: 'Promo tools', q: ['What is in Promo tools?', 'Where are the swipes and banners?'], tags: ['promo tools', 'social posts', 'swipes', 'banners'],
re: /(promo tools?|social posts?|email swipes?|banners? (kit|set)|text a friend|objection|hook videos?|angle (link|video|page)|share buttons?)/i,
a: 'Promo tools (' + SITE_URL + '/tools#promo) holds everything personalised with your invite link: social posts, text-a-friend messages, email swipes, banners in the standard sizes, an objection-handling bank with honest replies, and the hook videos. There are five hook angles, each with its own join page and video: links (stop juggling links), pages (a bridge page in a minute), zones (your site pays you), audiences (reach your visitors again) and stack (the three tools, free). An angle link is your normal link with ?v= on the end, so every join and purchase still credits you.' },
{ id: 'blog', title: 'The blog', q: ['Is there a blog?', 'Where are the articles?'], tags: ['blog', 'articles'],
re: /\bblog\b|articles?|read more/i,
a: 'The blog at ' + SITE_URL + '/blog has Marty\'s articles on building a line, advertising that pays and daily habits. Each article has its own page you can share, and there is an RSS feed at /blog/feed.xml.' },
{ id: 'packages', title: 'Packages and prices', q: ['How much are the packages?', 'What does the $10 door package do?', 'Which package should I buy?'], tags: ['packages', 'price', 'credits', 'qualification'],
re: /(price|cost|packages?|how much is|ladder|\$10|\$25|\$50|\$100|\$250|\$500|door package)/i,
a: 'Six packages, priced in dollars and settled in POL at the live rate: the $10 door (1,000 credits, for trying the ads; it does not count toward qualification), $25 Starter (2,500), $50 Builder (5,000), $100 Growth (10,000), $250 Leader (25,000) and $500 Network (50,000). One credit is one cent of ad delivery. Any package of $25 or more makes you a qualifying buyer for your sponsor. Buy under Credits in your Control Room; the live ladder is on the home page.' },
{ id: 'credits', title: 'What credits are and how you get them', q: ['What is a credit?', 'How do I get credits?', 'What am I buying?'], tags: ['credits', 'ad delivery', 'impressions'],
re: /(credits?|impression|cpm|what do i get|what am i buying|one cent|1 cent)/i,
a: 'One credit is one cent of ad delivery: banner, text and login ads shown across the LinkSpin ad viewer, every member zone and the partner network, managed from the Ads screen. Credits come two ways, bought in a package or earned free (zones, the daily ad set, videos, verified visits, daily sign-in). Earned credits spend on banner and text campaigns; a login-ad slot (1,000 purchased credits for 30 days) takes purchased credits only. Credits are advertising, not money: they never cash out and are never converted to crypto.' },
{ id: 'trust-drain', title: 'Trust Wallet "drain your wallet" warning', q: ['Trust Wallet says this will drain my wallet', 'My wallet blocked the purchase'], tags: ['trust wallet', 'drain', 'wallet warning'],
re: /(drain (my|your) wallet|stop and go back|trust wallet.*(warn|block|red)|wallet (warning|blocked))/i,
a: 'That red "this transaction will drain your wallet" screen is Trust Wallet\'s own safety rule, not a problem with the purchase: it blocks any transaction that spends most of the POL in the wallet. Ways through: buy a smaller package first, add some POL so the purchase is well under half the balance, or connect a different wallet. SafePal, MetaMask and Phantom have no such block. Extra POL always stays yours. If the next try says WalletConnect disconnected, open the Wallet screen, disconnect, then connect again.' },
{ id: 'wallets', title: 'Which wallet, and buying POL with a card', q: ['Which wallet should I use?', 'How do I buy POL with a card?', 'I have never owned crypto'], tags: ['wallet', 'safepal', 'metamask', 'moonpay', 'buy pol'],
re: /(which wallet|what wallet|best wallet|recommended wallet|set ?up (a )?wallet|buy (pol|crypto|polygon)|get (pol|crypto)|moonpay|card to crypto|no crypto|never (had|held|owned) crypto|metamask|safepal|phantom|coinbase wallet)/i,
a: 'SafePal is the recommended wallet; MetaMask, Phantom (turn Polygon on first under Settings, Active Networks) and any WalletConnect wallet work too. Trust Wallet works but blocks a purchase that spends most of its POL, so keep about double the package cost there. Never held crypto? Link your wallet, open Credits and tap Buy POL with a card: MoonPay opens with POL on Polygon and your own address filled in, you pay by card, Apple Pay or Google Pay (the first time needs an ID check), the POL lands in your wallet in minutes, then you buy the package. Keep a little extra POL for network fees.' },
{ id: 'join', title: 'How to join and sign in', q: ['How do I join?', 'Do I need a wallet?', 'Is there a password?'], tags: ['join', 'sign up', 'sign in', 'code'],
re: /(need (a )?wallet|crypto experience|how (do i|to) (join|sign ?up|register|sign in)|sign ?up|register|password|sign.?in code|six.?digit)/i,
a: 'Join free with just your email at ' + SITE_URL + '/join. A six-digit code signs you in, there is no password, and no wallet is needed to use the links, pages and zones. The wallet step comes later, inside your Control Room, when you want to be paid or to buy a package.' },
{ id: 'referral-link', title: 'My invite link', q: ['Where is my referral link?', 'How do I invite people?'], tags: ['referral', 'invite link', 'promo tools'],
re: /(referral link|invite link|share link|join link|my link|refer(ring)? (people|friends|someone))/i,
a: 'Your invite link is live the moment you sign in, free members included: ' + SITE_HOST + '/join/yourname. Promo tools lists it with the five angle versions (links, pages, zones, audiences, stack), each with a video and Copy and Share buttons; they are the same link with ?v= on the end, so every join and purchase credits you. One tip: switch on payouts (Credits screen, one transaction, no purchase needed) before your people start buying, because the contract locks each buyer to their sponsor at their first purchase.' },
{ id: 'sponsor', title: 'Who is my sponsor; wrong sponsor; carry-over', q: ['I joined under the wrong sponsor', 'Who is my sponsor?', 'Is my InstantAdPay sponsor carried over?'], tags: ['sponsor', 'carry-over', 'registry', 'invite link'],
re: /(wrong sponsor|who is my sponsor|which sponsor|sponsor (cookie|link|credit|carr)|carry.?over|clicked (someone|another|two).*link|last (link|click)|first (link|click|touch)|change (my )?sponsor|same (team|sponsor|upline)|registry)/i,
a: 'The invite link you opened most recently sets your sponsor, and the join page shows who you are joining under. It locks when you create your account, and your first purchase binds you to that sponsor on the contract. Crypto Team Build Network members who sign in with the email they use on InstantAdPay get their sponsor carried over automatically from the network registry when no invite link was used, so the same people are above you here. Already joined under the wrong sponsor by mistake? Message support before your first purchase and the admin can move you.' },
{ id: 'activation', title: 'Switching on payouts', q: ['How do I switch on payouts?', 'How do I link my wallet?', 'How do I activate?'], tags: ['activation', 'payouts', 'link wallet'],
re: /(activat|switch(ed)? on payouts|payouts (on|off)|turn on payouts|get paid to my wallet|link (my |a )?wallet)/i,
a: 'Payouts switch on when your wallet is registered on the contract. That happens two ways: buy any package, or use the free activation on the Credits screen, one transaction that costs only network gas. First link the wallet that should receive your payouts (one signature, no transaction), then activate. From then on the contract pays your share of every qualifying purchase in your line straight to that wallet. Buying is never required to be paid at level 1; a $25 or larger package is what makes you a qualifying buyer for your own sponsor and funds your own ads.' },
{ id: 'pol-only', title: 'Which coin and network: POL on Polygon', q: ['Which crypto do you use?', 'What network is this on?', 'Is it MATIC?'], tags: ['pol', 'polygon', 'crypto', 'network'],
re: /(which|what) (crypto|coin|token|currency|chain|network)|paid in what|get paid in|\bpol\b|polygon|matic/i,
a: 'One coin, one network: POL, the native coin of Polygon. Packages are priced in dollars and settled in POL at the live rate, and every payout arrives as POL in your own Polygon wallet in the same transaction. No other coins, tokens or chains are used. Send POL on the Polygon network, never MATIC on Ethereum.' },
{ id: 'control-room', title: 'The Control Room screens', q: ['Where do I find my links?', 'What is on the dashboard?', 'Which screen has my campaigns?'], tags: ['control room', 'dashboard', 'menu', 'tools'],
re: /(control room|dashboard|where (do|can) i (find|see)|which screen|menu|navigation|more tools|\/tools)/i,
a: 'Your Control Room has these screens: Links (spin links), Pages (the page builder), Zones (ad slots on your site plus Audiences), Ads (your campaigns and the daily ad set), Credits (buy packages, link your wallet, switch on payouts), Reports (every link in one view), Team (your line, three levels) and Wallet (what was paid to you). More, at ' + SITE_URL + '/tools, holds Promo tools, Training, the Pipeline follow-up board, My line and your Profile.' },
{ id: 'holding-tank', title: 'Holding tank and adoptions', q: ['What is the holding tank?', 'How do I adopt a member?'], tags: ['holding tank', 'adopt', 'no sponsor'],
re: /(holding tank|adopt|no sponsor|without a sponsor|orphan)/i,
a: 'Members who join from the public site with no sponsor wait in the holding tank under More, My line. A member who has switched on payouts and bought their own qualifying package can adopt one, first come, with a 7-day window for the new member to link a wallet or buy; otherwise they return to the tank. Adopting sets the sponsor, and their first purchase then binds to the adopter on the contract.' },
{ id: 'team', title: 'My line: the Team screen', q: ['How do I see my downline?', 'Who is in my team?'], tags: ['team', 'my line', 'downline', 'levels'],
re: /(my line|downline|my team|who (is|are) (in|on) my|three levels|level 1\b)/i,
a: 'Team shows your line as a working table, three levels deep: who joined through your link, who has switched on payouts, who has bought, and how many qualifying buyers each person has. The chip count is what opens your levels: two qualifying buyers ($25 or larger) open level 2, five open level 3.' },
{ id: 'balance-rule', title: 'Why my balance went down', q: ['Why did my balance go down?', 'Where did my credits go?'], tags: ['balance', 'credits', 'campaigns'],
re: /(balance (went|going|keeps going) down|credits? (disappear|missing|gone|dropping|went down)|why (is|did) my (balance|credits)|in campaigns|set aside|reserved credits|available to spend)/i,
a: 'One rule: your available balance is what is not committed to a live campaign. When you start a campaign its whole budget is set aside right then, so Available drops once and then sits still while the ad runs; the budget spends down inside that campaign on the Ads screen, where you can see delivered views and what is left. A paused campaign keeps its unspent budget set aside so it can resume. Nothing is lost when a balance reads low while a campaign is live.' },
{ id: 'safe', title: 'Is it safe? Who holds the money?', q: ['Is this safe?', 'Can you run away with the money?', 'Who holds the funds?'], tags: ['safe', 'contract', 'custody', 'trust'],
re: /(safe|trust (you|this|the site)|rug|run away|disappear|hold(s|ing)? (my|the) (money|funds))/i,
a: 'The money never touches us. A verified, immutable contract on Polygon splits every purchase in the same transaction, holds no balance, and has no pause switch or upgrade path. Credits live on the platform and are advertising, not money. Read the plain-language review and the verified source at ' + SITE_URL + '/contract, and watch every payout land at ' + SITE_URL + '/ledger.' }
];
// CANNED + the FAQ seeds, in the shape kb.js stores (order keeps the first-match-wins sequence)
function seeds() {
return CANNED.map((c, i) => ({ id: 'c-' + c.id, title: c.title, questions: c.q || [], answer: c.a, tags: c.tags || [], pattern: c.re.source,
handoff: !!c.handoff, order: (i + 1) * 10, source: 'canned' })).concat(kbSeed.FAQ);
}
// ---- facts for the AI fallback ----
function systemPrompt(kbBlock) {
return `You are the assistant on LinkSpin (${SITE_URL}), a link rotator, page builder and advertising network for marketers, a Crypto Team Build Network property.
FACTS:
- PRODUCT, all free with an email account: SPIN LINKS (the rotator: one short link, /r/<code>, rotates between destinations by weight; pause any destination; a fallback for when all are off; one-hop redirect; every click recorded with day, country, source, device and a daily-salted visitor hash; bots filtered on the server; click ids and sub ids such as clickid, subid, s1 to s4 pass through to the destination; split tests by tagging the same link with different sub ids; a demo spin on the home page needs no account; DAYPARTING is live: a 7x24 hours grid per spin and per destination, time zone by name or the local time of the visitor, presets, and 'my best hours' from the clicks of the member after 200 clicks; automatic HEALTH CHECKS are live: every destination is checked every 30 minutes, a dead or parked one is paused after three failing checks and resumed when it passes twice, the owner is told once, and Check now runs it on demand). PAGES (page builder: scan any offer URL, get a bridge, review or squeeze page; designs, palettes, layouts and niche presets with hero images; leads to the member's own list, CSV or webhook; published on the pages domain lookfirst.page; sales, advertorial and press-release layouts are coming). ZONES (an ad slot on the member's own site: one async script tag, nine sizes 728x90, 468x60, 300x250, 336x280, 250x250, 125x125, 160x600, 120x600, 320x50; waterfall = LinkSpin member campaign, then a network ad for 728x90 and 468x60, then the LinkSpin house banner; pays ad credits per VIEWABLE impression, half the banner on screen for one second, bots never, 50 credited views per visitor per zone per day; rates 1 credit per 5 viewable member-ad views and 1 per 10 network-ad views, 1 per 8 on a Verified zone; warm-up: a zone earns after its first 100 on-site views with at least 40 percent viewable and goes on hold below that; origin lock: paid ads serve only on the declared site and its subdomains, elsewhere the house banner shows and nothing is earned; up to 50 zones per account; PUBLISHER PROGRAM at /publishers for site owners, tiers Standard (default) and Verified (admin-reviewed site, better network rate)). AUDIENCES (first-party retargeting: "My visitors" collects everyone who viewed the member's pages and zones for 30 days; a pixel tag /p.js for other sites; campaigns can "show only to" or "never show to" an audience; nothing personal stored). PROMO TOOLS at /tools#promo (social posts, text-a-friend, email swipes, banners, objection bank, hook videos; five hook angles with videos: links, pages, zones, audiences, stack; angle links are the invite link plus ?v=). REPORTS (every link in one view, plus Pages, Zones, and since 2026-10-12 Traffic sources and Placements). BLOG at /blog with RSS at /blog/feed.xml. TRAFFIC SOURCES at /sources (2026-10-12): a source is a record of a network the member buys traffic on, created from a catalog of networks (PropellerAds, Zeropark, Adsterra, ExoClick, HilltopAds, TrafficStars, PopAds and more, with each network's macro tokens and conversion postback URL; account-specific slots such as a goal id are filled in at creation) or defined by hand; a spin link is pointed at one source (Share kit on the Links screen, or the Sources screen), and then the Share kit's first row is the exact campaign URL for that network with its macros already in place; when a click that came through that source converts (join, lead, wallet, purchase, or a partner-reported conversion; the member picks which) LinkSpin fires that network's own postback with the network's click id and the payout, server to server, and only the network that sent the click is told; Reports show clicks, uniques and conversions by source and by placement (the value the network's zone, placement, site, campaign, creative, banner or keyword macro carried); up to 30 sources per account, 20 params each; a source with no postback still builds the campaign URL and shows in Reports; the account-level Postbacks list on the Links screen (for the member's own tracker) still works alongside. Knowledge checked on ${KNOWLEDGE_DATE}.
- TOOL LIMITS BY TIER (2026-10-21): spin links and pages each: Free (no package) 3, Starter (any package of your own) 10, Builder (level 2 open, 2 qualifying buyers) 50, Leader (level 3 open, 5 qualifying buyers) unlimited (fair use). Each spin link rotates up to 25 destinations at every tier; clicks are unlimited. Nothing already made is ever removed when a cap applies; new ones wait for the upgrade. Banner Spin has its own ladder (Starter 2 x 5, Builder 5 x 15, Leader 10 x 25). Other limits, same for everyone: 50 zones, 20 audiences, 20 postbacks, 5 linked positions.
- BANNER SPIN (LIVE 2026-10-18, reports and health checks 2026-10-20): one image address (/i/<code>.gif on a link domain) and one click address (/c/<code>) that rotate up to 25 banners, each with its own target (any https page or one of the member's spin links), weights 1 to 100, random by weight on every view or one banner per visitor per day, the dayparting grid per Banner Spin and per banner, pause, a fallback page and an optional fallback banner image, and a traffic source so its conversions fire that network's postback. Built on the Links screen (${SITE_URL}/links#b). WHO GETS IT: a free add-on for members with their own package of $25 or more; tiers: Starter 2 Banner Spins x 5 banners, Builder (level 2 open, 2 qualifying buyers) 5 x 15, Leader (level 3 open, 5 qualifying buyers) 10 x 25; dropping below a tier keeps everything serving, it only stops new ones. One size per Banner Spin (468x60, 728x90, 300x250, 125x125, 160x600, 120x600, 336x280, 250x250, 320x50); JPG, PNG or GIF (animated is fine), 150 KB at most, uploads count toward the 10 files a day. EMBEDS: the image + click pair (traffic exchanges, safelists, downline builders), an HTML snippet (own sites, blogs, HTML email), a script tag (writes the banner and its own link, so every click matches exactly) and forum BBCode; every link domain answers every code. MATCHING: with the pair, the server remembers which banner a visitor saw on which page for 15 minutes and sends the click there; an unmatched click goes to the fallback. LIMITS: paid ad networks (Froggy, PropellerAds and the like) copy the image at upload, so it freezes on one banner there; Gmail and some mail apps fetch images through a caching proxy, so email readers mostly see one banner and clicks fall back: use a single-banner Banner Spin for email. REPORTS: per banner and per placement views, unique viewers (daily sample), clicks, CTR, match rate and conversions, by Central day, country and device, bots and server loads shown separately and never counted; a WINNER badge once two or more live banners have 1,000 views each and one leads on click rate (LinkSpin never changes weights by itself); a CACHED flag on a placement that copies banners to its own server; totals also on the Reports screen. HEALTH: every 30 minutes each live banner's image must load as an image of the right size and its target must pass the spin-link checks (dead, parked, slow); three failures in a row pause that banner, two clean passes resume it, the last live banner is never auto-paused, and the status shows on each banner row.
- PACKAGES (priced in dollars, settled in POL at the live rate, 1 credit = 1 cent of ad delivery): $10 door = 1,000 credits, for trying the ads, does NOT count toward qualification; $25 Starter = 2,500; $50 Builder = 5,000; $100 Growth = 10,000; $250 Leader = 25,000; $500 Network = 50,000. Any package of $25 or more makes the buyer a qualifying buyer for their sponsor.
- THE SPLIT, same transaction on Polygon, fixed in the contract: 50 percent direct sponsor, 20 percent level 2, 10 percent level 3, 10 percent + 10 percent to the two admin wallets. Level 1 pays from a referral's first qualifying purchase once the sponsor's payouts are on. Level 2 opens after two of the member's people buy a qualifying ($25 or larger) package, level 3 after five. An unfilled tier passes up the line to the next qualified member, then to the platform. Nothing is held, there are no withdrawals, no pending balances. Contract ${CONTRACT} on Polygon, verified on Polygonscan; plain-language review at ${SITE_URL}/contract; live ledger at ${SITE_URL}/ledger with a verify link on every row.
- CREDITS VS POL: every member, free ones included, earns CREDITS (zones, the daily ad set with a claim streak, watch-to-earn videos, verified visits, a daily sign-in bonus). Credits buy the member's own banner and text ads (a login-ad slot takes purchased credits only) and NEVER cash out or convert to crypto. POL only reaches a wallet through the contract split when a package sells in the member's line. Never promise or estimate income.
- AD FORMATS members buy with credits: banner ads (standard sizes), text ads, full-screen login ads (a flat slot: 1,000 PURCHASED credits for 30 days of unlimited sign-in impressions, never charged per day; at most 6 member slots live at once (raised from 3 on 2026-10-23); PAID QUEUE (2026-10-23): when all 6 are taken a member can reserve the next slot by paying the full 1,000 purchased credits now, first paid first served, the 30 days start only when a slot frees (a slot ends or is paused) and the member gets an on-site notice and an email, the Ads screen shows the place in line and an ESTIMATED start date in Central time, edits are free while waiting, cancelling before the start refunds the full amount as purchased credits (a running slot is not refundable), and a paused slot can resume only when live plus waiting slots are under 6; house login ads only show when no member slot is running; earned credits never fund login ads); EDITING AN AD (2026-10-18): the Edit button on each ad on the Ads screen changes the click link, the banner image (upload or https link), a text ad's headline and line, and the ad name; type, size, budget, countries, schedule and audience cannot change (start a new ad); the first edit of every ad is free, each later edit costs the campaignEditFee, 100 credits by default, earned credits first, then purchased; a new link and a new banner image get the same checks as a new ad, plus solo ads to member inboxes, watch-to-earn video, verified visits. Banner and text ads also run on member zones and the partner network.
- ACCOUNT: join at ${SITE_URL}/join with email only, a six-digit code, no password. Wallet linking happens inside the Control Room (Credits screen): one signature to link, then payouts switch on by activating (one transaction, gas only) or by buying any package. SafePal is the recommended wallet; MetaMask, Phantom (turn Polygon on first) and any WalletConnect wallet work; Trust Wallet blocks a buy that spends most of its POL. MoonPay card on-ramp from the Credits screen puts POL on Polygon into the member's own wallet.
- SPONSOR: the invite link opened most recently sets the sponsor (30-day cookie), shown on the join page, locked when the account is created; the contract binds the buyer to that sponsor at the first purchase. CARRY-OVER: Crypto Team Build Network members who sign in with the email they use on InstantAdPay get their InstantAdPay sponsor from the network registry automatically when no invite link was used. Wrong sponsor before the first purchase: the admin can move the account. Members should switch on payouts before their people buy.
- CONTROL ROOM screens: Links, Pages, Zones (with Audiences), Ads, Credits, Reports, Team (three levels, who has payouts on, who bought, qualifying-buyer counts), Wallet (what was paid to this wallet, payout history). More at ${SITE_URL}/tools: Promo tools, Training, Pipeline (a follow-up board for prospects and directs), My line (including the holding tank: members who joined with no sponsor wait there and can be adopted by a member with payouts on and their own qualifying package), Profile.
- PRE-LAUNCH (since 2026-10-17): LinkSpin is open to everyone for pre-launch testing until the official launch on November 15, 2026. Everything is live and working (links, sources, zones, ads, credits, payouts), but features and screens may change while it is tested. A notice at the top of every member screen says so. If someone got a reminder email about a member they have not contacted, they can ignore it: nothing changed in their line.
- SUPPORT (LIVE 2026-10-16): members open Help in the Control Room (${SITE_URL}/help) to send Marty a ticket (pick a category, a subject, the message), see each ticket's status (Open, Waiting on you, Closed), and read and answer his replies; a badge on the Help item shows when he has replied, and replies also arrive by email. Anyone signed out or locked out uses the public form at ${SITE_URL}/support, gets a private link to follow the ticket without signing in, and can reply there. The chat can also pass a conversation to support ("Send this to support"). Marty answers every ticket himself; there is no support email address, point people to ${SITE_URL}/support instead. Tickets share one desk with the rest of the Crypto Team Build Network.
- Leaderboard at ${SITE_URL}/leaderboard ranks members by packages sold to direct referrals (weekly, monthly, all time; prizes are credits, never cash). Release notes and roadmap at ${SITE_URL}/whats-new.
- InstantAdPay is the sister property in the same network, not this site: it is the ad marketplace (buy ad packages, earn credits by viewing ads, get paid when your line buys); LinkSpin is the tool side (rotator, page builder, zones), free with an email, whose packages buy ad delivery across the LinkSpin viewer, member zones and the partner network and pay the same sponsor line in the purchase transaction. Username, sponsor and profile (avatar, bio, social links) carry over when the member signs in with the same email, and can be changed here any time. Do not describe InstantAdPay mechanics (holding-tank rescue emails, Five Dollar Friday, Wired Wednesday, games, mint passes, surf earn tab) as LinkSpin features.
RULES:
- 1 to 4 sentences, plain text, no markdown, include full URLs when pointing at a page.
- 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 in their line.
- No em dashes. If you do not know, say so and point to ${SITE_URL}/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 ${SITE_URL}/help, or ${SITE_URL}/support when signed out.` + (kbBlock ? '\n\n' + kbBlock : '');
}
// OPENROUTER_URL overrides the endpoint (local tests point it at a mock); production uses openrouter.ai
function endpoint() {
try { return new URL(process.env.OPENROUTER_URL || 'https://openrouter.ai/api/v1/chat/completions'); } catch (e) { return new URL('https://openrouter.ai/api/v1/chat/completions'); }
}
function askAI(message, historyText, kbBlock) {
return new Promise((resolve, reject) => {
const body = JSON.stringify({
model: MODEL,
reasoning: { enabled: false }, // deepseek-v4-flash thinks by default and can spend the whole max_tokens on it (IAP, 2026-10-16)
max_tokens: 300,
messages: [
{ role: 'system', content: systemPrompt(kbBlock) },
...(historyText ? [{ role: 'user', content: 'Earlier context: ' + historyText.slice(0, 800) }] : []),
{ role: 'user', content: String(message).slice(0, 600) }
]
});
const ep = endpoint();
const req = (ep.protocol === 'http:' ? http : https).request({ hostname: ep.hostname, port: ep.port || undefined, path: ep.pathname + ep.search, method: 'POST',
headers: { Authorization: 'Bearer ' + key(), 'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body) }, timeout: 30000 },
res => {
let d = '';
res.on('data', c => d += c);
res.on('end', () => {
// OpenRouter can pad a slow upstream with keepalive lines before the JSON (IAP, 2026-09-17): find the object
const i = d.indexOf('{');
let txt = '';
try { txt = String(JSON.parse(i < 0 ? d : d.slice(i)).choices[0].message.content || '').trim(); }
catch (e) { return reject(new Error('openrouter ' + res.statusCode + ': ' + d.slice(0, 150))); }
if (!txt) return reject(new Error('openrouter ' + res.statusCode + ': empty content'));
resolve(txt);
});
});
req.on('error', reject);
req.on('timeout', () => req.destroy(new Error('openrouter timeout')));
req.end(body);
});
}
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|\/help\b)/i;
// every reply leaves without em dashes (Marty's voice rule; the model slips one in now and then, 2026-10-20)
async function answer(message, historyText) { const r = await answerRaw(message, historyText); if (r && typeof r.reply === 'string') r.reply = r.reply.replace(/\s*\u2014\s*/g, ', '); return r; }
async function answerRaw(message, historyText) {
const msg = String(message || '').trim();
if (!msg) return { error: 'Say something first.' };
// fast path: the knowledge base's instant answers (seeded from CANNED); the in-code list only if the KB store is down
let hit = null, kbOk = true;
try { hit = await kb.fastPath(msg); } catch (e) { kbOk = false; console.error('kb fast path', e.message); }
if (hit) return Object.assign({ reply: hit.answer, canned: true, kb: hit.id }, hit.handoff ? { handoff: true } : {});
if (!kbOk) for (const c of CANNED) if (c.re.test(msg)) return Object.assign({ reply: c.a, canned: true }, c.handoff ? { handoff: true } : {});
// retrieval: the closest entries ride along in the system prompt (a short follow-up borrows words from the chat so far)
let kbBlock = '', kbIds = [];
try {
const query = msg.split(/\s+/).length < 4 && historyText ? msg + ' ' + String(historyText).slice(-200) : msg;
const hits = await kb.context(query, 5);
kbBlock = kb.promptBlock(hits); kbIds = hits.map(h => h.entry.id);
} catch (e) { console.error('kb search', e.message); }
if (!enabled()) return { reply: 'Good question. The quick answers I have cover spin links, pages, zones, packages, the payout split, qualification and joining; for anything deeper, the plain-language contract review at ' + SITE_URL + '/contract covers most of it, or tap "Send this to support" and Marty will answer.', handoff: true };
// handoff: the answer admits it cannot help, so the widget offers "Send this to support"
try { const reply = await askAI(msg, historyText, kbBlock); return Object.assign({ reply }, kbIds.length ? { kb: kbIds } : {}, UNSURE_RE.test(reply) ? { handoff: true } : {}); }
catch (e) {
console.error('chat AI failed', e.message);
return { reply: 'I hit a snag answering that one. The contract review at ' + SITE_URL + '/contract and the live ledger at ' + SITE_URL + '/ledger cover most deep questions, or tap "Send this to support" and Marty will answer.', handoff: true };
}
}
module.exports = { init, answer, enabled, KNOWLEDGE_DATE, CANNED, seeds, systemPrompt };