'use client'; import React, { useState, useEffect } from 'react'; import { PhoneCall, ShieldCheck, Server, Lock, RefreshCw, CheckCircle2, AlertCircle, PhoneForwarded, Clock, History, Play, Key, } from 'lucide-react'; import { toast } from 'sonner'; import { IntegrationsHeaderNav } from '@/components/integrations/IntegrationsHeaderNav'; import { integrationService } from '@/services/api/integrationService'; export default function KnowlarityCallIntegrationPage() { const [creds, setCreds] = useState({ api_key: '', authorization: '', virtual_number: '', call_url: 'https://kpi.knowlarity.com/Basic/v1/account/call/makecall', log_url: 'https://kpi.knowlarity.com/Basic/v1/account/calllog', source: 'unconfigured', is_locked_by_config: false, }); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); // Click to call form state const [agentNumber, setAgentNumber] = useState(''); const [customerNumber, setCustomerNumber] = useState(''); const [calling, setCalling] = useState(false); // Call logs table const [logs, setLogs] = useState([]); const [logsLoading, setLogsLoading] = useState(false); const [page, setPage] = useState(1); const fetchKnowlarityConfig = async () => { setLoading(true); try { const data = await integrationService.getKnowlarityCredentials(); setCreds(data); if (data.api_key || data.authorization) { fetchLogs(); } } catch (err: any) { toast.error('Failed to load Knowlarity settings'); } finally { setLoading(false); } }; const fetchLogs = async () => { setLogsLoading(true); try { const res = await integrationService.getKnowlarityCallLogs(page, 20); const callData = res.data?.call_logs || res.data?.objects || res.call_logs || []; setLogs(callData); } catch (err) { console.warn('Call logs error:', err); } finally { setLogsLoading(false); } }; useEffect(() => { fetchKnowlarityConfig(); }, []); const handleSave = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); try { await integrationService.saveKnowlarityCredentials(creds); toast.success('Knowlarity credentials saved successfully'); fetchLogs(); } catch (err: any) { toast.error(err.message || 'Failed to save Knowlarity credentials'); } finally { setSaving(false); } }; const handleMakeCall = async (e: React.FormEvent) => { e.preventDefault(); if (!agentNumber.trim() || !customerNumber.trim()) { toast.error('Both Agent number and Customer number are required for bridging'); return; } setCalling(true); try { const res = await integrationService.makeKnowlarityCall({ agent_number: agentNumber.trim(), customer_number: customerNumber.trim(), }); if (res.status === 'SUCCESS') { toast.success('Call initiated! Knowlarity is ringing the agent first, then connecting customer.'); fetchLogs(); } else { toast.error(`Call failed: ${res.detail || JSON.stringify(res)}`); } } catch (err: any) { toast.error(err.message || 'Call initiation failed'); } finally { setCalling(false); } }; return (
{/* Top Banner */}

Knowlarity Cloud Telephony & SuperReceptionist IVR

Cloud IVR call routing, technician click-to-call bridging, customer service recordings, and live call logs.

{creds.is_locked_by_config ? ( Configured via Config.py ) : ( Database Configuration )}
{/* Credentials Form (Cols 1-7) */}

SuperReceptionist Credentials

setCreds({ ...creds, virtual_number: e.target.value })} placeholder="e.g. +91XXXXXXXXXX" className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" />
setCreds({ ...creds, api_key: e.target.value })} placeholder="Knowlarity x-api-key" className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" />
setCreds({ ...creds, authorization: e.target.value })} placeholder="Knowlarity Authorization" className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" />
setCreds({ ...creds, call_url: e.target.value })} className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" />
setCreds({ ...creds, log_url: e.target.value })} className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" />
{!creds.is_locked_by_config && ( )}
{/* Live Click-to-Call Dialer (Cols 8-12) */}

Agent Click-to-Call Bridge

Connect a technician or sales rep with a customer through Knowlarity without revealing personal numbers.

setAgentNumber(e.target.value)} className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-rose-500 focus:outline-none" />
setCustomerNumber(e.target.value)} className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-rose-500 focus:outline-none" />
Virtual Number: {creds.virtual_number || 'SR Number'}
{/* Call Logs Table */}

Telephony Call Logs & Recordings

{logs.length === 0 ? ( ) : ( logs.map((log: any, idx: number) => ( )) )}
Date / Time Customer Agent Status Duration Recording
{logsLoading ? 'Fetching call logs from Knowlarity...' : 'No call logs recorded yet.'}
{log.start_time || log.call_date || 'Recent'} {log.customer_number || log.caller_id || '-'} {log.agent_number || log.destination || '-'} {log.status || log.call_type || 'COMPLETED'} {log.duration ? `${log.duration}s` : '0s'} {log.recording_url ? ( Audio ) : ( - )}
); }