From d471a5664d9397e852c5d4ed669703d2e5b7cba2 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 17 Nov 2026 08:16:39 -0600 Subject: [PATCH] AI ad writer on text-ad campaigns (Marty 2026-11-17: "do it on the other sites too"): "Write my ad from my link" under the text ad fields asks the network hub (hubadwriter.js, POST /v1/adwriter, headline 60 / ad text 140) for 3 ads from the Target URL; GET/POST /api/my/adwriter; shown only when the hub says on; chatbot fact, KNOWLEDGE_DATE 2026-11-17; my.js?v=20261117aiw. iap-qa member 0 bugs, kb green Co-Authored-By: Claude Opus 5.5 --- chatbot.js | 3 ++- hubadwriter.js | 54 +++++++++++++++++++++++++++++++++++++++++ public/assets/my.js | 23 ++++++++++++++++++ public/my.html | 3 ++- qa/hubadwriter.test.mjs | 43 ++++++++++++++++++++++++++++++++ server.js | 14 +++++++++++ 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 hubadwriter.js create mode 100644 qa/hubadwriter.test.mjs diff --git a/chatbot.js b/chatbot.js index 2d27b59..9aea3be 100644 --- a/chatbot.js +++ b/chatbot.js @@ -50,7 +50,7 @@ function key() { function enabled() { return !!key(); } // ---- canned answers: instant, free, always in voice ---- -const KNOWLEDGE_DATE = '2026-11-15'; // bump whenever the canned answers / prompt are brought up to date +const KNOWLEDGE_DATE = '2026-11-17'; // 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 = [ // network sign-in (2026-11-12): signed in on one of InstantAdPay / LinkSpin = signed in on the other, no code (networksso.js) @@ -395,6 +395,7 @@ ${WEEKEND ? (() => { try { return WEEKEND.fact() || ''; } catch (e) { return ''; - WALL OWNERSHIP LADDER: the public wall has 3 positions. Position 1 = the member's line banner. Positions 2 and 3 show upline banners (then house ads) UNTIL the member earns them: 2 qualifying buyers ($20+) unlock position 2, 5 unlock position 3; a fully qualified member's wall is 100% their own links/offers (set in Profile > Your wall: label, https link, optional banner image). Empty unlocked slots fall back to upline banners, then house ads. - LINE BANNER (free, set in Profile): every member can set a destination URL (must allow framing) plus an optional banner image. It is shown to their next THREE levels of new members during welcome tours (position 1 for directs, 2, 3 below), and on their public BANNER WALL at /wall/ — a shareable page showing their line ladder with their join link. Free viral traffic that compounds as the team grows; no credits spent. - Ad packages: Micro $5/500 credits, Starter $10/1,000, Activation $20/2,000, Builder $50/5,500, Growth $100/12,000, Leader $250/32,500, Elite $500/70,000. Dollar-priced, settled in POL (Polygon) at the live Chainlink rate. 1 credit = 1 cent of ad delivery. +- AI AD WRITER (LIVE 2026-11-17): on Advertise > create a campaign, pick Text ad, put your link in Target URL and tap "Write my ad from my link": the network ad writer reads that page and suggests 3 text ads (headline up to 60, ad text up to 140) using only what the page says (no made-up claims, numbers or income promises); tapping one fills the headline and ad text to edit; nothing is created until you create the campaign. 5 writes a day per member (reset at midnight Central); the same page again within 24 hours is free. The same writer is on ViralAdSource, ViralAdBlitz and LinkSpin. - Live formats: display banners (per impression), text ads (per impression), full-screen LOGIN ADS (per day: right after a member signs in they land on a sponsor interstitial — they click "Open Ad", the advertiser's page opens in a NEW tab, a countdown runs on the interstitial, and at zero a "Go to dashboard" button appears. Just a CTA link is enough; an optional banner image can be the clickable creative. No framing requirement since it opens in its own tab), WATCH-TO-EARN VIDEO ADS (advertiser uploads an MP4/WebM or gives a direct https .mp4/.webm link and picks a required watch length — 10s/30s/60s — which sets the per-view price; viewers watch in an escape-proof player under Earn credits > Watch videos, the watch time is enforced on the server clock, and they earn credits per completed watch; you never see your own videos), and solo ads. Banner ads also require a size (standard IAB sizes like 728x90, 300x250). Video watching is capped at 8 a day per member and pays 1, 2 or 4 credits for a 10, 30 or 60 second watch. FEATURED LINKS (live): a headline + link in the Featured strip at the top of every member's Overview, booked for 1, 2 or 7 days at 40 credits a day, up to 7 days ahead, at most 10 links sharing any day; flat buy paid when booked; the row shows days left and 'runs through ', counts views (one per viewer per hour) and clicks, and offers Extend run. VERIFIED-VISIT PACKS (live): 3 credits per visit, minimum 20 visits, paid up front; each visit is a distinct member who opens the site in a new tab, stays 8 seconds and passes a check, at most 20 visits per member per day; the row shows 'N of M visits delivered' and Buy more visits adds to the pack; the visitor earns 1 credit. - WALLETS + BUYING POL (Training > Wallets and buying POL, /wallets, members only): say "SafePal or any other crypto wallet" and never recommend MetaMask by name (Marty 2026-11-13; a wallet app with several accounts serves Qualified Start), Phantom (PHANTOM GOTCHA: Polygon is OFF by default; Settings > Active Networks > turn on Polygon, otherwise connect/buy fails or shows the wrong network; seen with Jim Watts' EB team 2026-09-13), SafePal, Coinbase Wallet; Trust works but blocks buys spending most of its POL (keep ~2x). MoonPay flow: connect wallet, Buy packages > "Buy POL with a card" opens MoonPay with POL on Polygon + the member's address prefilled; card/Apple Pay/Google Pay; first-time ID check; minimum order ~$30; buy package cost + 2-3 POL for fees; POL arrives in minutes; then buy. Exchanges: withdraw POL on the Polygon network. Never MATIC on Ethereum, never share the recovery phrase. - PROHIBITED CONTENT (2026-10-30, Terms section 8, /terms#prohibited): gambling, casinos, betting, lotteries, sweepstakes; adult or sexual content; drugs and prescription pharmaceuticals; weapons; hate or harassment; malware, phishing, counterfeit goods; misleading financial promises. Refused at save time in bios, social links, line banners, wall offers and every campaign field. A bio may not contain a URL or a domain (links go in the social fields). Profile text, avatar and social links appear on the public wall ONLY for members who have bought a package; a free account's wall shows the name, the line's ads and the join button. Link-farm accounts (created to plant links in profile fields) are removed without notice with their profile text. diff --git a/hubadwriter.js b/hubadwriter.js new file mode 100644 index 0000000..3d2246c --- /dev/null +++ b/hubadwriter.js @@ -0,0 +1,54 @@ +// The network AI ad writer, asked through the hub (Marty 2026-11-17: "the AI generation of the ads worked really well. Let's go +// ahead and do it on the other sites too."). The hub reads the member's page, asks the model and filters the copy +// (network-hub lib/adwriter.js); this file only signs the call for this site's signed-in member and passes the answer on. +// status(member?) -> {on, daily, left?} (cached 60 s; on: false when the hub is unset, unreachable or switched off) +// write(member, url, limits) -> {ok, options: [{headline, line?}], url, cached, left} | {error (member-friendly), code, status, left?} +// Signed as HUB_SITE with HUB_SECRET: X-Hub-Site, X-Hub-Ts, X-Hub-Sig = hex HMAC-SHA256(ts + newline + raw body), like every /v1 call. +// AI_WRITER=0 hides the button on this site. Nothing is posted: the member picks an option, edits it and saves it themselves. +'use strict'; +const crypto = require('crypto'); + +const DEFAULT_SITE = 'iap'; +const hubUrl = () => String(process.env.HUB_URL || '').trim().replace(/\/+$/, ''); +const secret = () => String(process.env.HUB_SECRET || '').trim(); +const site = () => String(process.env.HUB_SITE || DEFAULT_SITE).trim(); +const configured = () => !/^(0|false|no|off)$/i.test(String(process.env.AI_WRITER || '').trim()) && !!hubUrl() && secret().length >= 32; + +async function call(route, body, timeoutMs) { + const raw = JSON.stringify(body); const ts = String(Date.now()); + const sig = crypto.createHmac('sha256', secret()).update(ts + '\n' + raw).digest('hex'); + const r = await fetch(hubUrl() + route, { method: 'POST', body: raw, signal: AbortSignal.timeout(timeoutMs), + headers: { 'Content-Type': 'application/json', 'X-Hub-Site': site(), 'X-Hub-Ts': ts, 'X-Hub-Sig': sig } }); + let j = null; try { j = await r.json(); } catch (e) { j = null; } + return { status: r.status, body: j || {} }; +} + +let st = { at: 0, v: { on: false, daily: 0 } }; +async function status(member) { + if (!configured()) return { on: false, daily: 0 }; + if (!member && Date.now() - st.at < 60000) return st.v; + try { + const r = await call('/v1/adwriter/status', member ? { member: String(member) } : {}, 3000); + const v = r.status === 200 && r.body && typeof r.body.on === 'boolean' ? r.body : { on: false, daily: 0 }; + if (!member) st = { at: Date.now(), v: { on: v.on, daily: v.daily || 0 } }; + return v; + } catch (e) { if (!member) st = { at: Date.now() - 45000, v: { on: false, daily: 0 } }; return { on: false, daily: 0 }; } // a down hub is asked again in 15 s +} +// the button shows only when the hub says the writer is on (60 s cache, never waits on a slow hub for long) +async function enabled() { return (await status()).on === true; } + +async function write(member, url, limits) { + if (!configured()) return { error: 'The ad writer is switched off right now. You can still write your ad yourself.', code: 'off', status: 503 }; + try { + const r = await call('/v1/adwriter', { member: String(member), url: String(url || '').trim().slice(0, 600), limits }, 75000); + const b = r.body || {}; + if (r.status === 200 && b.ok && Array.isArray(b.options)) return { ok: true, options: b.options, url: b.url, cached: !!b.cached, left: b.left }; + if (r.status === 401 || r.status === 403 || !b.message) { console.error('hubadwriter: hub answered ' + r.status + ' ' + String(b.error || '')); return { error: 'The ad writer is busy right now. Try again in a minute, or write your ad yourself.', code: 'hub', status: 502 }; } + return { error: String(b.message), code: b.error || b.code || 'error', status: r.status >= 400 && r.status < 600 ? r.status : 502, left: b.left }; + } catch (e) { + console.error('hubadwriter: ' + (e.name === 'TimeoutError' || e.name === 'AbortError' ? 'timeout' : String(e.message).slice(0, 120))); + return { error: 'The ad writer did not answer in time. Try again in a minute, or write your ad yourself.', code: 'hub', status: 504 }; + } +} + +module.exports = { status, enabled, write, configured, _reset: () => { st = { at: 0, v: { on: false, daily: 0 } }; } }; diff --git a/public/assets/my.js b/public/assets/my.js index 50b17c7..5f0264a 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -1543,6 +1543,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str $('cSizeRow').hidden = t !== 'banner'; $('cTitleRow').hidden = t !== 'text' && t !== 'solo'; $('cBodyRow').hidden = t !== 'text'; + if ($('cAiRow')) $('cAiRow').hidden = t !== 'text' || !aiWriterOn; $('cSoloRow').hidden = t !== 'solo'; $('cSoloHint').hidden = t !== 'solo'; $('cVideoRow').hidden = t !== 'video'; @@ -1563,6 +1564,28 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str if (t === 'featured') featHint(); } $('cType').addEventListener('change', applyType); + // the AI ad writer (Marty 2026-11-17): 3 text ads the network hub writes only from the member's own Target URL; picking one fills + // the headline and ad text to edit. Shown only when the hub answers it is on. + var aiWriterOn = false; + (async () => { + if (!$('cAiRow')) return; + try { const w = await (await fetch('/api/my/adwriter')).json(); aiWriterOn = !!(w && w.on); } catch (e) { aiWriterOn = false; } + applyType(); + const box = $('cAiList'); let opts = []; + const escA = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); + $('cAiWrite').onclick = async () => { + const url = $('cTarget').value.trim(); box.hidden = false; + if (!/^https?:\/\/\S+\.\S+/i.test(url)) { box.innerHTML = '

Put your link in the Target URL box first (starting with https://), then tap the button again.

'; $('cTarget').focus(); return; } + $('cAiWrite').disabled = true; box.innerHTML = '

Reading your page and writing 3 ads. This takes a few seconds...

'; + let r; try { r = await api('/api/my/adwriter', { url }); } catch (e) { r = { error: e.message || 'The ad writer did not answer. Try again in a minute.' }; } + $('cAiWrite').disabled = false; + if (r.error) { box.innerHTML = '

' + escA(r.error) + '

'; return; } + opts = r.options || []; + box.innerHTML = '

Tap one to use it. Check every word is true for your offer before you create the campaign.' + (typeof r.left === 'number' ? ' Ad writes left today: ' + r.left + '.' : '') + '

' + + opts.map((o, i) => '').join(''); + box.querySelectorAll('button[data-ai]').forEach(b => { b.onclick = () => { const o = opts[Number(b.dataset.ai)]; $('cTitle').value = o.headline; $('cBody').value = o.line || ''; box.hidden = true; IAP.status('Filled in. Edit it as you like, then create your campaign.', 'ok'); }; }); + }; + })(); let featStartDay = 0; // selected start-day offset (0 = today) async function featHint() { if (!lastRates || !lastRates.featuredDurations) return; diff --git a/public/my.html b/public/my.html index 5e5cb1e..387769a 100644 --- a/public/my.html +++ b/public/my.html @@ -577,6 +577,7 @@ +