GoToIf Issues

I’m having a weird issue - probably due to ignorance - with a bit of asterisk dialplan. I am attempting to get only certain calls to apply a SIP header with the below dialpan:

[macro-dialout-one-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(ACCOUNTCODE=${DB(AMPUSER/${CALLERID(dnid)}/accountcode)})
exten => s,n,Noop(${ACCOUNTCODE})
exten => s,n,GotoIf("${ACCOUNTCODE}" = "Folsom"]?special)
exten => s,n,MacroExit
exten => s,n(special),Noop(Auto Answer Call)
exten => s,n,Gosub(func-set-sipheader,s,1(Alert-Info,Auto Answer))
exten => s,n,MacroExit

Essentially I am trying to lookup the accountcode for the called party, and if it matches the value specified in the dialplan, move forward with applying the sip header. If not, it should exit (I think).

Here is the snippet of my test call, where I expected it to exit prior to applying the headers. At this point, all calls are applying the sip header which is not intended:

[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dial-one:50] Macro("PJSIP/507-0000184b", "dialout-one-predial-hook,") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:1] NoOp("PJSIP/507-0000184b", "Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("PJSIP/507-0000184b", "ACCOUNTCODE=Layer7") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:3] NoOp("PJSIP/507-0000184b", "Layer7") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:4] GotoIf("PJSIP/507-0000184b", ""Layer7" = "Folsom"]?special") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx_builtins.c: Goto (macro-dialout-one-predial-hook,s,6)
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:6] NoOp("PJSIP/507-0000184b", "Auto Answer Call") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@macro-dialout-one-predial-hook:7] Gosub("PJSIP/507-0000184b", "func-set-sipheader,s,1(Alert-Info,Auto Answer)") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@func-set-sipheader:1] NoOp("PJSIP/507-0000184b", "Sip Add Header function called. Adding Alert-Info = Auto Answer") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@func-set-sipheader:2] Set("PJSIP/507-0000184b", "HASH(__SIPHEADERS,Alert-Info)=Auto Answer") in new stack
[2023-07-20 11:26:41] VERBOSE[29889][C-00000ab0] pbx.c: Executing [s@func-set-sipheader:3] Return("PJSIP/507-0000184b", "") in new stack

I’m rubbish with asterisk dialplan so any help is appreciated.

 exten => s,n,GotoIf("${ACCOUNTCODE}" = "Folsom"]?special)

You have a syntax error. You’re missing the opening $[ for this. It should be:

exten => s,n,GotoIf($["${ACCOUNTCODE}" = "Folsom"]?special)
1 Like

Yep that was it. Appreciate it :+1:

How would I play a beep after the auto answer occurs? I have previously done it with a Dial and a beep but that actually prevents the auto answer from working properly.

[macro-dialout-one-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(ACCOUNTCODE=${DB(AMPUSER/${CALLERID(dnid)}/accountcode)})
exten => s,n,Noop(${ACCOUNTCODE})
exten => s,n,GotoIf($["${ACCOUNTCODE}" = "Folsom"]?special)
exten => s,n,MacroExit
exten => s,n(special),Noop(Auto Answer Call)
exten => s,n,Gosub(func-set-sipheader,s,1(Alert-Info,Auto Answer))
exten => s,n,Dial(${DSTRING},5,A(beep))
exten => s,n,MacroExit

Here’s that section of the call

    -- Goto (macro-dialout-one-predial-hook,s,6)
    -- Executing [s@macro-dialout-one-predial-hook:6] NoOp("PJSIP/507-00001890", "SIP/511&SIP/518&PJSIP/515/sip:515@PHONEWANIP:1083;x-ast-orig-host=192.168.50.62:0") in new stack
    -- Executing [s@macro-dialout-one-predial-hook:7] NoOp("PJSIP/507-00001890", "") in new stack
    -- Executing [s@macro-dialout-one-predial-hook:8] Gosub("PJSIP/507-00001890", "func-set-sipheader,s,1(Alert-Info,Auto Answer)") in new stack
    -- Executing [s@func-set-sipheader:1] NoOp("PJSIP/507-00001890", "Sip Add Header function called. Adding Alert-Info = Auto Answer") in new stack
    -- Executing [s@func-set-sipheader:2] Set("PJSIP/507-00001890", "HASH(__SIPHEADERS,Alert-Info)=Auto Answer") in new stack
    -- Executing [s@func-set-sipheader:3] Return("PJSIP/507-00001890", "") in new stack
    -- Executing [s@macro-dialout-one-predial-hook:9] Dial("PJSIP/507-00001890", "SIP/511&SIP/518&PJSIP/515/sip:515@PHONEWANIP:1083;x-ast-orig-host=192.168.50.62:0,5,A(beep)") in new stack
[2023-07-20 14:46:04] NOTICE[7929][C-00000ad5]: app_dial.c:2687 dial_exec_full: Unable to create channel of type 'SIP' (cause 20 - Subscriber absent)
[2023-07-20 14:46:04] NOTICE[7929][C-00000ad5]: app_dial.c:2687 dial_exec_full: Unable to create channel of type 'SIP' (cause 20 - Subscriber absent)
  == Begin MixMonitor Recording PJSIP/507-00001890
    -- Called PJSIP/515/sip:515@PHONEWANIP:1083;x-ast-orig-host=192.168.50.62:0
  == Using SIP RTP Audio TOS bits 184
  == Using SIP RTP Audio TOS bits 184 in TCLASS field.
  == Using SIP RTP Audio CoS mark 5
    -- PJSIP/515-00001891 is ringing

While you are adding SIP headers to the header hash you are never applying them in your Dial() command. You need to have:

exten => s,n,Dial(${DSTRING},5,A(beep)b(func-apply-sipheaders^s^1))
1 Like

Works a treat. Thanks!

Got it to auto answer and play the beep?

Yep. Auto answers and plays the beep on the receiving end.

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