Build Call History from Asterisk's call records #81
Loading…
Reference in a new issue
No description provided.
Delete branch "patrick/call-history"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Nothing ever wrote
call_logs. The/api/call-logsendpoint had no caller, so Call History was always empty, there was no data for billing, and recordings had nothing to attach to. A Dallas client's call couldn't be traced for the same reason.How it works
Asterisk → Postgres.
cdr_adaptive_odbcwrites every call that reaches the dialplan, answered or not, to a newasterisk_cdrtable. It uses the same ODBC connection as realtime. Calls PJSIP rejects before the dialplan (the SIP scanners) never get a record.Postgres → Call History.
orbital:ingest-cdrsruns every minute. It groups records bylinkedidand rebuilds onecall_logsrow per call, so it's idempotent and a late record corrects the call. Each row gets:ai,extension,queue,voicemail,ai_unavailable)metadataRaw records are kept for 30 days after ingest.
Tagging. The from-trunk dispatcher tags inbound calls with the client, routing rule, DID and the carrier's SIP Call-ID (what edge recordings are keyed by). Calls between a client's own extensions are attributed from their
tenant_Ncontext.AI calls. The AI leg now carries
X-Orbital-Call(the linkedid). The worker sends it with the call context, and sends the transcript (caller and agent turns only) when the session ends, so AI calls get their persona and transcript whichever arrives first.UI. Call History (portal) and Call Logs (admin) get:
h:mm:ssdurationsChecked against the Asterisk 22 source, not only tests
adaptive_odbcwritesdispositionas a number (8 = answered). It writes an unanswered leg's answer time as the epoch. The ingester normalises both, and the tests use that real format.id,ingested_at) are left out of its INSERT.alias start => started_atis the right syntax (endis reserved in SQL).CDR()variables carry over to a channel's later CDRs.CHANNEL(pjsip,call-id)exists.pre-upgrade, before Asterisk restarts. config-sync also reloadscdr_adaptive_odbcwith every dialplan reload as a safety net.Not in this PR
Tests
CallHistoryIngestTest: 14 tests.🤖 Generated with Claude Code