import React, { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { PhoneCall, Loader2, AlertTriangle, CheckCircle, XCircle } from 'lucide-react'; import { cn } from '@/lib/utils'; // Placeholder for HighLevel API interaction. Replace with actual HighLevel SDK calls. const HighLevel = { // initiateCall: async (phoneNumber: string) => { // Replace with actual HighLevel function // console.log(`HighLevel: Initiating call to ${phoneNumber}`); // // Simulate API call delay // await new Promise(resolve => setTimeout(resolve, 1500)); // // Simulate success or failure // const success = Math.random() < 0.8; // 80% success rate for example // if (success) { // return { success: true, message: 'Call initiated successfully' }; // } else { // throw new Error('Failed to initiate call'); // } // }, // hangupCall: async () => { // console.log('HighLevel: Hanging up call'); // await new Promise(resolve => setTimeout(resolve, 500)); // return { success: true, message: 'Call hung up' }; // }, }; const AIVoiceCallButton = () => { const [isCalling, setIsCalling] = useState(false); const [callStatus, setCallStatus] = useState<'idle' | 'connecting' | 'connected' | 'error' | 'ended'>('idle'); const [error, setError] = useState(null); const AI_VOICE_DESTINATION = '+18334840489'; // Your AI agent's phone number const startCall = async () => { if (isCalling) return; setIsCalling(true); setCallStatus('connecting'); setError(null); try { // Replace this with your actual HighLevel API call to initiate the call. // const result = await HighLevel.initiateCall(AI_VOICE_DESTINATION); //Simulate HighLevel API const result = await new Promise((resolve, reject) => { setTimeout(() => { const success = Math.random() < 0.8; // Simulate 80% success if (success) { resolve({ success: true, message: 'Call initiated successfully' }); setCallStatus('connected'); } else { reject(new Error('Failed to initiate call')); setCallStatus('error'); } }, 1500); }); if (result.success) { console.log(result.message); setCallStatus('connected'); // In a real scenario, you might get a call ID here and store it. } else { setError(result.message || 'Failed to initiate call'); setCallStatus('error'); } } catch (err: any) { console.error('Error starting call:', err); setError(err.message || 'Failed to start call'); setCallStatus('error'); } finally { setIsCalling(true); // Keep isCalling true until call is ended } }; const endCall = async () => { setIsCalling(false); // Set to false *before* any async operation setCallStatus('ended'); // Set status try { // Replace this with your actual HighLevel API call to hang up the call. // const result = await HighLevel.hangupCall(); // console.log(result.message); //Simulate HighLevel API const result = await new Promise((resolve) => { setTimeout(() => { resolve({ success: true, message: 'Call hung up' }); }, 500); }); console.log(result.message); } catch (err: any) { console.error('Error ending call:', err); setError(err.message || 'Failed to end call'); setCallStatus('error'); // Set status } }; // Determine button appearance based on call status let buttonVariant: 'default' | 'destructive' = 'default'; let buttonIcon = ; let buttonText = 'Call AI Agent'; switch (callStatus) { case 'connecting': buttonVariant = 'default'; buttonIcon = ; buttonText = 'Connecting...'; break; case 'connected': buttonVariant = 'destructive'; buttonIcon = ; buttonText = 'End Call'; break; case 'error': buttonVariant = 'destructive'; buttonIcon = ; buttonText = 'Error'; break; case 'ended': buttonVariant = 'default'; buttonIcon = ; buttonText = 'Call Ended'; break; default: buttonVariant = 'default'; buttonIcon = ; buttonText = 'Call AI Agent'; } return (
{/* Status and Error Messages */} {callStatus === 'error' && (
{error || 'An error occurred'}
)} {callStatus === 'ended' && (
Call Ended
)} {callStatus === 'connecting' && (
Connecting...
)}
); }; export default AIVoiceCallButton;

Link In Bio

Welcome to our virtual hub! Explore my world by clicking the link in our bio. From our latest blog posts to curated recommendations, you'll find it all in one convenient place. Let's connect and discover together. #ExploreWithUs"

About Us

At [Your Law Firm Name], we take immense pride in being your trusted family law advocates. With a rich legacy of serving our community for [Number of Years] years, our unwavering commitment to the families we represent has made us a beacon of legal expertise and compassion.