Why does this code always result in a 'yesmatch'?


(D E) #1

I’ve received some truly heart warming help from a member here to try to recognise if a caller has called before already {today} and I’m 90% there but for some reason the script always returns true, even if the caller is calling for the first time. Just wondered if anyone had time to assist?

As I say, I called today (the inbound route points at this script via an announcement) and I got a ‘yesmatch’ even though I hadn’t already called. There’s a call trace here if it’s useful. Thanks!!

[app-announcement-10]
include => app-announcement-5-custom
exten => s,1,GotoIf($["${CHANNEL(state)}" = "Up"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Noop(Playing announcement testannoucement)

exten => s,n,ExecIf($["${FROMEXTEN }" != "07113380031"]?goto(yesmatch))
exten => s,n,ExecIf($["${FROMEXTEN}" = ""]?goto(nomatch))  
exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(match)) 
exten => s,n,Set(dblogin=root)  
exten => s,n,Set(dbpass=)  
exten => s,n,Set(DateCheck=${STRFTIME(${EPOCH},,%Y-%m-%d)})    
exten => s,n,MYSQL(Connect connid localhost ${dblogin} ${dbpass} asteriskcdrdb) 
exten => s,n,MYSQL(Query resultid ${connid} select * from cdr where clid like "%${FROMEXTEN}%" and calldate like "%${DateCheck}%" order by calldate desc limit 1)
exten => s,n,MYSQL(Fetch fetchid ${resultid} calldate clid src dst dcontext )  
exten => s,n,NoOp(&&&&&&&&&&&&&&&&&&&&&&& ${calldate} ${clid} ${src} ${dst} ${dcontext} &&&&&&&&&&&&)
exten => s,n,MYSQL(Disconnect ${connid})   
exten => s,n,MYSQL(Clear ${resultid}) 
exten => s,n,GotoIf($["${calldate}" = "" ]?nomatch) 

exten => s,n,GotoIf($["${dst}" = "" ]?nomatch) 
exten => s,n,GotoIf($["${dst}" != "" ]?yesmatch) 

exten => s,n,ExecIf($["${dst}" = "macro-pincollection"]?goto(${dst},s,1)

exten => s,n,ExecIf($["${dst}" = "6475580588"]?Dial(Local/${dst}@from-internal/n,)

exten => s,n,ExecIf($["${dst}" = "app-annoucement-1"]?goto(${dst},s,1)
exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(match)) 
exten => s,n,Set(dblogin=root)  
exten => s,n,Set(dbpass=)  
exten => s,n,Set(DateCheck=${STRFTIME(${EPOCH},,%Y-%m-%d)})    
exten => s,n,MYSQL(Connect connid localhost ${dblogin} ${dbpass} asteriskcdrdb) 
exten => s,n,MYSQL(Query resultid ${connid} select * from cdr where clid like "%${FROMEXTEN}%" and calldate like "%${DateCheck}%" orde$
exten => s,n,MYSQL(Fetch fetchid ${resultid} calldate clid src dst dcontext )  
exten => s,n,NoOp(&&&&&&&&&&&&&&&&&&&&&&& ${calldate} ${clid} ${src} ${dst} ${dcontext} &&&&&&&&&&&&)
exten => s,n,MYSQL(Disconnect ${connid})   
exten => s,n,MYSQL(Clear ${resultid}) 
exten => s,n,GotoIf($["${calldate}" = "" ]?nomatch) 

exten => s,n,GotoIf($["${dst}" = "" ]?nomatch) 
exten => s,n,GotoIf($["${dst}" != "" ]?yesmatch) 

exten => s,n,ExecIf($["${dst}" = "macro-pincollection"]?goto(${dst},s,1)

exten => s,n,ExecIf($["${dst}" = "6475580588"]?Dial(Local/${dst}@from-internal/n,)

exten => s,n,ExecIf($["${dst}" = "app-annoucement-1"]?goto(${dst},s,1)

exten => s,n(nomatch),NoOp(No previous caller match)
exten => s,n,Goto(ivr-1,s,1)

exten => s,n(yesmatch),NoOp(Previous caller match)
exten => s,n,Background(custom/heater)

#2

I believe it’s because of the extra space here inside your curly braces.


(D E) #3

hmmm. HUGE thanks, but that dosen’t seem to have sorted it. I setup a new inbound route and called again from a new number and straight away I get the heater message instead of the IVR


#4

I apologize, it was just a guess from looking at it quickly.

Are you certain about FROMEXTEN? You can add that variable to your NoOp to print out what it actually contains. Maybe what you are really needing is CALLERID(num).


(Dickson) #5

…post the live log of the call.


(D E) #6

@dickson is that an even liver log than the one in my original post? Would that be the one I have to login to the asterisk and turn on SIP debugging or similar?


(Dickson) #7

asterisk -cvvvvvvr

make a test call

CTRL+C
copy and paste somewhere, can take a look at what is wrong.


#8

He already posted it.


(Dickson) #9

Sorry didn’t see the “here” link way at the top.

You fixed that code as billsimon said,

ExecIf($["${FROMEXTEN }"

Did you reload the config? asterisk -rx ‘core reload’
from command prompt?


(Dickson) #10

This line is wrong too

exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(match))

Should be “nomatch”

Did you paste the code twice? Its doubled up in your original post, that will cause weirdness if in production.


(D E) #11

Sorry yes I must have doubled up when trying to copy paste from nano. I opened the file in the GUI ‘config edit’ and this is how it looks. I have done reloads, yes.

I’ll amend the line as you suggest and retry. Thanks!

[app-announcement-10]
include => app-announcement-5-custom
exten => s,1,GotoIf($["${CHANNEL(state)}" = "Up"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Noop(Playing announcement testannoucement)

exten => s,n,ExecIf($["${FROMEXTEN}" != "07333380031"]?goto(yesmatch))  
exten => s,n,ExecIf($["${FROMEXTEN}" = ""]?goto(nomatch))  ;don't count people with no callerid
exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(match)) ;if their CLID isn't 11 digits, ignore.
exten => s,n,Set(dblogin=root)  ;database user
exten => s,n,Set(dbpass=)  ;database password
exten => s,n,Set(DateCheck=${STRFTIME(${EPOCH},,%Y-%m-%d)})    ;get current date YYYY-MM-DD
exten => s,n,MYSQL(Connect connid localhost ${dblogin} ${dbpass} asteriskcdrdb) ;connect to asterisk CDR
exten => s,n,MYSQL(Query resultid ${connid} select * from cdr where clid like "%${FROMEXTEN}%" and calldate like "%${DateCheck}%" order by calldate desc limit 1)
exten => s,n,MYSQL(Fetch fetchid ${resultid} calldate clid src dst dcontext )  ;get the sql results (if any)
exten => s,n,NoOp(&&&&&&&&&&&&&&&&&&&&&&& ${calldate} ${clid} ${src} ${dst} ${dcontext} &&&&&&&&&&&&);echo the values in the log
exten => s,n,MYSQL(Disconnect ${connid})   ;close database connection
exten => s,n,MYSQL(Clear ${resultid}) ;clear the sql connection.
exten => s,n,GotoIf($["${calldate}" = "" ]?nomatch) ;no previous call detected, go to IVR

exten => s,n,GotoIf($["${dst}" = "" ]?nomatch) ;check to see if there is data in the last know DST column.  If empty, goto ivr
exten => s,n,GotoIf($["${dst}" != "" ]?yesmatch) ;check to see if there is data in the last know DST column.  If there is, goto yesmatch

exten => s,n,ExecIf($["${dst}" = "macro-pincollection"]?goto(${dst},s,1)

exten => s,n,ExecIf($["${dst}" = "6475580588"]?Dial(Local/${dst}@from-internal/n,)

exten => s,n,ExecIf($["${dst}" = "app-annoucement-1"]?goto(${dst},s,1)

exten => s,n(nomatch),NoOp(No previous caller match)
exten => s,n,Goto(ivr-1,s,1)

exten => s,n(yesmatch),NoOp(Previous caller match)
exten => s,n,Background(custom/heater)

(Dickson) #12

Ok, i have my coffee into me and I see what probably the problem is

exten => s,n,ExecIf($["${FROMEXTEN}" != "07333380031"]?goto(yesmatch))  

You don’t need this line. Take it out. I originally put that in as way for you to test the code without affecting production, but its been since altered and wasn’t needed anyway.
Its doing exactly what you are telling it. If the number doesn’t equal that 073 number, goto “yesmatch”
But yesmatch is at the bottom and bypasses all the code.

Also, fix
exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(match))

and make that
exten => s,n,ExecIf($[${LEN(${FROMEXTEN})} != 11]?goto(nomatch))

IF you want that YES match to play some custom message, then just put it above the dblogin portion, that will also fix things and let your callers hear the custom message.

exten => s,n(yesmatch),NoOp(Previous caller match)
exten => s,n,Background(custom/heater)
exten => s,n,Set(dblogin=root)  ;database user
 exten => s,n,Set(dbpass=)  ;database password

(D E) #13

Brilliant! This works. Thank you!! :slight_smile: :slight_smile:
Where you refer to that YES match, is that for the != 11 digits? If so that’s fine, we don’t need a case for that. Thank you!


(system) closed #14

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