From 76b5d2f2600eafb7a344b73aea6c33dd255c5f5a Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 5 Jul 2010 18:14:27 +0000 Subject: [PATCH] Added several new options to agi-AGENT_route.agi Added ability to send vendor_lead_code as a channel variable into the ALL_inbound AGI script when using VIDPROMPT Call Handle methods git-svn-id: svn://192.168.202.10@1470 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 7 ++ agi/agi-AGENT_route.agi | 211 +++++++++++++++++++++++++++++++---- agi/agi-VDAD_ALL_inbound.agi | 13 ++- 3 files changed, 208 insertions(+), 23 deletions(-) diff --git a/UPGRADE b/UPGRADE index ac5c77b3..eb52c1f6 100644 --- a/UPGRADE +++ b/UPGRADE @@ -185,6 +185,13 @@ OTHER CHANGES: fields, but you can import custom field data when using the non-agent API add_lead function(see the NON-AGENT_API.txt doc for more info). +44. Added more options to agi-AGENT_route.agi to allow it to prompt for user IDs + as well as set the number of digits to collect and check whether a user + is logged into ViciDial. The script can also now be run as an AGI route + option in CallMenus as well as in the custom dialplan. + Look at the comments in the code for more info. + + diff --git a/agi/agi-AGENT_route.agi b/agi/agi-AGENT_route.agi index a3ac46b2..e990196c 100644 --- a/agi/agi-AGENT_route.agi +++ b/agi/agi-AGENT_route.agi @@ -2,19 +2,37 @@ # # agi-AGENT_route.agi version 2.4 # -# for use with a Call Menu in the custom dialplan section. +# for use with a Call Menu in the custom dialplan section or as an AGI route. # # ; settings for this script: # ; 1. DID pattern to use for In-group initiation settings ('default' is default) # ; 2. the agentdirect in-group to send the calls to ('AGENTDIRECT' is default) +# ; 3. transfer only to ACTIVE in the system agent or vicidial LOGGED_IN agent +# ; ('ACTIVE' is default) +# ; 4. prompt for user ID, if this is filled in with a filename it will ask, +# ; otherwise it will assume $extension is the user ID +# ; 5. number of digits required for user ID validation, X will allow anything, +# ; this will only be enforced if "prompt for user ID" prompt is populated +# ; 6. audio filename for invalid selection, agent not available ('invalid' is default) +# ; 7. audio filename for invalid user id re-enter prompt, agent not available +# ; 8. number of retry attempts to enter a valid user ID +# ; this will only be enforced if "prompt for user ID" prompt is populated +# ; 7. in-group to send the call to if there is no valid agent, if none is +# ; defined, then the call will be directed to 's' exten +# ; 10. audio filename before sending call to no-agent route +# ; 11. audio filename before sending call to no-agent route if agent active but +# ; not logged-in to vicidial # +#; example in CallMenu AGI route with all options +# "agi-AGENT_route.agi,default---AGENTDIRECT---LOGGED_IN---if-u-know-ext-dial---X---invalid---please-try-again---3---TEST_IN3---pbxtransfer---outside-transfer" #; example with 4-digit agent IDs -# exten => _XXXX,1,AGI(agi-AGENT_route.agi,default---AGENTDIRECT) +# exten => _XXXX,1,AGI(agi-AGENT_route.agi,default---AGENTDIRECT---ACTIVE) # # Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 # # changes: # 100321-0108 - First Build +# 100704-2128 - Added several options # $script = 'agi-AGENT_route.agi'; @@ -124,14 +142,36 @@ if (length($ARGV[0])>1) ### list of command-line array arguments: @ARGV_vars = split(/---/, $ARGV[0]); - $did_settings = $ARGV_vars[0]; - $in_group = $ARGV_vars[1]; + $did_settings = $ARGV_vars[0]; + $in_group = $ARGV_vars[1]; + $agent_active_filter = $ARGV_vars[2]; + $user_id_prompt = $ARGV_vars[3]; + $minimum_user_digits = $ARGV_vars[4]; + $invalid_prompt = $ARGV_vars[5]; + $invalid_reenter_prompt = $ARGV_vars[6]; + $retry_attempts = $ARGV_vars[7]; + $invalid_ingroup = $ARGV_vars[8]; + $transfer_prompt = $ARGV_vars[9]; + $transfer_logout_prompt = $ARGV_vars[10]; } if (length($did_settings) < 1) {$did_settings = 'default';} if (length($in_group) < 1) {$in_group = 'AGENTDIRECT';} - +if (length($agent_active_filter) < 1) + {$agent_active_filter = 'ACTIVE';} +if (length($invalid_prompt) < 1) + {$invalid_prompt = 'invalid';} +if (length($retry_attempts) < 1) + {$retry_attempts = '3';} +if (length($minimum_user_digits) < 1) + {$minimum_user_digits = 'X';} +$pound_finish = 0; +if ($minimum_user_digits =~ /X/) + { + $minimum_user_digits = '20'; + $pound_finish = 1; + } $|=1; while() @@ -214,20 +254,41 @@ while ($sthArows > $cbc) } $sthA->finish(); -### find out if user exists and is active in system -$active_user=0; -$stmtA = "SELECT count(*) FROM vicidial_users where user='$extension' and active='Y';"; -$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; -$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; -$sthArows=$sthA->rows; -if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $active_user = $aryA[0]; - } -$sthA->finish(); +$active_user=0; +$logged_in_user=0; +if (length($user_id_prompt) > 0) + { + $attempts=0; + while ( ($retry_attempts > $attempts) && ($active_user < 1) ) + { + $attempts++; + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + + &user_id_gather; + + &find_if_active_user; + + if (length($invalid_reenter_prompt) > 0) + { + $user_id_prompt = $invalid_reenter_prompt; + } + } + } +else + { + &find_if_active_user; + } + +if ( ($agent_active_filter =~ /LOGGED_IN/) && ($logged_in_user < 1) && ($active_user > 0) ) + { + $transfer_prompt = $transfer_logout_prompt; + $active_user=0; + } + ### Route call to a logged-in VICIDIAL agent if ($active_user > 0) @@ -236,14 +297,31 @@ if ($active_user > 0) } else { - $did_extension = "s"; - $ext_context = $context; + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + $AGI->stream_file("$invalid_prompt"); - $AGI->stream_file('sip-silence'); - $AGI->stream_file('sip-silence'); - $AGI->stream_file('invalid'); + if (length($invalid_ingroup) > 1) + { + $did_extension = "99909$S$did_id$S$invalid_ingroup$S$S"; + } + else + { + $did_extension = "s"; + $ext_context = $context; + } } +if (length($transfer_prompt) > 1) + { + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + $AGI->stream_file('sip-silence'); + $AGI->stream_file("$transfer_prompt"); + } + + if ($AGILOG) {$agi_string = "exiting the AGENT app, transferring call to $did_extension @ $ext_context"; &agi_output;} print "SET CONTEXT $ext_context\n"; @@ -261,6 +339,94 @@ exit; ######### SUBROUTINES ################# +sub find_if_active_user + { + ### find out if user exists and is active in system + $stmtA = "SELECT count(*) FROM vicidial_users where user='$extension' and active='Y';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $active_user = $aryA[0]; + } + $sthA->finish(); + + if ($agent_active_filter =~ /LOGGED_IN/) + { + $stmtA = "SELECT count(*) FROM vicidial_live_agents where user='$extension';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $logged_in_user = $aryA[0]; + } + $sthA->finish(); + } + } + + +##### BEGIN collect the user id number ###################################### +sub user_id_gather + { + ################################################################################ + # please enter the agent id followed by the pound key + + $interrupt_digit=''; + + $interrupt_digit = $AGI->stream_file("$user_id_prompt",'0123456789'); + + print STDERR "interrupt_digit |$interrupt_digit|\n"; + + $digits_being_entered=1; + $extension=''; + if ($interrupt_digit > 0) + { + # if ($interrupt_digit == 35) {$interrupt_digit='#';} + # if ($interrupt_digit == 42) {$interrupt_digit='*';} + if ($interrupt_digit == 48) {$interrupt_digit=0;} + if ($interrupt_digit == 49) {$interrupt_digit=1;} + if ($interrupt_digit == 50) {$interrupt_digit=2;} + if ($interrupt_digit == 51) {$interrupt_digit=3;} + if ($interrupt_digit == 52) {$interrupt_digit=4;} + if ($interrupt_digit == 53) {$interrupt_digit=5;} + if ($interrupt_digit == 54) {$interrupt_digit=6;} + if ($interrupt_digit == 55) {$interrupt_digit=7;} + if ($interrupt_digit == 56) {$interrupt_digit=8;} + if ($interrupt_digit == 57) {$interrupt_digit=9;} + + $extension=$interrupt_digit; + } + + $digit_loop_counter=0; + while ( ($digits_being_entered > 0) && ($digit_loop_counter < $minimum_user_digits) ) + { + $digit = chr($AGI->wait_for_digit('10000')); # wait 10 seconds for input, until the pound key is pressed or X digits + if ($digit =~ /\d/) + { + $extension = "$extension$digit"; + print STDERR "digit |$digit| extension |$extension|\n"; + # $AGI->say_digits("$digit"); + undef $digit; + } + else + { + if ($pound_finish > 0) + {$digits_being_entered=0;} + } + + $digit_loop_counter++; + } + + $extension =~ s/\D//gi; + if ($extension > 0) {print STDERR "digit collection done|$digit| extension |$extension|\n";} + } + ##### END collect the user id number ############################################### + + sub checkresult { $pass=0; $fail=0; @@ -289,6 +455,7 @@ sub checkresult } } + sub agi_output { if ($AGILOG >=2) diff --git a/agi/agi-VDAD_ALL_inbound.agi b/agi/agi-VDAD_ALL_inbound.agi index 288f0dba..c0aa7683 100644 --- a/agi/agi-VDAD_ALL_inbound.agi +++ b/agi/agi-VDAD_ALL_inbound.agi @@ -44,6 +44,7 @@ # ; 10. the campaign_id to search within lists if CIDLOOKUPRC # ; 11. the user to queue the call to for AGENTDIRECT in-group calls # ; 12. vendor_lead_code if external mechanism like custom IVR is used to prompt user for ID +# ; you can also set the vendor_lead_code variable instead if you are using VIDPROMPT # ; 13. VID enter prompt filename to play if method is set to a VID* option # ; 14. VID you-have-entered filename to play if method is set to a VID* option # ; 15. VID confirm prompt filename to play if method is set to a VID* option @@ -678,7 +679,17 @@ if ($call_handle_method =~ /DIGITID$/) if ($call_handle_method =~ /^VIDPROMPT/) { - &enter_id_number; + $vendor_lead_code = $AGI->get_variable('vendor_lead_code'); + if ( ($AGILOG) && (length($vendor_lead_code)>0) ) {$agi_string = "vendor id AGI variable: |$vendor_lead_code|"; &agi_output;} + + if (length($vendor_lead_code)>2) + { + $vendor_id = $vendor_lead_code; + } + else + { + &enter_id_number; + } } if ($call_handle_method =~ /LOOKUP/)