Extension for sending emails on missed calls

Hi together,

I want to send an email notification on missed calls.
Following is sending me an email on every call, how to do that only for missed calls?

[from-pstn-custom]
exten => _X.,1,NoOp(My Script Beginning)
same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?done)
same => n,System(echo "Missed Call From ${CALLERID(num)}" | mail -s "Missed Call From ${CALLERID(num)}" [email protected])
same => n(done),NoOp()

~

Thx, Axel

Why not call the email function on the same line as your condition, and use a negative comparison?

ExecIf($["${DIALSTATUS}" != "ANSWER"]?dostuff)

https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Application_ExecIf

Your issue might be a problem with the order that the dialplan is being interpreted; can you confirm that this code happens after the call is answered and not before? Try including something like this in your code to determine the state that is generating the email…my guess is that the code works but the state is different from what you expect.

"Missed Call (${DIALSTATUS}) from..."

Hi Overkill,

I checked - the code is called before the call is answered, not after, so this will be the problem.

What is the right hook in FreePBX to get this code after the call, not before?

I tried the following:

[from-pstn-custom]
exten => _X.,1,System(echo "mytest from-pstn-custom")
[ext-did-post-custom]
exten => _X.,1,System(echo "mytest ext-did-post-custom")
[ext-did-custom]
exten => _X.,1,System(echo "mytest ext-did-custom")

When I call and hang up after ringing, I get before I hangup:

[[email protected] ~]# tail -f /var/log/asterisk/full  |  grep mytest
[2016-12-19 07:08:29] VERBOSE[32473][C-00000001] pbx.c: Executing [[email protected]:1] System("PJSIP/peoplefone_90586055542-00000003", "echo "mytest from-pstn-custom"") in new stack

But I would need it afterwards :slight_smile:

Thx, Axel

Hi Folks,

Does sombody now which extension to use to execute code after ringing and before hangup?
See problem above - I need to send an Email for missed calls, but do not know which hook to use.

BR, Axel

Hi,

for trunks you can use this hook: macro-dialout-trunk-predial-hook

for extensions you can use this hook: macro-dialout-one-predial-hook

Thank you,

Daniel Friedman
Trixton LTD.

Hi Daniel,

Thx for you Reply - I need the other direction:
If a customer is calling from outside the PBX and hangs up before any extension is taking the call.
What ist the right hook for this?

BR, Axel

Hi,

It is the same hook. Once the call hits the from-internal context, it will go to one of the hooks if they are configured.

Thank you,

Daniel Friedman
Trixton LTD.

Hi Daniel,

I tried

[macro-hangupcall-custom]
exten => _X.,1,System(echo "mytest macro-hangupcall-custom")

[macro-dial-one-custom]
exten => _X.,1,System(echo "mytest macro-dial-one-custom")

[macro-dialout-trunk-predial-hook]
exten => _X.,1,System(echo "mytest macro-dialout-trunk-predial-hook")

[macro-dialout-one-predial-hook]
exten => _X.,1,System(echo "macro-dialout-one-predial-hook")

no of the four is getting called when a customer calls from outside.

BR, Axel

Hello,

That is because you are not writing it correctly. Here is an example for you to follow and customize.
Add it to your extensions_custom.conf file:

For trunks:

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(mytest macro-dialout-trunk-predial-hook)
exten => s,n,MacroExit()

For extensions:

[macro-dialout-one-predial-hook]
exten => s,1,NoOp(mytest macro-dialout-one-predial-hook)
exten => s,n,MacroExit()

Then type rasterisk -x'dialplan reload' in the Linux console.

Thank you,

Daniel Friedman
Trixton LTD.