; ═══════════════════════════════════════════════════════════════════════════════
; /etc/asterisk/extensions.conf — Dialplan Zadarma + ARI Softphone
; ═══════════════════════════════════════════════════════════════════════════════

[general]
static   = yes
writeprotect = no
autofallthrough = yes

; ─── Appels entrants depuis Zadarma ─────────────────────────────────────────
[from-zadarma]
; Tous les appels entrants passent dans l'app ARI "softphone"
exten => _X.,1,NoOp(=== Appel entrant Zadarma: ${CALLERID(num)} → ${EXTEN} ===)
 same  => n,Set(CALLERID(name)=${CALLERID(num)})
 same  => n,Stasis(softphone)
 same  => n,Hangup()

; Appel sans extension (direct)
exten => s,1,NoOp(=== Appel entrant sans exten ===)
 same  => n,Stasis(softphone)
 same  => n,Hangup()

; ─── Appels depuis le Softphone Web ─────────────────────────────────────────
[from-softphone]
; Numéros locaux (4 chiffres) → poste interne
exten => _1XXX,1,NoOp(=== Appel interne: ${EXTEN} ===)
 same  => n,Stasis(softphone)
 same  => n,Hangup()

; Numéros externes → sortie via Zadarma
exten => _0X.,1,NoOp(=== Appel externe via Zadarma: ${EXTEN} ===)
 same  => n,Set(CALLERID(num)=549318-100)
 same  => n,Dial(PJSIP/${EXTEN}@zadarma,30,gT)
 same  => n,Hangup()

exten => _+X.,1,NoOp(=== Appel international: ${EXTEN} ===)
 same  => n,Set(CALLERID(num)=549318-100)
 same  => n,Dial(PJSIP/${EXTEN:1}@zadarma,30,gT)
 same  => n,Hangup()

; Via ARI (originate depuis PHP)
exten => _X.,1,NoOp(=== Route ARI: ${EXTEN} ===)
 same  => n,Stasis(softphone)
 same  => n,Hangup()

; ─── Contexte ARI (Stasis) ──────────────────────────────────────────────────
[stasis-softphone]
exten => _X.,1,Stasis(softphone)
 same  => n,Hangup()
