#!/usr/bin/perl # # Written by: James Golovich # Munched by: Richard Lyman # # requires: # http://asterisk.gnuinter.net/files/asterisk-perl-0.08.tar.gz # and the following perl modules installed # Bundle::CPAN, Bundle::DBI, DBD::mysql # # search for 'ISSUE' to see where there will be issues with this code # and your existing environment. # # all the various places that use prompts to read back vars and stream # sound files *MUST* be changed to your prompt file names. # # if you do not use closers, the '-true' must be replaced with '-false' # # that should be it. when i designed and wrote this (per your spec sheet) # it was fully functional. # # to use this script it must be copied to your agi-bin directory and # permissions set. # # cp /path/to/RoadSide.agi /var/lib/asterisk/agi-bin/RoadSide.agi # chmod 755 /var/lib/asterisk/agi-bin/RoadSide.agi # # also requires a queue called 'CS_agents' as you specified wanting to # be able to pass to that queue, if they pressed option 2 on question 1. # # there is also base code included that was to and automated way store # the information gathered from the user and update the campaign table. # which will also require a 'INBOUND' campaign (reload a single record), # this is a fall-thru in case the normal lookup fails to find the # callerid number or dnid in ANY of the other campaign tables (this is # an example of why your dialer database needs to be cleaned up) # # extensions.conf example # # [some_inbound_context] # exten => _X.,1,Set(TIMEOUT(digit)=1|TIMEOUT(response)=1) # exten => _X.,2,Wait(2) ; this is so callerid is passed # ; we should have callerid by now, if not, we never will # exten => _X.,3,Answer() ; answer so asterisk knows to wake up # exten => _X.,4,AGI(RoadSide.agi|${CALLERID(num)},${IF(${ISNULL(${CALLERID(dnid)})}?${EXTEN}:${CALLERID(dnid)})}) use Asterisk::AGI; use DBI; my $dbh = DBI->connect("dbi:mysql:dialer:localhost:3306",'dialer','1234',{AutoCommit => 1, PrintError => 0, RaiseError => 0}); $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $tests = 0; my $pass = 0; my $fail = 0; my $verbal_debug = 1; #setup callback $AGI->setcallback(\&mycallback); print STDERR "AGI Environment Dump:\n"; foreach $i (sort keys %input) { print STDERR " -- $i = $input{$i}\n"; } score($AGI->answer()); my $CurDate = $AGI->get_variable("DATETIME"); score($AGI->verbose("RoadSide (v3.2) $CurDate munch'D by Richard", 3)); # replace with the initial welcome message for your users # this is xyz corp calling about the request for tow service score($AGI->stream_file('you-have-reached-a-test-number')); # lets start the process &question_1(); exit 0; sub score { my ($returncode) = @_; $tests++; if ($returncode >=0) { print STDERR "PASS ($returncode)\n"; $pass++; } else { print STDERR "FAIL ($returncode)\n"; $fail++; } } sub mycallback { my ($returncode) = @_; print STDERR "MYCALLBACK: User Hungup ($returncode)\n"; exit($returncode); } ################## sub what_dbs { local($thecallerid) = @_; my $ret = 0; my $sth = $dbh->prepare("SHOW TABLES"); $sth->execute; my $total_hits=0; # # ISSUE # because you have other non- tables (other than the 4 below) in your dialer database, # there will be issues with the lookups. this script was designed to be dynamic (meaning low # maintenance), which it cannot be when you place other tables in your dialer database. # while(@table = $sth->fetchrow_array) { if ($table[0] ne 'cdr' && $table[0] ne 'CDR' && $table[0] ne 'dnc' && $table[0] ne 'DNC') { $total_hits += search_table($table[0],$thecallerid); } } if ($total_hits lt 1) { $sth = $dbh->prepare("INSERT INTO INBOUND (id,phone) values (NULL,'" . $thecallerid . "')"); $sth->execute; $sth = $dbh->prepare("SELECT LAST_INSERT_ID()"); $sth->execute; while(@record = $sth->fetchrow_array) { print "SET VARIABLE CAMPAIGN INBOUND\n"; print "SET VARIABLE LEADID " . $record[0] . "\n"; print "SET CALLERID ~INBOUND-" . $record[0] . "-true~<" . $thecallerid . ">\n"; print "SET VARIABLE TOTALHITS " . $total_hits . "\n"; } } $sth->finish; return $ret; } sub search_table { local($thetable,$clid) = @_; my $mystring = "SELECT * FROM " . $thetable . " WHERE phone LIKE '%" . $clid . "%'"; my $sth = $dbh->prepare("$mystring"); $sth->execute; my $hit_count=0; while(@record = $sth->fetchrow_array) { $hit_count++; print "SET VARIABLE CAMPAIGN " . $thetable . "\n"; print "SET VARIABLE LEADID " . $record[0] . "\n"; print "SET CALLERID ~" . $thetable . "-" . $record[0] . "-true~<" . $clid . ">\n"; print "SET VARIABLE HITCOUNT " . $hit_count . "\n"; } $sth->finish; return $hit_count; } ##################### sub question_1 { # replace with the sound file for # press 1, if the provider arrived already # press 2, if they have not, this will connect you to an agent score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1) { if ($verbal_debug) { score($AGI->say_number('1')); } $AGI->verbose("Provider Arrived: YES", 3); &question_2(); } elsif ($getdigit == 2) { if ($verbal_debug) { score($AGI->say_number('2')); } $AGI->verbose("Provider Arrived: NO (should send to Agent Queue Now!)", 3); score($AGI->stream_file('please-wait-connect-oncall-eng')); score($AGI->exec("Queue CS_agents|tn|||60")); score($AGI->stream_file('all-reps-busy')); score($AGI->stream_file('please-wait-connect-oncall-eng')); score($AGI->exec("Queue CS_agents|tn|||60")); score($AGI->stream_file('all-reps-busy')); score($AGI->stream_file('goodbye')); score($AGI->hangup()); } else { # invalid input try again score($AGI->stream_file('invalid')); &question_1(); } } sub question_2 { # replace with sound file for # press 1, if the provider arrived before the scheduled time # press 2, if the provider arrived on time # press 3, if the provider show up late score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1) { if ($verbal_debug) { score($AGI->say_number('1')); } $AGI->verbose("Provider Arrived: EARLY", 3); &question_3(); } elsif ($getdigit == 2) { if ($verbal_debug) { score($AGI->say_number('2')); } $AGI->verbose("Provider Arrived: ONTIME", 3); &question_3(); } elsif ($getdigit == 3) { if ($verbal_debug) { score($AGI->say_number('3')); } $AGI->verbose("Provider Arrived: LATE", 3); &question_3(); } else { # invalid input try again score($AGI->stream_file('invalid')); &question_2(); } } sub question_3 { # replace with sound file for # press 1, if you have time for a short 3 question survey # press 2, if you do not score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1) { if ($verbal_debug) { score($AGI->say_number('1')); } $AGI->verbose("Time for Survey: YES", 3); &question_4(); } elsif ($getdigit == 2) { if ($verbal_debug) { score($AGI->say_number('2')); } $AGI->verbose("Time for Survey: NO", 3); score($AGI->stream_file('thank-you-cooperation')); score($AGI->stream_file('goodbye')); score($AGI->hangup()); # need to write info to database } else { # invalid input try again score($AGI->stream_file('invalid')); &question_3(); } } sub question_4 { # replace with sound file for # we would like to know about the quality of the service performed # from 1 to 5, where 1 was a poor experience to 5 being excellent score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1 || $getdigit == 2 || $getdigit == 3 || $getdigit == 4 || $getdigit == 5) { if ($verbal_debug) { score($AGI->say_number($getdigit)); } # write info to database &question_5(); } else { # invalid input try again score($AGI->stream_file('invalid')); &question_4(); } } sub question_5 { # replace with sound file for # we would like to know how courtious the provider was # from 1 to 5, where 1 was a poor experience to 5 being excellent score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1 || $getdigit == 2 || $getdigit == 3 || $getdigit == 4 || $getdigit == 5) { if ($verbal_debug) { score($AGI->say_number($getdigit)); } # write info to database &question_6(); } else { # invalid input try again score($AGI->stream_file('invalid')); &question_5(); } } sub question_6 { # replace with sound file for # and finally we would like to know if you would like to be entered in # our free drawing, we are giving away... # from 1 to 5, where 1 was a poor experience to 5 being excellent score($AGI->exec("READ dialed|gnudialer-intro|1||3|5")); my $getdigit = $AGI->get_variable("dialed"); $AGI->verbose("getDigit received: $getdigit", 3); if ($getdigit == 1 || $getdigit == 2 || $getdigit == 3 || $getdigit == 4 || $getdigit == 5) { if ($verbal_debug) { score($AGI->say_number($getdigit)); } # write info to database score($AGI->stream_file('thank-you-cooperation')); score($AGI->stream_file('goodbye')); score($AGI->hangup()); } else { # invalid input try again score($AGI->stream_file('invalid')); &question_6(); } }