Asterisk queue callback
eduguru 4 Comments `callback` int(3) NOT NULL default '0', `callbacknum` varchar(15) NOT NULL default '', `callbacknum`) VALUES (1, `queueid` smallint(6) NOT NULL default '8', `queuename` varchar(20) default NULL, `queuename` varchar(20) NOT NULL default '', '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!"; defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; umask 0; }, '>>/dev/null' or die "Can't write to /dev/null: $!"; defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; umask 0; } Expanded Queue Callb, '>>/dev/null' or die "Can't write to /dev/null: $!"; open STDERR, '311'), '911'), ">>/tmp/cb$row->{uniqueid}.call"; print CALLFILE "Channel: $outchan/$row->{callbacknum}"; print CALLFILE "MaxRetries: 3\n"; print CALLFILE "RetryTime: 60\n"; print CALLFILE "WaitTime: 30\n, "+>>/tmp/cb$row->{uniqueid}.call"; print CALLFILE "Channel: $outchan/$row->{callbacknum}\n"; print CALLFILE "MaxRetries: 3\n"; print CALLFILE "RetryTime: 60\n"; print CALLFILE "WaitTime: 3, "$calldir/$row->{uniqueid}.call"); } } # end main loop ############################################################################## sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open S, "$calldir/$row->{uniqueid}.call"); } # end main loop sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open STDIN, "$dbpass") or die $DBI::errstr; my $qql = "SELECT queuename FROM queuename"; my $aryRef = $dbh->selectall_arrayref($qql); my @queuename = map { $aryRef->[$_][0]} 0..$#{$aryRef}; while (1) { # be, "$dbpass") or die $DBI::errstr; while (1) { # begin main loop sleep($sleepsec); my $q1 = "SELECT uniqueid, "$dbuser", ${queueid}, ${VM_PREFIX}5857, 1, 1) [set-callback] exten => 9, 1) Queue Example An example of one of our queues, 2, 2) Perl Daemon (callbackd) !/usr/bin/perl use strict; use DBI; use POSIX; my $calldir = "/var/spool/asterisk/outgoing"; my $sleepsec = 20; # How often do we check for callbacks? my $outchan = "Zap/G2", and update privileges at a minimum to the database. CREATE TABLE `bit_blacklist` ( `uniqueid` int(11) NOT NULL auto_increment, Answer ;exten => s, Answer exten => 1, Asterisk queue callback, callback numbers are checked against a blacklist which is stored in a MySQL database. The number of calls allowed into all queues are set by a global variable as well as variable that sets the minimum, CALLBACKANNOUNCETHRES to set 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 reco, callbacknum, callbacknum FROM callers " . "ORDER BY uniqueid LIMIT 1"; my $row = $dbh->selectrow_hashref( $q1 ); if (!$row->{callbacknum}) { next; } open CALLFILE, callbacknum=\'${CALLBACKNUM}\'\, callbacknum=${CALLBACKNUM} WHERE\ uniqueid\=${UNIQUEID}) exten => 1, CREATE, CREATE TABLE `bit_callers` ( `uniqueid` varchar(15) NOT NULL default '', delte, GoTo(1) exten => 9, GoTo(Add9) exten => 9, Goto(ext-local, Goto(ext-queues-custom, GoTo(StoreNum) exten => 9, Goto(support-queue, GoToIf($["${CALLBACKNUM:0:3}"="210"]?:Not210) exten => 9, GotoIf($["${CORRECT}"="1"]?:1) exten => 9, GotoIf($["${f}"="1"]?:GoodNum) exten => 9, GotoIf($["${LEN(${CALLBACKNUM})}"="10"]?TenDigits) exten => 9, GotoIf($["${LEN(${CALLBACKNUM})}"="10"|"${LEN(${CALLBACKNUM})}"="7"]?GoodNumDigit) exten => 9, GoToIf($[${COUNT} >= ${CALLBACKANNOUNCETHRES}]?:EnterQueue) exten => 1, GotoIf($[${COUNT} >= ${QUEUESIZE}]?Queuevm) exten => 1, GotoIf($[${QUEUE_PRIO}=10]?EnterQueue) exten => 1, Hangup exten => h, INSERT, KEY `callback` (`callback`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `bit_queuename` ( `id` int(11) NOT NULL auto_increment, KEY `callback` (`callback`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Dialplan Additions [support-queue] exten => s, KEY `callbacknum` (`callbacknum`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Collection of numbers not allowed for customer callback' AUTO_INCREMENT=8 ; INSERT INTO `bit_blacklist` (`uniqueid`, KEY `queuename` (`queuename`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 Dialplan Additions If you are using Trixbox two variables should be set in globals_custom.conf - QUEUESIZE, MYSQL(Clear ${r1}) exten => 1, MYSQL(Connect connid 127.0.0.1 acd acd acd) exten => 1, MYSQL(Connect connid 127.0.0.1 acd acd acd) exten => 9, MYSQL(Connect connid 127.0.0.1 acd acd acd) exten => h, MYSQL(Connect connid 127.0.0.1 acd acdpass acd) exten => 1, MYSQL(Connect connid 127.0.0.1 acd acdpass acd) exten => h, MYSQL(Connect connid 127.0.0.1 acd acdpass acd) exten => s, MYSQL(Disconnect ${connid}) [callback] exten => s, MYSQL(Disconnect ${connid}) exten => 1, MYSQL(Disconnect ${connid}) exten => 9, MYSQL(Disconnect ${connid}) exten => s, MYSQL(Fetch f ${r} CALLBACKNUM) exten => 9, MYSQL(Fetch fetchid ${r1} COUNT) exten => 1, MYSQL(Query r ${connid} DELETE\ FROM\ callers\ where\ uniqueid=${UNIQUEID}\ AND\ callback=0) exten => h, MYSQL(Query r ${connid} INSERT\ INTO\ callers\ set\ uniqueid=\'${UNIQUEID}\'\, MYSQL(Query r ${connid} INSERT\ INTO\ callers\ set\ uniqueid=${UNIQUEID}) exten => s, MYSQL(Query r ${connid} SELECT\ callbacknum\ FROM\ blacklist\ WHERE\ callbacknum=${CALLBACKNUM}) exten => 9, MYSQL(Query r ${connid} UPDATE\ callers\ SET\ callback=1\, MYSQL(Query r1 ${connid} SELECT\ COUNT(*)\ FROM\ callers\) exten => 1, n, n(Add9), n(EnterQueue), n(GoodNum), n(GoodNumDigit), n(Not210), n(Queuevm), n(StoreNum), n(TenDigits), NoOp(${CALLBACKNUM}) exten => 9, NoOp(${CALLERID}) exten => 9, NoOp(${LEN(${CALLBACKNUM})}) exten => 9, placed in /etc/asterisk/queues_custom.conf. You may need to tweek these parameters to fit your requirements. [Spanish] wrapuptime=0 timeout=15 strategy=rrmemory retry=5 queue-youarenext=queue-youarene, Playback(after-the-tone) exten => 9, Playback(custom/queue-callback-msg) exten => 1, Playback(enter-phone-number10) exten => 9, Playback(goodbye) exten => 1, Playback(goodbye) exten => 9, Playback(if-this-is-correct) exten => 9, Playback(if-this-is-not-correct) exten => 9, Playback(pls-try-again) exten => 9, Playback(press-1) exten => 9, Playback(press-2) exten => 9, Playback(wrong-try-again-smarty) exten => 9, Playback(you-dialed-wrong-number) exten => 9, Playback(you-entered) exten => 9, PRIMARY KEY (`uniqueid`), put the following table into a database called 'acd'. CREATE TABLE `bit_callers` ( `uniqueid` varchar(15) NOT NULL default '', Queue(${QUEUENAME}|tT) exten => 1, Queue(support|t) exten => 1, queueid FROM callers WHERE queuename='".$queue."' ". "ORDER BY uniqueid LIMIT 1"; my $row = $dbh->selectrow_hashref( $q1 ); if (!$row->{callbacknum}) { next; } open CALLFILE, queueid=\'${QUEUEID}\'\, queueid=\'${queueid}\'\ WHERE\ uniqueid=${UNIQUEID}) exten => 9, queuename=\'${QUEUENAME}\') exten => 1, Read(CALLBACKNUM|beep|10) ; This is where you request the CallBack Number from your customer. Put your own prompts or whatever here. exten => 1, Read(CALLBACKNUM|beep|10||2|5) ; This is where you request the CallBack Number from your customer. Put your own prompts or whatever here. exten => 9, Read(CORRECT|beep|1||2|5) exten => 9, s, SayDigits(${CALLBACKNUM}) exten => 9, Set(CALLBACKNUM=${CALLBACKNUM:3:7}) exten => 9, Set(CALLBACKNUM=9${CALLBACKNUM}) exten => 9, Set(CALLBACKNUM=91${CALLBACKNUM}) exten => 9, Set(QUEUE_PRIO=10) exten => s, Set(QUEUEID=1) exten => 1, Set(QUEUENAME=Spanish) exten => 1, SQL Table Structure If using the dialplan below, Texas). You will need to change the code at label TenDigits for your area code(s). [ext-queues-custom] exten => 1, UNIQUE KEY `id` (`id`), Wait(1) ;exten => s, Wait(1) exten => 1, Wait(1) exten => 9, we are in San Antono, we give them text names so both the name of the queue and the queueid (the number a called presses when selecting a queue) is stored. The callback Perl script uses this information to make sure that w, yet. Functionality is there but there may be a bug or two laying around. I welcome suggestions on how to further enhance it. SQL Table Structure Three tables are used. Blacklist to hold the phone numb
SQL Table Structure If using the dialplan below, put the following table into a database called ‘acd‘. CREATE TABLE `bit_callers`
Read more