Files
selfphoneng/apps/api/src/generator/dialplan/emergency.ts
T
iamdoubz 71440ac85d cdr: store Cdr events, aggregate calls, fixtures from real calls
services/cdr.ts stores every AMI Cdr event in cdr and, 5 s after a
call's last event, builds its calls row (direction, status, from, to,
DID, answered by, talk time) and call_extensions (caller, rang,
answered) per 04 §5.4; linkedids without a calls row are caught up on
AMI connect. Aggregation is idempotent.

test/asterisk/cdr-record.ts records 8 scenarios with our config, the
fake voip.ms (now shared in provider.ts) and baresip phones; each has a
fixture and a test with the expected calls row. Queue abandon and park
come with M8.

Found while recording: Asterisk 24's Cdr event has no LinkedID unless
cdr_manager maps it, its times carry no zone (now usegmtime), and the
mappings read CDR variables, so the dialplan sets CDR(SP_DID) and
CDR(SP_DIRECTION) next to the channel variables. The Asterisk image
needs a rebuild for the cdr_manager.conf change.

Task: M7-T1
2026-10-18 14:37:14 -05:00

28 lines
1.2 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-or-later
// 911 (03 §6.14). Never blocked for any reason: no class check, no channel limits, no DND, and
// every enabled trunk is tried. The UserEvent makes the api notify people (04 §5.3).
import type { Snapshot } from '../load.ts';
import * as s from '../sanitize.ts';
export function renderEmergency(snap: Snapshot): string {
const trunks = snap.trunks
.filter((t) => t.enabled)
.sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
return (
[
'[sp-emergency-dial]',
'exten => 911,1,Goto(sp-emergency,s,1)',
'exten => 9911,1,Goto(sp-emergency,s,1) ; people who dial 9 first out of habit',
'',
'[sp-emergency]',
'exten => s,1,Set(CID=${IF($["${SP_E911CID}" != ""]?${SP_E911CID}:${SP_DEFAULT_E911_CID})})',
' same => n,UserEvent(SpEmergency,Ext: ${SP_EXT},CallerId: ${CID},Dialed: 911)',
' same => n,ExecIf($["${CID}" != ""]?Set(CALLERID(num)=${CID}))',
' same => n,Set(__SP_DIRECTION=outbound)',
' same => n,Set(CDR(SP_DIRECTION)=outbound)',
...trunks.map((t) => ` same => n,Dial(PJSIP/911@trunk-${s.ident(t.id)})`),
' same => n,Hangup()',
].join('\n') + '\n'
);
}