Kingdom Companion
Speak or type your heart. Your companion responds with empathy, guidance, and scripture.
Grace (Female Companion)
Eli (Male Companion)
Need more support?
Book a one‑on‑one live coaching session with a Kingdom Companion.
$159 per hour
/g, " ")); const voices = speechSynthesis.getVoices(); let chosen = null; if (gender === "male") { chosen = voices.find(v => /Male|David|Google UK English Male|English Male/i.test(v.name)) || voices[0]; } else { chosen = voices.find(v => /Female|Zira|Samantha|Google US English|English Female/i.test(v.name)) || voices[0]; } if (chosen) utterance.voice = chosen; utterance.rate = 1.0; utterance.pitch = gender === "male" ? 0.95 : 1.05; speechSynthesis.cancel(); speechSynthesis.speak(utterance); } catch (e) { /* silent */ } } // Compose persona/system instructions for backend function buildSystemPrompt(gender) { const name = gender === 'male' ? 'Eli' : 'Grace'; return ` You are ${name}, the Kingdom Companion — a compassionate spiritual guide. Respond with: - Empathy that reflects the user's feelings without judgment. - Scripture (but the client will append one verse at the end; you may reference scripture naturally). - One gentle, open-ended follow-up question. Style guidelines: - Warm, concise, and human. - Avoid medical or legal advice. - Never give specific treatment recommendations. - Keep to 2–4 short paragraphs max. `; } // Call your AI backend (replace URL and payload as needed) async function getAIReply(userText, gender) { const systemPrompt = buildSystemPrompt(gender); // IMPORTANT: Replace /api/kingdom-companion with your real endpoint. // Backend should return JSON: { reply: "string" } const res = await fetch('/api/kingdom-companion', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ system: systemPrompt, user: userText, companion: gender // optional hint to backend }) }); if (!res.ok) { const msg = `Sorry, I’m having trouble responding right now. Please try again.`; return msg; } const data = await res.json(); const aiText = (data.reply || '').trim(); // Append scripture on the client side const scripture = randomScripture(); return `${aiText}
${scripture}`; } // Send message flow async function handleSend() { const text = input.value.trim(); const gender = companionSelect.value; const name = gender === 'male' ? 'Eli' : 'Grace'; if (!text) return; // Add user message addMessage(text, 'user'); chatLog.push({ role: 'user', text }); // Show typing indicator const typingEl = document.createElement('div'); typingEl.className = 'message system'; typingEl.innerHTML = `${name} is typing...`; messagesDiv.appendChild(typingEl); messagesDiv.scrollTop = messagesDiv.scrollHeight; input.value = ''; // Get AI reply let reply; try { reply = await getAIReply(text, gender); } catch (e) { reply = `I’m here with you. Let’s try again in a moment.
${randomScripture()}`; } // Remove typing indicator and add companion message messagesDiv.removeChild(typingEl); const formatted = `${name} says: ${reply}`; addMessage(formatted, 'companion'); chatLog.push({ role: 'companion', text: formatted }); saveChat(); // Speak reply speakReply(formatted, gender); } sendBtn.addEventListener('click', handleSend); input.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); }); // Microphone (Web Speech API) const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; if (SpeechRecognition) { const recognition = new SpeechRecognition(); recognition.lang = "en-US"; recognition.interimResults = false; recognition.maxAlternatives = 1; micBtn.addEventListener("click", () => { try { recognition.start(); } catch (err) { alert("Mic could not start."); } }); recognition.addEventListener("result", (event) => { const transcript = event.results?.[0]?.[0]?.transcript || ""; input.value = transcript; }); } else { micBtn.addEventListener("click", () => alert("Mic not supported in this browser. Try Chrome or Edge.")); } // Coaching button document.getElementById('bookSessionBtn').addEventListener('click', () => { const proceed = confirm("You are about to book a live coaching session for $159/hour. Continue?"); if (proceed) window.location.href = "https://yourwebsite.com/book-session"; // replace with your booking link }); // Ensure voices are loaded if (typeof speechSynthesis !== "undefined") { speechSynthesis.onvoiceschanged = () => {}; }