IVR plan exten => Set take input

Hello,

I`m trying to make the IVR to take less than 8 digits and more than 4 digits.
The wait time is 8 seconds to input, 4 time repeat than hangup.
Now the IVR takes 6 and 6 only, if not goto - try again. 13 is the line to read from if its wrong.

Please help!!

The dial plan is :
exten => 1,n,Read(promopin,ivr/promopin,8,8,4)
exten => 1,n,Set($[LEN(${promopin}) != 6]?69:13)

exten => _X.,69,Playback(ivr/tryagain)
exten => _X.,70,Goto(ivrsystem,${EXTEN},13)

You are testing for exactly six characters!

Yes, but i want to make the Set take 4 to 8 digits, otherwise send to try again

Well donā€™t test for not exactly 6!

That is my point, i don`t know what to delete or how to change Set to take it. If i delete 6, it gives me an error on the asterisk with pbx_variables.c:1142 pbx_builtin_setvar: Set requires an ā€˜=ā€™ to be a valid assignment. And it waits around 20 sec to take the next exten.

Sorry, priority 2 is even less correct than I thought. I assumed a GotoIf. Iā€™d hope that what you have will produce an error. You appear to be asking for someone to write trivial Asterisk code for you. Iā€™m only prepared to point you to basic resources.

https://wiki.asterisk.org/wiki/display/AST/Expressions
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_GotoIf

The read is also missing a parameter:

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

Sounds fair.Thank you

I donā€™t think _X. will match a single digit, and there seems no reason to change the extension pattern, anyway.

LEN doesnā€™t appear to be built-in, so might need to given as a full diaplan function (it is possible that dialplan functions can be used without ${} in expressions, though).

You do NOT as far as I remember, have a way to test if a value is between somethingā€¦ I Would do something like this.

same => n,Set(ValueLength=${LEN(${promopin})}
same => n,GotoIf($[ "${ValueLength}" = "4"]?Success:)
same => n,GotoIf($[ "${ValueLength}" = "5"]?Success:)
same => n,GotoIf($[ "${ValueLength}" = "6"]?Success:)
same => n,Goto(Failure)

same => n(Success),Log(VERBOSE,Pin length accepted)
same => n,Hangup(16)

same => n(Failure),Log(VERBOSE,Pin length not accepted)
same => n,Hangup(16)

The idea is that you ONLY check success condition, and stop checking once it matches, if no match is found, the condition is false, and you do error handling. (Eg. loops back to the input step)

The reason for using ā€œā€ around the variable and values in the expression, is to handle the case where the variable is empty. If that happens, Asterisk will report a syntax error in the dialplan, the quotes makes sure there is always a valid value before the equal sign, and the quotes around the number is there because quotes are added to the actual value of the variable BEFORE comparing them.

Eg if the variable contains 4 the comparison will be "4" = "4", which will evaluate as true, but if quotes are NOT added to the right number you get "4" = 4 which will evaluate as false.

1 Like

The OP didnā€™t understand the comparison in the original code, so they are probably just going to copy and paste examples here.

However, although there is no range test operator, there is a boolean AND one (&). But if you are going to do anything but exact values on numbers, it is important not to include quotes, as I am pretty sure they will force character by character matching (not actually a problem if the maximum value is 9). The LEN function should never return an empty string.

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