Check Caller ID with SQL

Hi i want the help
I want update my asterisk with the controll with CALLERID.
In the exstension.conf i have

exten => s,1,Answer
exten => s,n,NoOp("Caller ID IS: {CALLERID(number)}") exten => s,n,MYSQL(Connect connid 127.0.0.0 USER PASSWORD TABLE) exten => s,n,MYSQL(Query resultid {connid} SELECT DISTINCT Enabled FROM Numbers WHERE Num=’{CALLERID(Num)}') exten => s,n,If(resultid = 0) exten => s,n,HangUp() exten => s,n,Else(resultid = 1) exten => s,n,Play(hello word) exten => s,n,MYSQL(Clear {resultid})
exten => s,n,MYSQL(Disconnect ${connid});

If the result my select is 0 go to hanup if the result is 1 go to my office
I wnat know if it is work o there are the error.
Thanks

There is no ‘If’ or ‘Else’ dialplan application.

OK thanks
How do i do it

I would recommend using func_odbc

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/getting_funky.html

OK i see.
My case is similar.
I have the table SQL
±--------±-------------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±--------±-------------±-----±----±--------±---------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| Number | varchar(100) | NO | UNI | NULL | |
| Enabled | tinyint(4) | NO | | NULL | |
±--------±-------------±-----±----±--------±---------------+

When incoming the call i see the caller id and if the number is Enabled o 0 (BLOCK CALL) have hangup o 1 (NO BLOCK CALL) go to my reception.

Yup should be as easy as defining your routine and then calling it from dialplan.
GotoIf([${CHECK_SOURCE(${CALLERID(NUM))} = 1]?NOBLOCK:BLOCK)

This is all extension?
I need modify only the variables for DB

exten => s,1,MYSQL(Connect connid {realdb_host} {realdb_user} {realdb_pass} {realdb_db})
exten => s,2,MYSQL(Query resultid {connid} SELECT\ callerid\ from\ blacklist\ where\ callerid={ARG1} and blockenabled = 1)
exten => s,3,MYSQL(Fetch fetchid {resultid} blacklistid) exten => s,4,MYSQL(Clear {resultid})
exten => s,5,MYSQL(Disconnect {connid}) exten => s,6,GotoIf([{CHECK_SOURCE(${CALLERID(NUM))} = 1]?NOBLOCK:BLOCK)
exten => s,7,Playback(Hello-Word)

I change the script, but dont work

; 0 DISABLED
; 1 ENABLED

exten => s,1,Answer
exten => s,2,NoOp({CALLERID(num)}) exten => s,n,MYSQL(Connect connid localhost root password database) exten => s,n,MYSQL(Query resultid {connid} SELECT enabled from numbers_table where number={CALLERID(num)}) exten => s,n,MYSQL(Fetch fetchid {resultid} enabledok)
exten => s,n,MYSQL(Disconnect ${connid})
exten => s,n,NoOp

exten => s,n,ExecIf(["{enabledok}"=""]?playback(hangup-try-again))
exten => s,n,ExecIf(["{enabledok}"=""]?HANGUP())

exten => s,n,PlayBack(Hello-word)
exten => s,n,Hangup()

Where i wrong?

in your text, you need to edit it

exten => s,n,NoOp
–>
exten => s,n,NoOp(enabledok = ${enabledok})

and if you add CLI message, it’ll be helpful!!

Yes, scuse me.
I need the result of the query and the name of result is enabledok

number={CALLERID(num)}) exten => s,n,MYSQL(Fetch fetchid {resultid} enabledok)
exten => s,n,MYSQL(Disconnect {connid}) exten => s,n,NoOp ({enabledok} )

Now i thnks is ok?

Please markup log file and configuration file extracts as preformatted, using the forum </> button.

Scuse David for the button

I go crazy
I need the script but i have a few minutes for the test.

exten => s,1,Answer
exten => s,2,NoOp(${CALLERID(num)})
exten => s,n,MYSQL(Connect connid localhost root password database)
exten => s,n,MYSQL(Query resultid ${connid} SELECT enabled from numbers_table where Number=${CALLERID(num)})
exten => s,n,MYSQL(Fetch fetchid ${resultid} enabledok)
exten => s,n,MYSQL(Disconnect ${connid})
exten => s,n,NoOp(enabledok = ${enabledok})

exten => s,n,ExecIf($["${enabledok}"=""]?playback(hangup-try-again))
exten => s,n,ExecIf($["${enabledok}"=""]?HANGUP())

exten => s,n,PlayBack(auth-thankyou)
exten => s,n,Hangup()

Please help me

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