E-Mail Feature for certain Dialstatus

Hello Folks,

currently i am developing a little Script which gets called wenn a certain Dialstatus is reached
I want to run this script right before the hangup, so i get the status even if the Call was not answered by someone (e.g. NOANSWER) so i can send a Mail or something other.

I am struggeling with 2 things:
1.) which macro can i use to execute the script? I’ve tried “macro-dialout-one-predial-hook” but i am not really sure if this is the right place because it will be executed right before the “Dial”-App. Can anyone point me into the right direction?

VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:50] Macro("PJSIP/Trunk-0000023d", "dialout-one-predial-hook,") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dialout-one-predial-hook:1] NoOp("PJSIP/Trunk-0000023d", "Dialstatus Script") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:51] ExecIf("PJSIP/Trunk-0000023d", "0?Set(D_OPTIONS=HhtrI)") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:52] ExecIf("PJSIP/Trunk-0000023d", "0?Set(CWRING=r(callwaiting)):Set(CWRING=)") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:53] NoOp("PJSIP/Trunk-0000023d", "") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:54] ExecIf("PJSIP/Trunk-0000023d", "0?Set(D_OPTIONS=HhTtrg)") in new stack
VERBOSE[4126][C-00000125] pbx.c: Executing [s@macro-dial-one:55] Dial("PJSIP/TrunkName-0000023d", "SIP/9925&SIP/25,15,HhTtrb(func-apply-sipheaders^s^1)") in new stack

2.) in this macro “macro-dialout-one-predial-hook” (which i defined in extensions_custom.conf) it seems that i don’t have the Variable “DIALSTATUS” anymore. When i try to echo it, the Variable is empty. So i did a dump_chan:

Variables:
MACRO_DEPTH=3
SYSTEMSTATUS=SUCCESS
ARG1=
MACRO_PRIORITY=50
MACRO_CONTEXT=macro-dial-one
MACRO_EXTEN=s
DB_RESULT=TestUser
KEEPCID=TRUE
CWIGNORE=
D_OPTIONS=HhTtr
GOSUB_RETVAL=
DSTRING=SIP/9925&SIP/25
ITER=3
THISDIAL=SIP/25
LOOPCNT=2
DEVICES=9925&25
EXTHASCW=
DIALSTATUS_CW=
DEXTEN=25
ARG3=25
ARG2=HhTtr
RECMODE=dontcare
CALLEE=dontcare
CALLTYPE=internal
REC_POLICY_MODE_SAVE=
MON_FMT=wav
FROMEXTEN=123456789
TIMESTR=20200330-115312
YEAR=2020
MONTH=03
DAY=30
NOW=1585561992
REC_STATUS=INITIALIZED
RT=15
PICKUPMARK=25
EXTTOCALL=25
RingGroupMethod=none
TTL=64
CALLEE_ACCOUNCODE=
AMPUSERCIDNAME=
AMPUSER=
REALCALLERIDNUM=123456789
HOTDESKCALL=0
HOTDESKEXTEN=Trunk
HOTDESCKCHAN=Trunk-0000023d
TOUCH_MONITOR=1585561992.714
RINGTIMER=15
CALLINGNUMPRES_SV=allowed_not_screened
CALLINGNAMEPRES_SV=allowed_not_screened
REVERSAL_REJECT=FALSE
MOHCLASS=default
CALLED_BLACKLIST=1

How can i acces the Dialstatus? I think i am a little bit lost atm.

Thanks in advance

Use the predial hook to add a hangup handler

https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

How would that work when the caller gets sent to voicemail? There wouldn’t be a hang up until the voicemail app is exited which could have a different result than the actual reason the call wasn’t answered.

Just because the dialed endpoint didn’t answer doesn’t mean there is a hangup immediately after that.

OP would need to work with the ${VMSTATUS} do determine weather the call was sent to voicemail and if a voicemail was left.

It seems to me that OP is looking to implement a missed call solution, I have written something like this in the past, it works fine. The only issue is, that the predial hook does not work with offline PJSIP extensions.

Not exactly missed call solution, this would be only a small part of it, thats why i asked where the best Place for a macro/hook is and how i can get the Dialstatus outside the Dial Application (cause it seems it is not available in “macro-dialout-one-predial-hook”

The Dial() application has to be completed before it can issue a DIALSTATUS. Doing any checks before the initial Dial() for that will not work as it doesn’t exist.

Ok, so what hook / macro should i use then? I am a little bit confused right now.

Well I guess it depends on what you are looking to do. Are you looking to alert that a call was dialed to a specific extension and just wasn’t answered? Or are you looking to alert each contact that should be related to the endpoint?

Then you need to be a little more detailed on what you are looking to do. What statuses you want, at what point do you want them, etc. There could be a few ways to skin this cat but without knowing routing logic of non-answered calls it will be hard to tell you when and where to inject this.

Well i am talking about every incoming call from external.
I want to track down the Dialstatus right before the call ends with the hangup.
To stay with the example of missed Calls:
If a customer is calling from outside the PBX and hangs up before any extension is taking the call.
Where would i inject my script to get the Status NOANSWER so i can send a Missed Call E-Mail?

OK then that means you need to look for certain variables that are set when an external call comes in. Those would be ${DIRECTION} and ${FROM_DID}, if either of those are set it is an external call that hit a DID/Inbound Route.

Here are the problems with that: Call Forwarding, FollowMe and Alternate Destinations. All off those are looked at right after a unanswered call and before a hangup. So that call could be re-routed to another destination before the hangup happens and another Dial() could be issued. Now those could go unanswered and then you’ll need to deal with it for each of those.

The dialstatus is set on the channel right after the Dial() application completes. FreePBX also sets it to a custom variable ${SV_DIALSTATUS} that you can try to look for as ${DIALSTATUS} is lost once the channel is destroyed.

Ahhh, that is a canceled call not a unanswered call. So at that point the hangup would happen immediately because the original channel was destroyed. But then you would need to track this on that channel not the Dial()'d channels.

This is quite doable so if the routing is very simple for calls you may only have one or two spots you might have to inject your custom hangup handler in and more spots if the routing gets more complex (Local channels, multiple re-routes, etc).

Ok, understood, i think this is quite easy to obtain.

Ok, this Variable is -in macro-dialout-one-predial-hook- not available. So i think this is the wrong place to check for it. We don’t use the FME Feature and don’t have any other Extensions then normal Phones. It is a very simple and small PBX (5 Extensions only) so there are no special Routings or so.

Yes this was my initial question: Where would i need to inject my Script
(or in Step 1 a simple GotoIf($["${DIALSTATUS}"="CANCEL"])yes:no )
to track down the Status. Do i need to create a macro in extensions_custom.conf? Can i use an existing macro?

Perhaps another approach?

If this is for for post-mortem conditional reporting, Then there will be a record of all channels invoved in any call in the mariadb asteriskcdr.cel table grouped by linkedid.

A stored procedure triggered by en eventtype of HANGUP that checks for a not null string DIALSTATUS in the extra field, could trigger a use-case specific select , perhaps into the cdr table on the uniqueid .

Mysql cant directly email by design, but it can trigger an incron/inotify recognizable file creation to achieve that end maybe start with

mysql asteriskcdrdb -e  " SELECT *  FROM cel WHERE eventtype = 'HANGUP' AND  extra NOT LIKE   '%\"dialstatus\":\"\"%' ORDER BY eventtime DESC LIMIT 5;"

Á caveat, this has not ben tested by me but similar things have.

I will try this for sure. Thanks for pointing me in this direction.

1 Like

If you go that route I suggest you :-

mysql asteriskcdrdb -e ’ ALTER TABLE cel ADD INDEX (eventtime)’

to improve performance cos cel gets effing 'uge

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.