Callback dialplan example

From BGNV Wiki

Jump to: navigation, search

Contents

[edit] Dialplan Additions

Two global variables should be set - a customized QUEUESIZE variable for each queue (in this case we used TECHQSIZE) and CALLBACKANNOUNCETHRES. This sets the total number of calls you will allow in all queues and how many calls must be in the queues before a caller hears about this option. A custom announcement must be recorded and placed in /var/lib/asterisk/sounds/custom/queue-callback-msg.

Additionally the code allows only 10 digit callback numbers to be entered.

[edit] The queues context

This is the main context where we put callers into the queue and add them to a database in order to schedule them. Unsure how deletions would be handled when the callee gets transferred to an extension. The extension number must match the QUEUEID which matches the id in the queuename table in the database.

[queues]
exten => 1,1,Answer
exten => 1,n,Wait(1)
exten => 1,n,Set(QUEUEID=1)
exten => 1,n,Set(QUEUENAME=tech)
exten => 1,n,MYSQL(Connect connid 127.0.0.1 acd acd acd)
exten => 1,n,GotoIf($[${QUEUE_PRIO}=10]?EnterQueue)
exten => 1,n,MYSQL(Query r1 ${connid} SELECT\ COUNT(*)\ FROM\ callers\)
exten => 1,n,MYSQL(Fetch fetchid ${r1} COUNT)
exten => 1,n,MYSQL(Clear ${r1})
exten => 1,n,GotoIf($[${COUNT} >= ${TECHQSIZE}]?return)
exten => 1,n,GoToIf($[${COUNT} >= ${CALLBACKANNOUNCETHRES}]?:EnterQueue)
exten => 1,n,Playback(custom/queue-callback-msg)
exten => 1,n(EnterQueue),MYSQL(Query r ${connid} INSERT\ INTO\ callers\ set\ uniqueid=\'${UNIQUEID}\'\,queueid=\'${QUEUEID}\'\,queuename=\'${QUEUENAME}\')
exten => 1,n,MYSQL(Disconnect ${connid})
exten => 1,n,Queue(${QUEUENAME}|rtT|||25)
exten => 1,n(return),Return

exten => h,1,MYSQL(Connect connid 127.0.0.1 acd acd acd)
exten => h,n,MYSQL(Query r ${connid} DELETE\ FROM\ callers\ where\ uniqueid=${UNIQUEID}\ AND\ callback=0)
exten => h,n,MYSQL(Disconnect ${connid})

[edit] The setup context

in this example the queue has context=set-callback in queues.conf so that a single digit will transfer the caller to that extension in this context. For this example if the caller were to press 9 they would enter this dialplan logic that requests their callback number, verifies it is 10 digits, and has the caller confirm the number, before modifying the record in the database.

[set-callback]
exten => 9,1,Playback(after-the-tone)
exten => 9,n,Playback(enter-phone-number10)
exten => 9,n,Read(CALLBACKNUM|beep|10||2|5) 
exten => 9,n,GotoIf($["${LEN(${CALLBACKNUM})}"="10"]?GoodNumDigit)
exten => 9,n,Playback(wrong-try-again-smarty)
exten => 9,n,GoTo(1)
exten => 9,n(GoodNumDigit),MYSQL(Connect connid 127.0.0.1 acd acd acd)
exten => 9,n,MYSQL(Query r ${connid} SELECT\ callbacknum\ FROM\ blacklist\ WHERE\ callbacknum=${CALLBACKNUM})
exten => 9,n,MYSQL(Fetch f ${r} CALLBACKNUM)
exten => 9,n,GotoIf($["${f}"="1"]?:GoodNum)
exten => 9,n,Playback(you-dialed-wrong-number)
exten => 9,n,Playback(pls-try-again)
exten => 9,n,GoTo(1)
exten => 9,n(GoodNum),Playback(you-entered)
exten => 9,n,NoOp(${CALLBACKNUM})
exten => 9,n,NoOp(${CALLERID})
exten => 9,n,SayDigits(${CALLBACKNUM})
exten => 9,n,Wait(1)
exten => 9,n,Playback(after-the-tone)
exten => 9,n,Playback(if-this-is-correct)
exten => 9,n,Playback(press-1)
exten => 9,n,Playback(if-this-is-not-correct)
exten => 9,n,Playback(press-2)
exten => 9,n,Read(CORRECT|beep|1||2|5)
exten => 9,n,GotoIf($["${CORRECT}"="1"]?:1)
exten => 9,n,NoOp(${LEN(${CALLBACKNUM})})
exten => 9,n,NoOp(${CALLBACKNUM})
exten => 9,n,Set(CALLBACKNUM=+1${CALLBACKNUM})
exten => 9,n(StoreNum),MYSQL(Query r ${connid} UPDATE\ callers\ SET\ callback=1\,callbacknum=\'${CALLBACKNUM}\'\,queueid=\'${queueid}\'\ WHERE\ uniqueid=${UNIQUEID})
exten => 9,n,MYSQL(Disconnect ${connid})
exten => 9,n,NoOp(${CALLBACKNUM})
exten => 9,n,Playback(goodbye)
exten => 9,n,Hangup

exten => h,1,MYSQL(Connect connid 127.0.0.1 acd acd acd)
exten => h,n,MYSQL(Query r ${connid} DELETE\ FROM\ callers\ where\ uniqueid=${UNIQUEID}\ AND\ callback=0)
exten => h,n,MYSQL(Disconnect ${connid})

[edit] The callback context

This is a simple context for the perl daemon that watches the database and then generates the callfile to place the calling channel into. The priority is raised to 10 and then directs the call to the correct queue.

[callback]
exten => s,1,Set(QUEUE_PRIO=10)
exten => s,n,Goto(queues,${queueid},1)
Personal tools
user administration