911 Alert email to different recipient depending on calling number

I have a custom dial plan in extensions_custom.conf to send an email to security whenever a 911 call was made.
This works well, but I have an additional requirement.
I need to be able to send the email to a different recipient depending on what extension (or CID) made the call.

Reason being, that some extensions are remote and a different security person has to be notified.

So, e.g. if 911 call was made from extension 1234 or 1235, send the email to email address 1.
From all other extensions, send email to address 2.

How would I change below dial plan to do that?

[macro-dialout-trunk-predial-hook]
exten => s,1,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,n,MacroExit()

Maybe you should add DumpChan() to you custom dialplan, then see what you get message-wise and then season to taste for any appropriate differences

That way every channel variable is exposed in that channel at that moment, then YOU can get busy :wink:

That was easier than I thought:

[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${AMPUSER}" = "1000" | "${AMPUSER}" = "1001"]?2:4) 
exten => s,2,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected] [email protected]))
exten => s,3,MacroExit()
exten => s,4,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,5,MacroExit()

Sorry to bring up an old post, but I have 300 extensions that need to go to one email, and then 300 others that need to go to another email.

The rabbit hole I was thinking is they are separated by their emergency CID number, can I route emails that are sent in custom.conf based on that?

One would think so. Any differentiator that works can be coded into the “s,1” line. If you query the Emergency CID information in the “ifgoto()” to send the call to priority ‘2’ or ‘4’.

Agreed, just cant find what to reference.

Instead of AMPUSER I need the database field name for Emergency CID.

Is there some reason you can’t use AMPUSERCIDNAME?

${DB(DEVICE/${AMPUSER}/emergency_cid)}
1 Like

Great! That is exactly what I needed.

Thanks for your help, I am right on the cusp of the finish line.

For the benefit of the forum, I’d like to share what I did so others can use it as well, if needed.

[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "99999999999" | "${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "88888888888" | "${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "7777777777"]?2:4:6) 
exten => s,2,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld1: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,3,MacroExit()
exten => s,4,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld2: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,5,MacroExit()
exten => s,6,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld3: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,7,MacroExit()

Now, how to catch the ones who don’t meet the first criteria but are calling 911, can I add the execIF at line 2 and bump all the others down. For example:

[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "99999999999" | "${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "88888888888" | "${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "7777777777"]?4:6:8) 
exten => s,2,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "OUTSIDE Bld: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,3,MacroExit()
exten => s,4,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld1: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,5,MacroExit()
exten => s,6,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld2: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,7,MacroExit()
exten => s,8,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bld3: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,9,MacroExit()

That way if it has a defined Emergency CID it can go to a specific group assigned per main building. But if it didn’t meet the gotoif it’ll get sent to an all alert address.

Some backround: Public school system with 3 main buildings and about 60 classrooms in 39 other buildings across 5 counties. The classrooms are connected to our pbxact and have assigned emergency CID numbers so the E-911 addresses are correct for the 42 locations that we have in total.

A couple of things that might change your code a little bit:

  1. The function GotoIf() has a specific set of arguments: (Condition?true:false). This means if “Condition” is true, the ‘true’ context priority is executed, if false, the ‘false’ priority is executed. You have ‘4:6:8’ and are hoping that the three ‘arguments’ are checked individually. Your condition (in English) is "if the Emergency Caller ID is one of the following: 999,888,777, just to 4 otherwise jump to 6. The ‘8’ in your code will always be ignored.

  2. In a normal context, the ‘s’ extension is the extension you are dialing. If you change it to ‘911’, the code will only be executed if the “OUTNUM” is ‘911’. Since this is a macro, we have to use an ‘s’ extension.

Take a look at this and see if it might do what you are hoping for:

>exten => s,1,ExecIf($["${OUTNUM}"="911"]?2:102)
>exten => s,2,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "999999999"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg1: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
>exten => s,3,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "888888888"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg2: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
>exten => s,4,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "777777777"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg3: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
> "more exten lines"
>exten => s,102,MacroExit()
1 Like

An Asterisk macro requires an s extension.

Oh crap, that’s right. I forgot that.

Let me make another run at that then…

About to edit the original code - do not be confused. That should be closer, but without having a phone server to try it on here, there might still be the occasional bracket/brace/parenthesis error in there. I can’t test it.

Thanks guys, this is a massive help.

My final question, can I just add a catch-all at the end to get the ones who don’t meet the specified criteria. In this case, I want the ones that meet the 3 emergency CID lines to send 1 email, and then hit the catch-all as well.

[macro-dialout-trunk-predial-hook]
exten => s,1,ExecIf($["${OUTNUM}"="911"]?2:102)
exten => s,2,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "999999999"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg1: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,3,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "888888888"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg2: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,4,ExecIf($["${DB(DEVICE/${AMPUSER}/emergency_cid)}" = "777777777"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "Bldg3: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,5,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "OUTSIDE: 911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,102,MacroExit()

Sort of.

exten => s,5,System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} …

You don’t need to recheck if OUTUM is 911 - you already did that. The only way to get to this line of the context is if the OUTNUM is 911.

You may also (for completeness) want to add an “exten=>s,n,MacroExit()” line after the “catchall” line. I don’t remember if the MacroExit at 102 will get executed if the priority number is not next in the sequence and leaving it to just “fall through” could (theoretically) give you an unpredictable result…

For that matter, you can change each of the “s,3”, “s,4”, and “s,5” to “s,n” since there are no references to those priority numbers. It’s a minor change - what you have now will work and adding another line to the context could be “s,6” if you don’t change them.

Thanks for all your help! Very happy with how it is working now.