// Cortex AI — Sales Chat Widget // Smart FAQ + lead capture + multilingual (function() { const KNOWLEDGE = { pricing: { en: "We have 3 plans:\n\n• **Starter** — $2,997/mo → 5 AI executives (CFO, CMO, COO, Legal, Chief of Staff)\n• **Business** — $5,997/mo → 10 AI executives + priority support\n• **Enterprise** — $14,997/mo → 20+ executives + dedicated account manager\n\nAll plans include a free trial. Want to get started?", pt: "Temos 3 planos:\n\n• **Starter** — $2.997/mês → 5 executivos IA (CFO, CMO, COO, Jurídico, Chief of Staff)\n• **Business** — $5.997/mês → 10 executivos IA + suporte prioritário\n• **Enterprise** — $14.997/mês → 20+ executivos + account manager dedicado\n\nTodos incluem free trial. Quer começar?", es: "Tenemos 3 planes:\n\n• **Starter** — $2,997/mes → 5 ejecutivos IA\n• **Business** — $5,997/mes → 10 ejecutivos IA\n• **Enterprise** — $14,997/mes → 20+ ejecutivos IA\n\nTodos incluyen prueba gratis. ¿Quieres empezar?" }, how: { en: "Here's how it works:\n\n1️⃣ Sign up and connect via Telegram\n2️⃣ Tell your AI Chief of Staff about your business (text, voice, docs)\n3️⃣ Your AI team is configured and goes live within hours\n4️⃣ Give orders, get results. 24/7. Any language.\n\nNo calls needed. No humans involved. Ready to try?", pt: "Funciona assim:\n\n1️⃣ Cadastre-se e conecte via Telegram\n2️⃣ Conte ao seu Chief of Staff sobre seu negócio (texto, áudio, docs)\n3️⃣ Seu time de IA é configurado e entra no ar em horas\n4️⃣ Dê ordens, receba resultados. 24/7. Qualquer idioma.\n\nSem ligações. Sem humanos. Quer experimentar?", es: "Así funciona:\n\n1️⃣ Regístrate y conéctate por Telegram\n2️⃣ Cuéntale a tu Chief of Staff sobre tu negocio\n3️⃣ Tu equipo de IA se configura en horas\n4️⃣ Da órdenes, recibe resultados. 24/7.\n\n¿Quieres probar?" }, agents: { en: "Your AI team includes:\n\n💰 **CFO** — Cash flow, reports, budgets, forecasting\n🎯 **CMO** — Marketing, content, campaigns, SEO\n⚡ **COO** — Operations, processes, KPIs\n⚖️ **Legal** — Contracts, compliance, governance\n📋 **Chief of Staff** — Coordinates everything, your single contact\n\nBusiness & Enterprise tiers add: CRO, CHRO, CTO, CISO, Accounting, and custom agents.", pt: "Seu time de IA inclui:\n\n💰 **CFO** — Fluxo de caixa, relatórios, orçamentos\n🎯 **CMO** — Marketing, conteúdo, campanhas, SEO\n⚡ **COO** — Operações, processos, KPIs\n⚖️ **Jurídico** — Contratos, compliance\n📋 **Chief of Staff** — Coordena tudo, seu contato único\n\nPlanos Business e Enterprise adicionam: CRO, CHRO, CTO, CISO, Contabilidade e agentes customizados.", es: "Tu equipo de IA incluye:\n\n💰 **CFO** — Flujo de caja, reportes, presupuestos\n🎯 **CMO** — Marketing, contenido, campañas\n⚡ **COO** — Operaciones, procesos, KPIs\n⚖️ **Legal** — Contratos, compliance\n📋 **Chief of Staff** — Coordina todo\n\nPlanes Business y Enterprise agregan más agentes." }, security: { en: "Your data is completely safe:\n\n🔒 Encrypted at rest and in transit\n🏢 Isolated infrastructure per client\n🚫 We never use your data to train models\n✅ Human-in-the-loop for critical actions (payments, emails)\n📋 SOC 2 compliance in progress\n\nYou set the boundaries. Your AI team respects them.", pt: "Seus dados estão completamente seguros:\n\n🔒 Criptografia em repouso e em trânsito\n🏢 Infraestrutura isolada por cliente\n🚫 Nunca usamos seus dados pra treinar modelos\n✅ Aprovação humana para ações críticas\n📋 SOC 2 em andamento\n\nVocê define os limites. Seu time IA respeita.", es: "Tus datos están completamente seguros:\n\n🔒 Encriptación en reposo y tránsito\n🏢 Infraestructura aislada por cliente\n🚫 Nunca usamos tus datos para entrenar modelos\n✅ Aprobación humana para acciones críticas" }, trial: { en: "Yes! We offer a free trial so you can see the value before committing. Sign up, connect with your AI Chief of Staff, and experience the power of having an AI executive team. No credit card required to start.\n\nWant to begin? 👆 Click 'Get Started' above!", pt: "Sim! Oferecemos um free trial pra você ver o valor antes de se comprometer. Cadastre-se, conecte com seu Chief of Staff de IA, e experimente o poder de ter um time executivo de IA. Sem cartão de crédito pra começar.\n\nQuer começar? 👆 Clique em 'Get Started' acima!", es: "¡Sí! Ofrecemos una prueba gratis. Regístrate, conéctate con tu Chief of Staff de IA, y experimenta el poder de un equipo ejecutivo de IA.\n\n¿Quieres empezar? 👆 Haz clic en 'Get Started' arriba!" }, default: { en: "I'd love to help! I can answer questions about:\n\n• 💰 Pricing & plans\n• 🤖 How it works\n• 👥 Our AI agents\n• 🔒 Security & data\n• 🆓 Free trial\n\nOr if you're ready, click **Get Started** to connect with your AI Chief of Staff!", pt: "Posso te ajudar! Respondo sobre:\n\n• 💰 Preços e planos\n• 🤖 Como funciona\n• 👥 Nossos agentes IA\n• 🔒 Segurança e dados\n• 🆓 Free trial\n\nOu se quiser começar, clique em **Get Started** pra conectar com seu Chief of Staff!", es: "¡Puedo ayudarte! Respondo sobre:\n\n• 💰 Precios y planes\n• 🤖 Cómo funciona\n• 👥 Nuestros agentes IA\n• 🔒 Seguridad y datos\n• 🆓 Prueba gratis\n\nO haz clic en **Get Started** para empezar!" } }; const GREETINGS = { en: "👋 Hi! I'm the Cortex AI assistant. How can I help you today?", pt: "👋 Olá! Sou o assistente Cortex AI. Como posso te ajudar?", es: "👋 ¡Hola! Soy el asistente de Cortex AI. ¿Cómo puedo ayudarte?" }; let lang = 'en'; let chatOpen = false; function detectLang(text) { const lower = text.toLowerCase(); if (/preço|plano|como funciona|olá|oi|quanto|negócio|empresa|quero/i.test(lower)) return 'pt'; if (/precio|plan|cómo|hola|cuánto|negocio|empresa|quiero/i.test(lower)) return 'es'; return 'en'; } function matchTopic(text) { const lower = text.toLowerCase(); if (/pric|cost|quanto|preço|custo|precio|cuesta|plan|plano|tier|how much|cuánto/.test(lower)) return 'pricing'; if (/how.*work|como funciona|cómo funciona|setup|começar|empezar|start/.test(lower)) return 'how'; if (/agent|agente|team|time|equipo|cfo|cmo|coo|legal|chief/.test(lower)) return 'agents'; if (/secur|segur|data|dado|privac|encrypt|cripto|safe|seguro/.test(lower)) return 'security'; if (/trial|free|grátis|gratis|test|prueba|experiment/.test(lower)) return 'trial'; return 'default'; } function formatMsg(text) { return text.replace(/\*\*(.*?)\*\*/g, '$1').replace(/\n/g, '
'); } function createWidget() { const style = document.createElement('style'); style.textContent = ` #cx-chat-btn { position:fixed; bottom:24px; right:24px; width:60px; height:60px; border-radius:50%; background:linear-gradient(135deg,#6366f1,#8b5cf6); border:none; cursor:pointer; z-index:999; box-shadow:0 4px 20px rgba(99,102,241,0.4); display:flex; align-items:center; justify-content:center; font-size:28px; transition:transform 0.2s; } #cx-chat-btn:hover { transform:scale(1.1); } #cx-chat-box { position:fixed; bottom:96px; right:24px; width:380px; max-height:500px; background:#111113; border:1px solid #27272a; border-radius:16px; z-index:999; display:none; flex-direction:column; box-shadow:0 8px 40px rgba(0,0,0,0.5); overflow:hidden; font-family:'Inter',sans-serif; } #cx-chat-header { padding:16px 20px; background:#18181b; border-bottom:1px solid #27272a; display:flex; align-items:center; gap:10px; } #cx-chat-header .avatar { width:36px; height:36px; border-radius:10px; background:linear-gradient(135deg,#6366f1,#8b5cf6); display:flex; align-items:center; justify-content:center; font-size:16px; } #cx-chat-header .info h4 { font-size:14px; font-weight:700; color:#fafafa; margin:0; } #cx-chat-header .info span { font-size:11px; color:#22c55e; } #cx-chat-header .close { margin-left:auto; background:none; border:none; color:#71717a; font-size:20px; cursor:pointer; } #cx-chat-msgs { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:10px; min-height:280px; max-height:340px; } .cx-msg { max-width:85%; padding:10px 14px; border-radius:12px; font-size:13px; line-height:1.5; color:#e4e4e7; } .cx-msg.bot { background:#1e1e22; border:1px solid #27272a; border-radius:12px 12px 12px 4px; align-self:flex-start; } .cx-msg.user { background:#6366f1; color:white; border-radius:12px 12px 4px 12px; align-self:flex-end; } #cx-chat-input { display:flex; padding:12px; border-top:1px solid #27272a; gap:8px; } #cx-chat-input input { flex:1; background:#09090b; border:1px solid #27272a; border-radius:8px; padding:10px 14px; color:#fafafa; font-size:13px; font-family:inherit; outline:none; } #cx-chat-input input:focus { border-color:#6366f1; } #cx-chat-input button { background:#6366f1; border:none; border-radius:8px; color:white; padding:10px 16px; cursor:pointer; font-size:13px; font-weight:600; } @media(max-width:480px) { #cx-chat-box { width:calc(100% - 16px); right:8px; bottom:80px; } } `; document.head.appendChild(style); // Chat button const btn = document.createElement('button'); btn.id = 'cx-chat-btn'; btn.innerHTML = '💬'; btn.onclick = toggleChat; document.body.appendChild(btn); // Chat box const box = document.createElement('div'); box.id = 'cx-chat-box'; box.innerHTML = `

Cortex AI

● Online
`; document.body.appendChild(box); } function toggleChat() { const box = document.getElementById('cx-chat-box'); chatOpen = !chatOpen; box.style.display = chatOpen ? 'flex' : 'none'; if (chatOpen && !box.dataset.init) { box.dataset.init = '1'; addBotMsg(GREETINGS[lang]); // Send notification that someone opened chat fetch('/.netlify/functions/lead-capture', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({name:'Chat Visitor',email:'chat@visitor',phone:'-',channel:'chat',company:'Unknown',tier:'Chat',language:lang,pain:'Opened chat widget'}) }).catch(()=>{}); } } function addBotMsg(text) { const msgs = document.getElementById('cx-chat-msgs'); const div = document.createElement('div'); div.className = 'cx-msg bot'; div.innerHTML = formatMsg(text); msgs.appendChild(div); msgs.scrollTop = msgs.scrollHeight; } function addUserMsg(text) { const msgs = document.getElementById('cx-chat-msgs'); const div = document.createElement('div'); div.className = 'cx-msg user'; div.textContent = text; msgs.appendChild(div); msgs.scrollTop = msgs.scrollHeight; } window._cxSend = function() { const input = document.getElementById('cx-input'); const text = input.value.trim(); if (!text) return; input.value = ''; // Detect language from first message lang = detectLang(text); addUserMsg(text); // Typing indicator setTimeout(() => { const topic = matchTopic(text); const response = KNOWLEDGE[topic][lang] || KNOWLEDGE[topic].en; addBotMsg(response); }, 600 + Math.random() * 800); }; // Init if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', createWidget); } else { createWidget(); } })();