String search/comparison with gotoif

please suggest right way for search text comparison , If I search one , it found all ones.

exten => 727272,1,Answer()
exten => 727272,n,Set(tempvalueeee=“one”)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “thirtyone”]?ClasssS31)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “twentyone”]?ClasssS21)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “elevone”]?ClasssS11)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “one”]?ClasssS1)
exten => 727272,n(ClasssS31),System(echo -e “${CALLER_ID},–,ClasssS31,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS21),System(echo -e “${CALLER_ID},–,ClasssS21,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS11),System(echo -e “${CALLER_ID},–,ClasssS11,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS1),System(echo -e “${CALLER_ID},–,ClasssS1,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()

Do a Hangup() after every action, otherwise the first action simply falls
through to the second, the third, and the fourth.

Antony.

Thanks @Pooh for reply,

ok, I will add, this is a just a sample, my need is search exact string.

There is nothing wrong with the “searches” (comparisons) you are doing; the
problem is with the logic of the dialplan after you have matched a certain
string.

Consider the following pseudo-code:

set A=“one”
if A=“one” goto label1
if A=“two” goto label2
label1: set A=1
label2: set A=2
print A

There are two major problems with this:

  1. If A is not “one” and is not “two”, the code will fall through to label1
    anyway

  2. If A is “one” it will go to label1, fall through to label2, and in the end,
    A will be set to 2 every time, no matter what its starting value was.

This is not a question about Asterisk; it is just programming logic.

Antony.

thanks,
Till now using same format for all our numeric value comparisons, facing issue with text searches.

you can also do it like a switch

exten => 727272,1,Answer()
same => n,Set(tempvalueeee=one)
same => n,ExecIf(${ISNULL(${tempvalueeee})}?Congestion(3))
same => n,Goto(temp,${TRIM(${TOLOWER(${tempvalueeee})})},1)

[temp]
exten => _[a-zA-Z0-9*#]!,1,Congestion(3) ;No Match
same => n,Hangup() ;match was made

exten => thirtyone,1,System(echo -e “${CALLER_ID},–,ClasssS31,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => twentyone,1,System(echo -e “${CALLER_ID},–,ClasssS21,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => elevone,1,System(echo -e “${CALLER_ID},–,ClasssS11,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => one,1,System(echo -e “${CALLER_ID},–,ClasssS1,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)

exten => h,1,NoOP(Hangup); prevent hangup to be match by _[a-zA-Z]!

thanks for your valuable suggestion.

In our case ${tempvalueeee} is a dynamic value and coming from speech synthesis.
would be better if you suggest with gotoif or ExecIf format, because search/compare will go to more than 40 lines.
currently text search is not well working

Please explain exactly what you mean by “currently text search is not well
working”.

If you mean that the dialplan logic you showed earlier does not do what you
want it to, that is because the logic itself is flawed (as I already
explained), and is nothing to do with the text string comparisons.

If you mean that strings are matching when they should not, or are not
matching when they should, please show us verbose log output (as text, not a
screenshot) of what is not working correctly.

Antony.

Thanks @TheMark @Pooh for your reply.

please review/test following code, as it seems working, here I am using without " " , I will wait for better solution to start ahead.

exten => 727272,1,Answer()
exten => 727272,n,Set(tempvalueeee=one)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Thirtyone]?ClasssS31)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Twentyone]?ClasssS21)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Elevone]?ClasssS11)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ one]?ClasssS1)
exten => 727272,n(ClasssS31),System(echo -e “${CALLER_ID},–,ClasssS31,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS21),System(echo -e “${CALLER_ID},–,ClasssS21,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS11),System(echo -e “${CALLER_ID},–,ClasssS11,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()
exten => 727272,n(ClasssS1),System(echo -e “${CALLER_ID},–,ClasssS1,${tempvalueeee}” >> /root/tempfiles/test2/logrecord5.log)
exten => 727272,n,Hangup()

@TheMark , what is your view/suggestion for above code, should I proceed with this.

I really do not like the use of =~ for pattern matching here.

For example, what would you do if you had three strings to be tested for:

  • one
  • Twenty
  • Twentyone

If you do a pattern match on “one” it will match two of those.

If you do a pattern match on “Twenty” it will also match two of those.

Ensuring that you put the comparisons in the correct order to avoid a partial
match will be unnecessarily complicated.

Please explain what, exactly, is going wrong when you use:

$[“${tempvalueeee}”=“Twentyone”] etc.

Antony.

If you spare 5 minutes and check the code, you will realize which one is working well.

This is working
exten => 727272,n,Set(tempvalueeee=one)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Thirtyone]?ClasssS31)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Twentyone]?ClasssS21)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ Elevone]?ClasssS11)
exten => 727272,n,GotoIf($[“${tempvalueeee}”=~ one]?ClasssS1)

This is not working
exten => 727272,n,Set(tempvalueeee=“one”)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “thirtyone”]?ClasssS31)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “twentyone”]?ClasssS21)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “elevone”]?ClasssS11)
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “one”]?ClasssS1)

can you try to eliminate case and show us some samples of what your speech synthesis is returning
as I belive there may be space or other text in your match that is not accounted for

same => n,Set(tempvalueeee=${TRIM(${TOLOWER(“one”)})})
same => n,NoOp(tempvalueeee="${tempvalueeee}")

https://wiki.asterisk.org/wiki/display/AST/Operators

"one " =~ "one" ;Match
"one " = "one" ;NoMatch
"${TRIM(${TOLOWER(“One ”)})}" = "one" ; match

Coming back to your original requirement (and assuming that your example is a
reasonably accurate indication of what you want to do), have you considered
something like:

exten => 727272,n,Set(tempvalueeee=“one”)

same => Set(result=None)
same => ExecIf($[“${tempvalueeee}”=“thirtyone"]?Set(result=ClasssS31))
same => ExecIf($[“${tempvalueeee}”=“twentyone"]?Set(result=ClasssS21))
same => ExecIf($[“${tempvalueeee}”=“elevone"]?Set(result=ClasssS11))
same => ExecIf($[“${tempvalueeee}”=“one"]?Set(result=ClasssS1))

same => ExecIf($[“${result}”=“none”]?Hangup())

same => System(echo -e “${CALLER_ID},–,${result},${tempvalueeee}” >>
/root/tempfiles/test2/logrecord5.log)

same => Hangup()

Antony.

you may want to do this externaly

Hello @Pooh
Have you tried code you shared, I am getting errors.

thanks @TheMark

My source variable is already in lower case.
would be better you test/review last shared code by me, if it is reliable , i will start implementation, as it is well working for me.

@helpinghandindia, Pooh missed the’priority.’ Easy to do when typing code off the top of your head.

That you didn’t recognize this and resolve it on your own suggests that you should invest some time in reading and applying Asterisk basics.

When you demonstrate a lack of effort on your part, many feel less inclined to put forth effort on their part.

Everybody here is a just a volunteer.

it is just that looking at your code there is a lot of mix and mash it together
uppercase, quats, operators
that we question what is being matched

=~ Thirtyone
= "thirtyone"

if this is not working somthing is very strange on you systen and we need to see the console output

This is not working
exten => 727272,n,Set(tempvalueeee=“one”)
exten => 727272,n,NoOp([“${tempvalueeee}” = “one”]?ClasssS1) ;please add this line and show console output
exten => 727272,n,GotoIf($[“${tempvalueeee}” = “one”]?ClasssS1)

also please use the “</>” when you paste code
and start usen the code simplification “same”

exten => 727272,n,GotoIf
same => n,GotoIf

https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities
also witch version of asterisk are you using ???

@sedwards - thanks for the correction - I did indeed miss the n off my lines of
code. As you say, easy to do, and especially when I no longer write dialplans
like this, but use AEL instead :slight_smile:

For @helpinghandindia’s benefit, here is what I should have written:

exten => 727272,n,Set(tempvalueeee=“one”)

same => n,Set(result=None)
same => n,ExecIf($[“${tempvalueeee}”=“thirtyone"]?Set(result=ClasssS31))
same => n,ExecIf($[“${tempvalueeee}”=“twentyone"]?Set(result=ClasssS21))
same => n,ExecIf($[“${tempvalueeee}”=“elevone"]?Set(result=ClasssS11))
same => n,ExecIf($[“${tempvalueeee}”=“one"]?Set(result=ClasssS1))

same => n,ExecIf($[“${result}”=“none”]?Hangup())

same => n,System(echo -e “${CALLER_ID},–,${result},${tempvalueeee}” >>
/root/tempfiles/test2/logrecord5.log)

same => n,Hangup()

Oh, and by the way, “I am getting errors” is not especially helpful. Always
tell people what the errors are.

Antony.