feat: track UCID from SIP headers for Ozonetel disposition

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 18:33:46 +05:30
parent e7c5c13e83
commit d6ef2b70d8
4 changed files with 42 additions and 15 deletions

View File

@@ -5,11 +5,13 @@ import type { SIPConfig, ConnectionStatus, CallState } from '@/types/sip';
let sipClient: SIPClient | null = null;
let connected = false;
let outboundPending = false;
let outboundActive = false;
type StateUpdater = {
setConnectionStatus: (status: ConnectionStatus) => void;
setCallState: (state: CallState) => void;
setCallerNumber: (number: string | null) => void;
setCallUcid: (ucid: string | null) => void;
};
let stateUpdater: StateUpdater | null = null;
@@ -46,21 +48,34 @@ export function connectSip(config: SIPConfig): void {
sipClient = new SIPClient(
config,
(status) => stateUpdater?.setConnectionStatus(status),
(state, number) => {
// Auto-answer SIP when it's a bridge from our outbound Kookoo call
(state, number, ucid) => {
// Auto-answer SIP when it's a bridge from our outbound call
if (state === 'ringing-in' && outboundPending) {
outboundPending = false;
outboundActive = true;
console.log('[SIP] Outbound bridge detected — auto-answering');
setTimeout(() => {
sipClient?.answer();
// Force active state in case SIP callbacks don't fire
setTimeout(() => stateUpdater?.setCallState('active'), 300);
}, 500);
// Store UCID even for outbound bridge calls
if (ucid) stateUpdater?.setCallUcid(ucid);
return;
}
// Don't overwrite caller number on outbound calls — it was set by click-to-call
stateUpdater?.setCallState(state);
if (number !== undefined) stateUpdater?.setCallerNumber(number ?? null);
if (!outboundActive && number !== undefined) {
stateUpdater?.setCallerNumber(number ?? null);
}
// Store UCID if provided
if (ucid) stateUpdater?.setCallUcid(ucid);
// Reset outbound flag when call ends
if (state === 'ended' || state === 'failed') {
outboundActive = false;
}
},
);
@@ -72,7 +87,9 @@ export function disconnectSip(): void {
sipClient = null;
connected = false;
outboundPending = false;
outboundActive = false;
stateUpdater?.setConnectionStatus('disconnected');
stateUpdater?.setCallUcid(null);
}
export function getSipClient(): SIPClient | null {