Send Email or SMS notification for EVERY inbound hangup call

I am searching for a way to have FreePBX send out an Email or SMS for every inbound call who hangs up. I discovered on this board the suggestion below however, I am unable to get it to work.

It seems my hangup is knowing exactly where to put the suggested “local/s@send-email” line.

Does anyone have a better way to accomplish this task?


QUOTE

lgaetzLorne GaetzSangoma

If I was doing this, I would create a new context in /etc/asterisk/extensions_custom.conf with content similar to:

[send-email]
exten => s,1,NoOp(Entering user defined context [send-email] in extensions_custom.conf)
exten => s,n,System(echo ‘Call from ${CALLERID(name)} at ${CALLERID(number)}’ | mail -s ‘SUBJECT’ ‘[email protected]’)
exten => s,n,hangup()

Then in FreePBX create an extension of type, other (custom) device, give it a name and number. In the dial field use:

local/s@send-email

Now you have a local dummy extension that will execute custom code whenever it is dialed. You can include it in ring groups, or queues, etc. It will never answer the call, but whenever it rings it will execute the custom code. You have the basis for adding your own code for whatever you can dream up once you learn a bit of Asterisk.

edit - fixed system line quote

1 Like

The context

[macro-hangupcall]
include => macro-hangupcall-custom
exten => s,1(start),GotoIf($["${USE_CONFIRMATION}"="" | "${RINGGROUP_INDEX}"="" | "${CHANNEL}"!="${UNIQCHAN}"]?theend)
exten => s,n(delrgi),Noop(Deleting: RG/${RINGGROUP_INDEX}/${CHANNEL} ${DB_DELETE(RG/${RINGGROUP_INDEX}/${CHANNEL})})
exten => s,n(theend),Hangup
exten => s,n,MacroExit()

so create your context in extensions_custom.conf

[macro-hangupcall-custom]
exten => s,1,DumpChan()
exten => s,n,System(echo ‘Call from ${CALLERID(name)} at ${CALLERID(number)}’ | mail -s ‘SUBJECT’ ‘[email protected]’)
exten => s,n,MacroExit()

If you need to filter so not EVERY call is responded to, that would be where to do it also.

What triggers this macro into action?

It is run every time Macro(hangupcall) is called, that is pretty well everything, that’s why I included to DumpChan() call, you can look at the log files and filter as appropriate. possibly on ${HANGUPCAUSE}

Unfortunately, I am still unsure as to what exactly starts the macro. Is it called via a Custom Destination like “Lenny” (Telemarketer Torture)?

I don’t now how to answer more clearly, if you look at your dialplan you will see that almost invariably Macro(hangupcall) is called on a hangup, thusly if Macro(hangupcall) is called (it will be) then (if the dialplan has been reloaded, Asterisk has been restarted or you reboot the system) then every hungup call will ‘include’ first your custom code, then the default code.

From the Wiki/Sample Configs of Asterisk:

“The order of matching within a context is always exact extensions, pattern match extensions, includes, and switches.”

That means that all the dialplan within macro-hangup that meets that criteria will be executed first followed by the includes (in their included order). That means

[main-context]
include => other-context
exten => _XX,1,NoOp(Something)
exten => 945,1,NoOp(Someting)

[other-context]
exten => _XX,1,NoOp(Other Something)

_XX will match in [main-context] first then look in [other-context]. Includes are executed after existing exten => code is processed in the context.

ADDITION:
It doesn’t matter if the include => is at the start or the bottom of the context.

[main-context]
include => other-context
exten => _XX,1,NoOp(Something)
exten => 945,1,NoOp(Someting)

AND

[main-context]
exten => _XX,1,NoOp(Something)
exten => 945,1,NoOp(Someting)
include => other-context

Does the same. The only real order that matters to include=> is the order of the contexts you want to include in a top/down manner.

[main-context]
include => addon-context1 <-- Matched first over addon-context2
include => addon-context2 <-- Matched second, etc, etc
exten => _XX,1,NoOp(Something) <--- Still matched first before the included contexts.