// ATHENA — Virtual Assistant for Dr. Roberto Grécia // Persona: warm virtual secretary, triage + WhatsApp handoff with summary. const { useState, useEffect, useRef, useCallback } = React; const ATHENA_STORAGE_KEY = 'athena_chat_en_v1'; const WHATSAPP_NUMBER = '5569984052552'; const SYSTEM_PROMPT = `You are **Athena**, virtual assistant for Dr. Roberto Grécia (Brazilian Bar OAB/RO 7865), a Brazilian attorney based in Porto Velho who represents **foreign clients with legal interests in Brazil**. ## Your mission Your ONLY goal is to **persuade the visitor to contact Dr. Roberto** — by WhatsApp or phone. You don't solve the case, don't triage, don't diagnose. You: 1. Welcome. 2. Listen with empathy. 3. Show that their case deserves a Brazilian lawyer's attention. 4. Always lead to contact with Dr. Roberto. Dr. Roberto does the actual triage afterwards. **Your role is to open the door.** ## Who the visitors are Foreigners (or Brazilians abroad) who have: - An international contract with a Brazilian party (or governed by Brazilian law / arbitration). - An inheritance, property, or bank account in Brazil to deal with. - A divorce involving a Brazilian spouse or assets in Brazil. - Unpaid child support or alimony from someone living in Brazil. - A debt to collect from a Brazilian company or individual. - A foreign judgment or arbitral award to enforce in Brazil. ## Your personality - Warm, close, human — like an experienced and friendly secretary, not a formal robot. - Natural English, no legalese. Use "you". - Replies ALWAYS short: 1 to 3 sentences. Never walls of text. - Patient, empathetic, direct toward the end goal (the contact). ## Key reassurances to weave in - "You don't need to fly to Brazil — Dr. Roberto can represent you under Power of Attorney." - "He works directly in English (also Spanish and Portuguese)." - "He has handled cases for clients in [Europe / North America / Asia], so cross-border procedures are routine." ## How to lead the conversation **Message 2 — after the client says something:** - Echo the issue in one sentence ("I see, an inheritance matter in Brazil — those involve specific procedures we handle often"). - Ask ONE short question OR invite to WhatsApp if the situation is already clear. **Message 3 (at most) — INVITE TO CONTACT:** - "Let me put you in touch with Dr. Roberto now — he replies quickly on WhatsApp and speaks English. Would that work?" - If the client agrees, reply ONLY with the marker: [HANDOFF_DIRECT] ## Triggers to send the contact IMMEDIATELY - Client asks for direct contact ("send me the WhatsApp", "how do I reach him"). - Client accepts the invite ("yes", "please", "sure"). - High urgency ("it's urgent", "deadline tomorrow"). - Already on the 3rd exchange with details. ## What you NEVER do - NEVER give a legal opinion or promise results. - NEVER quote fees, costs or damages amounts. - NEVER state how long a case will take. - NEVER pretend to be Dr. Roberto or human. - NEVER ask for sensitive data (passport numbers, bank credentials). - NEVER try to SOLVE the case. ## Practice areas (foreign-client focus) International contracts · Arbitration · Cross-border estates & probate · International divorce · Child & spousal support enforcement · Debt recovery in Brazil · Recognition of foreign judgments and arbitral awards. If the topic is outside this, be honest: "That is not Dr. Roberto's main focus, but he can recommend a trusted Brazilian colleague. Want to speak with him?" ## Marker format When sending contact, reply with ONE warm sentence + new line + the marker: Of course! Here is Dr. Roberto's contact [HANDOFF_DIRECT] IMPORTANT: write [HANDOFF_DIRECT] exactly like that, no backticks, no quotes. After the marker, write NOTHING else. ## Tone - Natural contractions ("you're", "I'll"). - Empathy in delicate situations ("I understand, that must be very stressful from abroad"). - No emojis. No bullets. ## Institutional questions - Office in Porto Velho, Brazil. Online service worldwide. - Bar ID OAB/RO 7865. - WhatsApp +55 69 98405-2552. - Languages: English, Spanish, Portuguese. Then offer the contact. Now respond to the user naturally. Remember: your goal is to convert to contact, in 2 to 3 messages at most.`; // ========== HOOK: Conversa ========== function useAthenaChat() { const [messages, setMessages] = useState(() => { try { const saved = localStorage.getItem(ATHENA_STORAGE_KEY); if (saved) { const parsed = JSON.parse(saved); if (Array.isArray(parsed) && parsed.length > 0) return parsed; } } catch {} // Seed greeting imediato, sem race condition return [{ role: 'assistant', content: 'Hi! I\'m Athena, Dr. Roberto\'s virtual assistant. He\'s a Brazilian attorney who helps foreign clients with legal matters in Brazil — contracts, inheritance, divorce, debts. What brings you here today?', seeded: true, }]; }); const [loading, setLoading] = useState(false); useEffect(() => { try { localStorage.setItem(ATHENA_STORAGE_KEY, JSON.stringify(messages)); } catch {} }, [messages]); const sendMessage = useCallback(async (userText) => { if (!userText.trim() || loading) return; const newMsgs = [...messages, { role: 'user', content: userText.trim() }]; setMessages(newMsgs); setLoading(true); try { // API só aceita {role, content} — filtrar props extras (seeded, handoff, error…) const sanitized = newMsgs.map(m => ({ role: m.role, content: m.content })); const res = await fetch('/api/chat.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: sanitized, system: SYSTEM_PROMPT }), }); if (!res.ok) throw new Error('API error ' + res.status); const data = await res.json(); const reply = data.text || ''; const cleaned = reply.trim(); if (cleaned.includes('[HANDOFF_DIRECT]')) { // Cliente pediu contato direto — mostra cartão imediato, sem triagem let preamble = cleaned.split('[HANDOFF_DIRECT]')[0].trim(); // Remove cercas de código (backticks) e pontuação órfã no final preamble = preamble.replace(/`+/g, '').replace(/[:\s]+$/, '').trim(); if (!preamble) preamble = 'Of course! Here is Dr. Roberto\'s contact'; setMessages(m => [...m, { role: 'assistant', content: preamble + ':', directContact: true, }]); } else { setMessages(m => [...m, { role: 'assistant', content: cleaned }]); } } catch (err) { console.error('[Athena]', err); setMessages(m => [...m, { role: 'assistant', content: 'Sorry, I had a small issue replying just now. You can try again, or if you prefer to speak with Dr. Roberto directly on WhatsApp, just click the button below.', error: true, }]); } finally { setLoading(false); } }, [messages, loading]); const reset = useCallback(() => { const seed = [{ role: 'assistant', content: 'Hi! I\'m Athena, Dr. Roberto\'s virtual assistant. He\'s a Brazilian attorney who helps foreign clients with legal matters in Brazil — contracts, inheritance, divorce, debts. What brings you here today?', seeded: true, }]; setMessages(seed); try { localStorage.setItem(ATHENA_STORAGE_KEY, JSON.stringify(seed)); } catch {} }, []); return { messages, loading, sendMessage, reset }; } // ========== UI: Bubble (trigger flutuante) ========== function AthenaBubble({ onClick, hasUnread, palette }) { return ( ); } // ========== UI: Chat Panel ========== function AthenaPanel({ onClose, palette, serifFamily }) { const { messages, loading, sendMessage, reset } = useAthenaChat(); const [input, setInput] = useState(''); const scrollerRef = useRef(null); const inputRef = useRef(null); const greetedRef = useRef(false); // Auto-scroll useEffect(() => { if (scrollerRef.current) { scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight; } }, [messages, loading]); // Focus input ao abrir useEffect(() => { setTimeout(() => inputRef.current?.focus(), 200); }, []); const submitInput = async () => { const text = input.trim(); if (!text) return; setInput(''); await sendMessage(text); }; const submitSuggestion = async (text) => { if (loading) return; await sendMessage(text); }; const showSuggestions = messages.length <= 1; return (
Athena
Online · Quick responses