Priority for emergency calls
This extension for 911 tries to dial out. If no channel is available on the Zap interface, one call is terminated, we wait one second and then dial out on the line.exten => 911,1,ChanIsAvail(Zap/1)
exten => 911,2,Dial(Zap/1/911)
exten => 911,3,Hangup()
exten => 911,102,SoftHangup(Zap/1-1)
exten => 911,103,Wait(1)
exten => 911,104,Goto(1)
exten => 911,2,Dial(Zap/1/911)
exten => 911,3,Hangup()
exten => 911,102,SoftHangup(Zap/1-1)
exten => 911,103,Wait(1)
exten => 911,104,Goto(1)
However, you don't want to hang up a call that is an emergency call! Thus the only thing I would add is a variable to set for emergency call already on the channel. That way before you do the disconnect you can check to see if it is already an emergency call.
Try this variation (untested):
[globals]
EMERGENCY=0
LINEOUT=Zap/1
exten => 911,1,ChanIsAvail(${LINEOUT})
exten => 911,2,SetGlobalVar(EMERGENCY=1)
exten => 911,3,Dial(${LINEOUT}/911)
exten => 911,4,SetGlobalVar(EMERGENCY=0)
exten => 911,5,Hangup
exten => 911,102,GotoIf($[${EMERGENCY} = 1]?999)
exten => 911,103,SoftHangup(${LINEOUT}-1)
exten => 911,104,Wait(1)
exten => 911,105,Goto(1)
exten => 911,999,Congestion()
EMERGENCY=0
LINEOUT=Zap/1
exten => 911,1,ChanIsAvail(${LINEOUT})
exten => 911,2,SetGlobalVar(EMERGENCY=1)
exten => 911,3,Dial(${LINEOUT}/911)
exten => 911,4,SetGlobalVar(EMERGENCY=0)
exten => 911,5,Hangup
exten => 911,102,GotoIf($[${EMERGENCY} = 1]?999)
exten => 911,103,SoftHangup(${LINEOUT}-1)
exten => 911,104,Wait(1)
exten => 911,105,Goto(1)
exten => 911,999,Congestion()
- If you want to give the user a chance to hangup, play a message and wait for a couple of seconds before connecting to the 911 emergency service.
- For most of Europe, replace 911 with 112. Also in the UK, 999 is usually dialed (911 does not work). Australia uses 000, Mexico 080 and Pakistan 15.
Contributed by Brian Schrok
Another variation:
The untested example above has several problems.
- The EMERGENCY variable is never set to zero (the context ends after the call is completed; priority 911,4 is never reached) Which means it can only grab a line once!
- The Dial command might jump to 105 if (a) the 911 callcenter is busy, or (b) the outbound trunk has become busy again, which may not be what you want
- There are race conditions which cannot be solved without writing a "smash and grab" application within Asterisk (the example below does not solve that)
- The Wait(1) should be long enough for a digital trunk (and in fact should be unnecessary with a digital trunk) ... but with an analog trunk it may not be long enough. In my situation I found that nothing under 12 seconds worked. The only way to know is to test.
- Never, *EVER* set up an emergency calling context that you haven't tested with every possible scenario.
Here is a context that I tested and debugged quite a bit. It is ugly, even more complicated and even more difficult to understand. In general I prefer the KISS principle (Keep it Simple, Stupid!) and I think that's particulary important for emergency calls... But anyway, here it is. Be sure to test it (not with a real 911 callcenter!) before you use it.
[globals]
EMERGENCY=0
EMERGENCY_TRUNK=Zap/17
; Change this for production use:
EMERGENCY_NUM=some_test_phone_number
[nineoneone]
exten => s,1,SetVar(SET_EMERG_FLAG=0)
exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})
exten => s,n,SetGlobalVar(EMERGENCY=1)
exten => s,n,SetVar(SET_EMERG_FLAG=1)
exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})
exten => s,s+2(trunkbusy),GotoIf($[${EMERGENCY} = 1]?inprogress)
exten => s,n,SoftHangup(${EMERGENCY_TRUNK}-1)
exten => s,n,Wait(12)
exten => s,n,Goto(checkavail)
exten => s,s+2(inprogress),Congestion
exten => s,checkavail+101(notavail),Goto(trunkbusy)
exten => h,1,GotoIf($[${SET_EMERG_FLAG} = 1]?3)
exten => h,3,SetGlobalVar(EMERGENCY=0)
[your_main_context]
exten => 911,1,Goto(nineoneone,s,1)
...etc...
-- Added by Bicster, 27 October 2004
Edited by Christian Hoffmeyer 14January2004
See Also
- Asterisk tips and tricks
- Emergency Notification
- Emergency Calls - All countries
- VOIP 911 Service Providers
Asterisk | Asterisk Configuration | The Dialplan - extensions.conf
Comments
333However...
Any advice on how to avoid this would be appreciated.
333Without priority jumps
[globals] ;Set this to the appropriate port for your setup EMERGENCY_TRUNK=Zap/4 EMERGENCY=0 ;Set this appropriately - this works fine in UK but don't use it when testing EMERGENCY_NUM=112 [emergency] exten => s,1,ExecIf($[${EMERGENCY}=1],Congestion) exten => s,n,Set(EMERGENCY=1,g) exten => s,n,Set(SET_EMERG_FLAG=1) exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM}) exten => s,n,GotoIf($["${DIALSTATUS}"="CHANUNAVAIL"]?hangup) exten => s,n+1(hangup),SoftHangup(${EMERGENCY_TRUNK}-1) exten => s,n,Wait(12) exten => s,n,Goto(dial) exten => h,1,ExecIf($[${SET_EMERG_FLAG}=1],Set,EMERGENCY=0,g) [allow-emergency] ;include this context in that of all phones that are allowed to make emergency calls ;remember, these numbers are for UK - please adjust accordingly exten => _112!,1,Goto(emergency,s,1) exten => _999!,1,Goto(emergency,s,1)333Without priority jumps
globals<br>
;Set this to the appropriate port for your setup<br>
EMERGENCY_TRUNK=Zap/4<br>
EMERGENCY=0<br>
;Set this appropriately - this works fine in UK but don't use it when testing<br>
EMERGENCY_NUM=112<p>
emergency<br>
exten => s,1,ExecIf($${EMERGENCY}=1,Congestion)<br>
exten => s,n,Set(EMERGENCY=1,g)<br>
exten => s,n,Set(SET_EMERG_FLAG=1)<br>
exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})<br>
exten => s,n,GotoIf($"${DIALSTATUS}"="CHANUNAVAIL"?hangup)<br>
exten => s,n+1(hangup),SoftHangup(${EMERGENCY_TRUNK}-1)<br>
exten => s,n,Wait(12)<br>
exten => s,n,Goto(dial)<br>
exten => h,1,ExecIf($${SET_EMERG_FLAG}=1,Set,EMERGENCY=0,g)<p>
allow-emergency<br>
;include this context in that of all phones that are allowed to make emergency calls<br>
;remember, these numbers are for UK - please adjust accordingly<br>
exten => _112!,1,Goto(emergency,s,1)<br>
exten => _999!,1,Goto(emergency,s,1)<br>
333Re: Re: Re: What is n(checkavail)?
: exten => s,s+2(trunkbusy),GotoIf($${EMERGENCY} = 1?inprogress)
: exten => s,s+2(inprogress),Congestion
Any real reason to do so apart from possibly making it clearer from the script-maker point of view?
333Blocking 911 from Extenal Extensions
from-wan
;deny access to 911 for extensions outside of the house
;added by John Mullinix
exten => 911,1,answer
exten => 911,2,Playback(no-911-2)
exten => 911,3,AGI(festival-script.pl|Please use your land based phone to call 9 1 1.)
exten => 911,4,Congestion
exten => 911,5,Hangup
include => from-internal
This short section of code intercepts the 911 call and informs the caller to use their land based phone to call. It allows all other calls to be handled by the "from-internal" context.
333Re: Re: Re: What is n(checkavail)?
333Re: Re: What is n(checkavail)?
333Re: What is n(checkavail)?
: exten => s,n,Goto(checkavail)
will jump to this line:
: exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})
333What is n(checkavail)?
Can you please explain what is n(checkavail) or s+2(inprogress).
I couldn't find any info on that.
Regards