911 email notification - dialplan question

This subject isn’t new and there are many ways to achieve this. We want to keep simple and in fact only 3 new lines are required in the dialplan. This is working but could be more future proof?

Basically I done that:
-edit extensions_custom.conf file:

[from-internal-custom]
exten => 911,1,Macro(user-callerid)
exten => 911,n,System(echo “Appel au 911 depuis le poste ${CALLERID(NUM)} […etc…] )}” | mail -s “ALERTE 911 de ${CALLERID(NUM)} - ${CALLERID(NAME)}” email@address)

This context is included at the begining and after the call continue to the next context matching “911”. BUT the next priority in this case is “3” so the first two commands aren’t executed. Lukily the call is execute correctly but I don’t like this behavior. We are talking about emergency calls…

The solution is to add this line in the custom context:

exten => 911,n,Goto(outrt-4,911,1)

The “outrt-4” is the context where the 911 call is made. This way we put the execution to the first command in the context. Ok this is better but what will happen if we change something in FreePBX and the context name change?

In other words, is it possible to include the custom context like a did to send email and continue to the next action normally executed at the first place? Just thinking, is it possible, at the end of the custom context to reset the “n” priority to “1”? I’m a rooky in the dialplan code so maybe someone with better experience know a better way.

Thanks

I think a better place for this code is in /etc/asterisk/extensions_custom.conf with the [macro-dialout-trunk-predial-hook] code - check for the 911 and then send your message if it is there and then continue on - we use this hook to add a P-Asserted identity, but any valid code will execute here.

Here is what we use it for:

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Adding P-Asserted-Identity)
exten => s,n,ExecIf($["${TRUNKOUTCID}"=“505XXXXXXX”]?SipAddHeader(P-Asserted-Identity: sip:[email protected] )
exten => s,n,Set(FAXOPT(gateway)=yes,10)
exten => s,n,MacroExit()

1 Like

Great! Thanks GSnover!
This is exactly what I was looking for. I didn’t know about this macro (macro-dialout-trunk-predial-hook).
Your solution works like a charm with this 3 lines in the dialplan:

[macro-dialout-trunk-predial-hook]
exten => s,1,ExecIf($[“${OUTNUM}”=“911”]?System(echo “Appel au 911 depuis le poste ${CALLERID(NUM)} - ${CALLERID(NAME)} at ${STRFTIME(%C%m%d%y%H%M)}” | mail -s “ALERTE 911 de ${CALLERID(NUM)} - ${CALLERID(NAME)}” email@address))
exten => s,n,MacroExit()

But how to do the same with a internal emergency number? If someone calls “555”, how to send an email since it will never transfer to a trunk?
Is there a macro like this one but for from-internal context? The only way I’ve found is to use the “from-internal-custom” (my first solution). I dont see predefine macro we can customize from this context.

Bonjour!
(Hi!)

macro-dialout-one-predial-hook

There are a few others for other purposes… If you want to see what is available you can look in extensions.conf.

Don’t modify anything there though, it would get overwritten

Bonne chance et bonne journèe!
(Good luck and have a nice day!)

Nick

1 Like

Bonjour Marbled!

I took a look in extensions.conf and you are right I have found some others left blank macros we can customize. This one works for internal calls:

[macro-dialout-one-predial-hook]

That is exactly what I was looking for. Just to be advice that this macro won’t be executed if the extension is not registered.

Merci beaucoup!

Bonjour!
(Hi!)

I know… :wink:

(I guess I should have put more emphasis on it when I mentioned it, it looks like you had to go through all of them…Luckily I think there are only like 4 or 5… :slight_smile:)

My guess is that it might since it is predial but I didn’t check and can’t right now…

De rien!
(You are welcome!)

Nicolas

Some suggestions for you. Instead of hard coding “911”, I use an outbound route called “emergency”. That route contains 911, poison control, and various other emergency numbers.
If anyone calls any emergency number, or the security / fire systems call the central stations, then I immediately get an SMS message. Asterisk automatically records the emergency calls and when it is completed, emails me an mp3, so I can get a heads-up of what is happening while we are en-route to the location.

Also, I have a number defined “922” for testing the emergency systems without actually calling 911.

Just some ideas for you.

This works great, except the ${CALLERID(NUM)} is the trunk or route CallerID. How do I make it the CID of the extension?

Great ideas! Your solution is far more complete than I would expect and I will definitly look a it. For the moment the solution with dialplan works but we get only email notification.
Thanks!

You’re right. When I did the test the calls didn’t actually passed to the trunk and the ${CALLERID(NUM)} was working. Here what I use to get the extension’s number and name:

exten => s,n,ExecIf($[“${OUTNUM}”=“911”]?System(echo “Appel au 911 depuis le poste ${AMPUSER} - ${AMPUSERCIDNAME} at ${STRFTIME(%C%m%d%y%H%M)}” | mail -s “ALERTE 911 de ${AMPUSER} - ${AMPUSERCIDNAME}” email@address))

This is working with Asterisk 13.2.

There’s a back story to why I did this, if you are interested.

One afternoon I was driving home from work, and as I pulled onto my street, there was a line of firetrucks and police cars. As I got closer to my house, I saw firetrucks surrounding my house and the state police helicopter next to my back yard.

For 10 minutes I sat in my car and couldn’t get near my house. It was a horrible feeling not knowing what was happening, my wife and kids were in there. No one answered the phone, the police blocked off the road.

Once the helicopter lifted off I was able to get in and then I found out what was happening. My elderly neighbor was cleaning up brush on his farm, he was burning it. He lost control and got trapped in the fire. My kids saw this and called for rescue. He died on the way to the hospital.

Thanks for providing the code.

May I suggest you include it in a Features Request and submit it so that everyone can benefit from your resourcefulness and perhaps avoid a similar catastrophe in the future.

Perhaps one of the developers can put a control page on the front of it and make a real, human safety improvement to the system.