How to handle GotoIf() on Read() input when a caller enters nothing

A quick question. How can i use the GotoIf() after a caller has not given any input. Getting an error message. Which is obvious cause ctbIvrMenuEmployeeByIntroductionUserChoice is not set.

The dialplan

exten => 1,1,Verbose(Ivr menu employee by introduction init)
same => n,Playback(${ctbPromptIvrMenuUserIntroduction});
; set the the data for the first userprompt to play back
same => n,Set(ref=${SHELL(echo '${ctbJsonResult}' | jq '.data.user'${ctbIvrMenuEmployeeByIntroductionUserPromptCounter}.ref  | tr -d '\n"')})
; check if the user prompt exist, else set the default user prompt
same => n,Set(ctbUserPrompt=${SHELL(test -e /etc/asterisk/dialplans/chattabai/prompts/user/${ref}.sln && echo /etc/asterisk/dialplans/chattabai/prompts/user/${ref} | tr -d '\n"' || echo /etc/asterisk/dialplans/chattabai/prompts/user/thisUserDoesNotHaveAPrompt | tr -d '\n"')})
same => n,read(ctbIvrMenuEmployeeByIntroductionUserChoice,${ctbUserPrompt},1)
; on 1 forward to the user
same => n,GotoIf($[${ctbIvrMenuEmployeeByIntroductionUserChoice}=1]?ctbIvrMenuEmployeeByIntroductionForwardToUser,1,1:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,7)
; on 2 goto the next user
same => n,GotoIf($[${ctbIvrMenuEmployeeByIntroductionUserChoice}=2]?ctbIvrMenuEmployeeByIntroductionUserPrompt,1,8:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,11)
same => n,Verbose(Ivr menu employee by introduction going to the next user)
same => n,Set(ctbIvrMenuEmployeeByIntroductionUserPromptCounter=${MATH(${ctbIvrMenuEmployeeByIntroductionUserPromptCounter}+1)})
same => n,Goto(ctbIvrMenuEmployeeByIntroductionUserPrompt,1,3)
; on 9 goto the main menu
same => n,GotoIf($[${ctbIvrMenuEmployeeByIntroductionUserChoice}=9]?ctbIvrMenuEmployeeByIntroductionUserPrompt,1,1:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,12)
; no valid choice given go back to ivr menu employee by introduction
same => n,Playback(${ctbPromptThisIsAnInvalidOption})
same => n,Goto(ctbIvrMenuEmployeeByIntroductionUserPrompt,1,1)

The log

 -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:3] Set("PJSIP/local2-00000027", "ref=000048") in new stack
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:4] Set("PJSIP/local2-00000027", "ctbUserPrompt=/etc/asterisk/dialplans/chattabai/prompts/user/000048") in new stack
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:5] Read("PJSIP/local2-00000027", "ctbIvrMenuEmployeeByIntroductionUserChoice,/etc/asterisk/dialplans/chattabai/prompts/user/000048,1") in new stack
    -- Accepting a maximum of 1 digits.
    -- <PJSIP/local2-00000027> Playing '/etc/asterisk/dialplans/chattabai/prompts/user/000048.slin' (language 'en')
    -- User entered nothing.
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '=', expecting $end; Input:
=1
^
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:6] GotoIf("PJSIP/local2-00000027", "?ctbIvrMenuEmployeeByIntroductionForwardToUser,1,1:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,7") in new stack
    -- Goto (ctbIvrMenuEmployeeByIntroductionUserPrompt,1,7)
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '=', expecting $end; Input:
=2
^
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:7] GotoIf("PJSIP/local2-00000027", "?ctbIvrMenuEmployeeByIntroductionUserPrompt,1,8:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,11") in new stack
    -- Goto (ctbIvrMenuEmployeeByIntroductionUserPrompt,1,11)
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '=', expecting $end; Input:
=9
^
[May 10 01:14:34] WARNING[2401014][C-00000026]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:11] GotoIf("PJSIP/local2-00000027", "?ctbIvrMenuEmployeeByIntroductionUserPrompt,1,1:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,12") in new stack
    -- Goto (ctbIvrMenuEmployeeByIntroductionUserPrompt,1,12)
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:12] Playback("PJSIP/local2-00000027", "/etc/asterisk/dialplans/chattabai/prompts/en/thisIsAnInvalidOption") in new stack
    -- <PJSIP/local2-00000027> Playing '/etc/asterisk/dialplans/chattabai/prompts/en/thisIsAnInvalidOption.slin' (language 'en')
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:13] Goto("PJSIP/local2-00000027", "ctbIvrMenuEmployeeByIntroductionUserPrompt,1,1") in new stack
    -- Goto (ctbIvrMenuEmployeeByIntroductionUserPrompt,1,1)
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:1] Verbose("PJSIP/local2-00000027", "Ivr menu employee by introduction init") in new stack
Ivr menu employee by introduction init
    -- Executing [1@ctbIvrMenuEmployeeByIntroductionUserPrompt:2] Playback("PJSIP/local2-00000027", "/etc/asterisk/dialplans/chattabai/prompts/en/ivrMenuUserIntroduction") in new stack
    -- <PJSIP/local2-00000027> Playing '/etc/asterisk/dialplans/chattabai/prompts/en/ivrMenuUserIntroduction.slin' (language 'en')
    -- Executing [1@chattabai:1] Answer("PJSIP/local2-00000028", "") in new stack
       > 0xffff700bf4b0 -- Strict RTP learning after remote address set to: 190.88.119.147:62858
       > 0xffff700bf4b0 -- Strict RTP qualifying stream type: audio
       > 0xffff700bf4b0 -- Strict RTP switching source address to 172.16.171.1:62858

Put quotes round both operands of =, or prefix LHS with 0. (Take care for numbers over 7.)

I agree with the suggestion for quotes, but regarding the prefix of zero, I
prefer to suffix with zero and divide by 10.

Antony.

Hi David551, what do you mean with, take care for numbers over 7 ?

I think it may use the convention that leading zeroes mean an octal number.

If found another way to solve this, by checking if the read input is stored or not by using Function_EXISTS - Asterisk Project - Asterisk Project Wiki

same => n,Set(ctbUserPrompt=${SHELL(test -e /etc/asterisk/dialplans/chattabai/prompts/user/${ref}.sln && echo /etc/asterisk/dialplans/chattabai/prompts/user/${ref} | tr -d '\n"' || echo /etc/asterisk/dialplans/chattabai/prompts/user/thisUserDoesNotHaveAPrompt | tr -d '\n"')})
same => n,read(ctbIvrMenuEmployeeByIntroductionUserChoice,${ctbUserPrompt},1)

; no input given go back to ivr menu employee by introduction
same => n,GotoIf($[!${EXISTS(${ctbIvrMenuEmployeeByIntroductionUserChoice})}]?ctbIvrMenuEmployeeByIntroductionUserPrompt,1,7:ctbIvrMenuEmployeeByIntroductionUserPrompt,1,9)
same => n,Playback(${ctbPromptThisIsAnInvalidOption})
same => n,Goto(ctbIvrMenuEmployeeByIntroduction,1,1)

I didn’t mention EXISTS because you were doing a comparison. You seem to have changed the logic.

I don’t believe:

$[${EXISTS(${x})&&${x}=9]

would have worked, because I think the whole expression gets parsed, and the parser would still see an error:

$[${EXISTS()&&=9]

The expression evaluator doesn’t see variables; they are macro expanded out before the expression is parsed.

A couple of suggestions.

  1. I’d rather use Background() when dealing with “IVR” like stuff because it handles timeouts, invalid entries etc really nice.

  2. I use IF $["foo${myVar}"="foo"] to check if it is empty.

  3. You can use ${STAT(e,/path/to/file)} to check if it exists.

  4. You can use ${JSON_DECODE(varname,item[,separator[,options]])} to decote JSONs

1 Like

Would “empty${myVar}”=“empty” be more indicative of your intent?

yiks
please do not use this to check if empty

IF($["foo${myVar}"="foo"]?X)

this much cleaner

IF(${ISNULL(${myVar})}?X)
1 Like

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