by ibrahimbit17 » Mon Sep 26, 2011 4:04 am
Hi,
I have solved specific agent based call routing problem. For doing this I have added some extra control into agi-VDAD_ALL_inbound.agi file.
Now total scenario of my system is as like below:
Every registered customer has a respective agent and his/her basic information which are saved into vicidial_list . If any registered customer calls into system then he/she will given his/her registration ID after hearing IVR for giving this. Then system will check this customer's respective agent is logged in or not. If this agent is logged-in then system will send this caller call only this specific agent. Otherwise this caller call will go to others available agents "Call Queue" and then any agent can take this call using "Take call" option according to system setting.
For doing this I have changed this thing:
Firstly, I have saved every registered customer's agent name in "owner" column into vicidial_list.
When Any registered customer call into system then he/she will give his/her Registration ID. Then using this ID number I have make a new query in agi-VDAD_ALL_inbound.agi file for finding out the agent name against this registration ID. And then done other things.........
My agi-VDAD_ALL_inbound.agi file is below which I have changed. Please search in this file with this word "ibrahimbit0117" for further help and comments.
....................................................
.........................................................................
#!/usr/bin/perl
#
# agi-VDAD_ALL_inbound.agi version 2.4
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
# ## THIS SCRIPT CONSOLIDATES THIRTEEN SEPARATE VDAD closer inbound SCRIPTS ##
#
#
# You need to put lines similar to those below in your extensions.conf file:
# ; Below are the parameters needed for the script to be run properly
# ; 1. the method of call handling for the script:
# ; - CID - CID received, add record with phone number
# ; - CIDLOOKUP - Lookup CID to find record in whole system
# ; - CIDLOOKUPRL - Restrict lookup to one list
# ; - CIDLOOKUPRC - Restrict lookup to one campaign's lists
# ; - CLOSER - Closer calls from VICIDIAL fronters
# ; - ANI - ANI received, add record with phone number (based on RBS T1s)
# ; - ANILOOKUP - Lookup ANI to find record in whole system
# ; - ANILOOKUPRL - Restrict lookup to one list
# ; - ANILOOKUPRC - Restrict lookup to one campaign's lists
# ; - VID - Add record with Vendor Lead Code received as argument 12
# ; - VIDLOOKUP - Lookup Vendor Lead Code received as argument 12 to find record in whole system
# ; - VIDLOOKUPRL - Restrict lookup to one list (argument 12)
# ; - VIDLOOKUPRC - Restrict lookup to one campaign's lists (argument 12)
# ; - VIDPROMPT - Prompt Vendor Lead Code to User with IVR to add record with Vendor Lead Code
# ; - VIDPROMPTLOOKUP - Prompt Vendor Lead Code to User with IVR to find record in whole system
# ; - VIDPROMPTLOOKUPRL - Restrict lookup to one list
# ; - VIDPROMPTLOOKUPRC - Restrict lookup to one campaign's lists
# ; - 3DIGITID - Enter 3 digit code to go to agent
# ; - 4DIGITID - Enter 4 digit code to go to agent
# ; - XDIGITID - Enter X digit code to go to agent(variable, i.e. 9DIGITID, 12DIGITID, etc...)
# ; 2. the method of searching for an available agent:
# ; - LO - Load Balance Overflow only (priority to home server)
# ; - LB - <default> Load Balance total system
# ; - SO - Home server only
# ; 3. the full name of the IN GROUP to be used in vicidial for the inbound call
# ; 4. the phone number that was called, for the log entry
# ; 5. the callerID or lead_id of the person that called(usually overridden)
# ; 6. the park extension audio file name if used
# ; 7. the status of the call initially(usually not used)
# ; 8. the list_id to insert the new lead under if it is new (and CID/ANI available)
# ; 9. the phone dialing code to insert with the new lead if new (and CID/ANI available)
# ; 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
# ; 16. VID digit length validation to use if method is set to a VID* option, set to empty or X to disable
#
# ;inbound VICIDIAL calls:
#exten => 1234,1,Answer ; Answer the line
#exten => 1234,2,AGI(agi-VDAD_ALL_inbound.agi,CID-----LB-----INB-----7274515134-----Closer-----park----------999-----1-----OUTB)
#exten => 1234,3,Hangup
#
# ;inbound with removal of first digit of callerID on all calls:
#exten => 1234,1,Answer ; Answer the line
#exten => 1234,n,set(CALLERID(num)=${CALLERID(num):1})
#exten => 1234,n,AGI(agi-VDAD_ALL_inbound.agi,CID-----LB-----INB-----7274515134-----Closer-----park----------999-----1-----OUTB)
#exten => 1234,n,Hangup
#
#; inbound VICIDIAL transfer calls [can arrive through PRI T1 crossover, IAX or SIP channel]
#exten => _90009.,1,Answer ; Answer the line
#exten => _90009.,2,AGI(agi-VDAD_ALL_inbound.agi,CLOSER-----LB-----CL_TESTCAMP-----7275551212-----Closer-----park----------999-----1)
#exten => _90009.,3,Hangup
#exten => _990009.,1,Answer ; Answer the line
#exten => _990009.,2,AGI(agi-VDAD_ALL_inbound.agi,CLOSER-----LB-----CL_TESTCAMP-----7275551212-----Closer-----park----------999-----1)
#exten => _990009.,3,Hangup
#; DID forwarded calls
#exten => _99909*.,1,Answer
#exten => _99909*.,2,AGI(agi-VDAD_ALL_inbound.agi)
#exten => _99909*.,3,Hangup
#
# Copyright (C) 2011 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# changes:
# 70828-0924 - First Build
# 71013-0310 - Added use of default Music-on-hold instead of generic on-hold message
# 71020-1714 - fixed issues with MoH and stream_file messages
# 71024-2153 - Added CLOSER functionality for calls coming from VICIDIAL fronters
# 71029-1726 - Changed CLOSER-type campaigns to use new campaign_allow_inbound field
# 71030-0713 - fixed after-hours logging
# 71030-0939 - fixed issue where MoH was still playing, added ding and wait before transfer
# 71103-2305 - added group rank and fewest calls options to next_agent_call
# 71112-0058 - fixed multi-logging bug on CLOSER calls
# 71116-1045 - added fewest_calls_campaign agent call routing option
# 71128-1758 - added CIDLOOKUPRC method to search all lists within a campaign
# 80109-2348 - added option to trigger a system process when the call is sent to an agent
# 80227-0335 - added queue priority functionality
# 80302-0232 - added drop_action and transfer to in-group
# 80402-0142 - added code for manual dial transfer duplicate check
# 80430-1144 - added term_reason to vicidial_closer_log, QUEUETIMEOUT, AFTERHOURS
# 80501-0515 - added after hours transfer in-group
# 80525-1040 - added ability to convert IVR status inbound calls to LIVE in-group calls
# 80630-2232 - added queue_log logging of inbound calls
# 80821-0133 - fixed non-play issue with hold message
# 80918-0505 - Added place in line and estimated time on hold
# 81002-1120 - Added processing for DID forwarded calls
# 81011-1019 - Added option for press 1 to leave voicemail if wait time > hold-time-option-seconds
# 81020-0237 - Added term_reason logging for all possible exits of the script
# 81021-2315 - Changed and add queue_log logging
# 81024-0006 - Changed LOOKUP to insert new lead if phone_number < 3 digits, changed queue_sec calculation
# 81104-0301 - Changed code to alter callerIDnumber for remote agents to the number of the caller
# 81105-0248 - Added MySQL error logging
# 90103-0311 - Added sip-silences before transfers to fix rare MoH issues
# 90115-0601 - Added AGENTDIRECT functionality
# 90607-1717 - Fix for AGENTDIRECT bug under certain configurations
# 90623-0724 - Changed prompts to multi-file prompts, changed agent alert exten to a prompt
# 90627-0546 - Added no-agent-no-queue options
# 90702-2129 - Fixed rare agent alert bug, added option to send to remote agent as phone*vendor_id
# 90709-1648 - Fixed alt-number transfers
# 90712-2307 - Added agent grab call in queue
# 90720-0023 - Added checks for filename validity before streaming, changed initial heavy search from 3 to 2 seconds
# 90726-0114 - Fixed bug on some calls for agent grab
# 90808-0307 - Added longest_wait_time as agent routing option
# 91004-0959 - Fix for queue_log consultative transfers
# 91105-1258 - Added CallerIDnumber change on Drop when sending call out
# 91122-2352 - Added queue_log IVR and DID entry linking
# 91125-0921 - Fixed no-agent-no-queue AGENTDIRECT bug
# 91213-0942 - Added queue_position to queue_log COMPLETE... records
# 91214-2034 - Fixes for rare in-group rank route bug
# 91223-0959 - Added VID(vendor_lead_code) options
# 91230-0911 - Reset to original callerID when sending the call to VMAIL/CALLMENU/PHONE/etc...
# 100121-1954 - Added TIMEOT/AFTHRS/NANQUE dropping event statuses
# 100123-1015 - Added voicemail_id lookup for user from AGENTDIRECT drop
# 100212-0653 - Added AGENTVMAIL AGENTDIRECT option for no-queue, hold time and after hours features
# 100226-0927 - Fixed reinsert issue in vicidial_auto_calls table with auto_call_id
# 100319-0614 - Added extension group remote agent feature
# 100414-2046 - Added extension_appended_cidname option
# 100424-1234 - Added unique status options and extended logging
# 100429-1457 - Remote agent fixes
# 100512-2118 - Added several press-1 hold time options
# 100513-2338 - Changed hold time callback filename to after press filename and now plays after all PRESS-1
# 100518-0710 - Added call time after hours override options
# 100527-0111 - Added on-hold and hold-time-option no-block options and message seconds, NA CID cleaning
# 100616-1600 - Added VID filename and digit validation options
# 100718-1822 - Added second hold time option and wait time options
# 100805-1530 - Added FILTER from-did-route feature, changed active=n to go to after hours action
# 100811-0751 - Added calculate_estimated_hold_seconds option
# 100830-1445 - Allow the changing of the queue priority of a call while the call is in queue
# 100903-0041 - Changed lead_id max length to 10 digits
# 100929-1201 - Added add_lead_url feature
# 101008-0410 - Added option for alternate Minimum Hold Time Message
# 101219-2110 - Added call time overflow
# 110224-1735 - Added compatibility with QM phone environment logging
# 110303-2338 - Added on-hook agent compatibility and rewrote a few sections
# 110324-2330 - Added recording of remote agent calls, per in-group and campaign recording settings
# 110325-1409 - Added user recording override settings checking for remote agent recording
#
$script = 'agi-VDAD_ALL_inbound.agi';
$dtmf_silent_prefix = '7';
$DROP_TIME = 720; ### default number of seconds to wait until you drop a waiting call
$start_moh=1;
$wait_prompt_runs=0;
$at='@';
$S='*';
$mel=1; # Mysql Error Log enabled = 1
$mysql_log_count=173;
$one_mysql_log=0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$hm = "$hour$min";
$hm = ($hm + 0);
$now_date_epoch = time();
$start_epoch = $now_date_epoch;
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$CLInow_date = "$year-$mon-$mday\\ $hour:$min:$sec";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec";
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$ORIGINAL_call_time = $SQLdate;
while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959
$BDtarget = ($now_date_epoch - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
if (!$PRSLOGfile) {$PRSLOGfile = "$PATHlogs/prsout.$year-$mon-$mday";}
if (!$PRSTESTfile) {$PRSTESTfile = "$PATHlogs/prstest.$year-$mon-$mday";}
if (!$ERRLOGfile) {$ERRLOGfile = "$PATHlogs/MySQLerror.$year-$mon-$mday";}
use DBI;
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$stmtA = "SELECT agi_output,local_gmt FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
$rec_count=0;
while ($sthArows > $rec_count)
{
$AGILOG = '0';
@aryA = $sthA->fetchrow_array;
$DBagi_output = $aryA[0];
$local_gmt = $aryA[1];
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
$rec_count++;
}
$sthA->finish();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
$i++;
}
### list of command-line array arguments:
@ARGV_vars = split(/-----/, $ARGV[0]);
$call_handle_method = $ARGV_vars[0];
$agent_search_method = $ARGV_vars[1];
$channel_group = $ARGV_vars[2];
$inbound_number = $ARGV_vars[3];
$parked_by = $ARGV_vars[4];
$park_extension = $ARGV_vars[5];
$status = $ARGV_vars[6];
$list_id = $ARGV_vars[7];
$phone_code = $ARGV_vars[8];
$Scampaign_id = $ARGV_vars[9];
$agent_only = $ARGV_vars[10];
$vendor_id = $ARGV_vars[11];
$vid_enter_filename = $ARGV_vars[12];
$vid_id_number_filename = $ARGV_vars[13];
$vid_confirm_filename = $ARGV_vars[14];
$vid_validate_digits = $ARGV_vars[15];
}
$|=1;
while(<STDIN>)
{
chomp;
last unless length($_);
if ($AGILOG)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;}
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
if (/^agi_type\:\s+(.*)$/) {$type = $1;}
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;}
}
#......ibrahimbit0117......declare two variables for storing caller registration ID and find-out status his/her agent....agi debug...
$storeUserGivenRegistrationID = 0;
$respectiveAgentFound = 0;
#when respective agent name is found then this variable value will be set to 1
if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) )
{
$calleridname = $callerid;
$calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi;
$calleridname =~ s/\"|\" //gi;
}
$callerid =~ s/\D|\'//gi;
$calleridname =~ s/unknown|\'//gi;
if ( (!$callerid) or ($callerid =~ /unknown/) )
{$callerid = $calleridname;}
##### find out if this call is already in the vicidial_log_extended table
$VLEcount=0;
$stmtA = "SELECT count(*) FROM vicidial_log_extended where uniqueid='$uniqueid';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02144'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VLEcount = $aryA[0];
}
$sthA->finish();
$user_unavailable_action='';
##### special processing for DID forwarded calls "99909*1***DID"
if ($extension =~ /^999\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$referring_extension = $EXT_vars[0]; # initial extension sent
$did_id = $EXT_vars[1]; # the DID ID to grab settings from
$in_group_override = $EXT_vars[2]; # the in-group override, if set
$agentdirect_override = $EXT_vars[3]; # the agentdirect override, if set
$route_type = $EXT_vars[4]; # DID or FILTER from the did, if set
### Grab DID values from the database
if ($route_type =~ /FILTER/)
{
$stmtA = "SELECT filter_call_handle_method,filter_agent_search_method,filter_group_id,did_pattern,filter_list_id,filter_phone_code,filter_campaign_id,filter_user,filter_user_unavailable_action,filter_user_route_settings_ingroup,filter_action,filter_voicemail_ext,filter_extension,filter_exten_context,filter_phone,filter_server_ip FROM vicidial_inbound_dids where did_id = '$did_id';";
}
else
{
$stmtA = "SELECT call_handle_method,agent_search_method,group_id,did_pattern,list_id,phone_code,campaign_id,user,user_unavailable_action,user_route_settings_ingroup,did_route,voicemail_ext,extension,exten_context,phone,server_ip FROM vicidial_inbound_dids where did_id = '$did_id';";
}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02002'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$call_handle_method = $aryA[0];
$agent_search_method = $aryA[1];
$did_in_group = $aryA[2];
$inbound_number = $aryA[3];
$list_id = $aryA[4];
$phone_code = $aryA[5];
$Scampaign_id = $aryA[6];
$agent_only = $aryA[7];
$user_unavailable_action = $aryA[8];
$user_route_settings_ingroup = $aryA[9];
$did_route = $aryA[10];
$did_voicemail_ext = $aryA[11];
$did_extension = $aryA[12];
$did_exten_context = $aryA[13];
$did_phone = $aryA[14];
$did_phone_server_ip = $aryA[15];
if ($did_route =~ /AGENT/)
{$channel_group = $user_route_settings_ingroup;}
else
{$channel_group = $did_in_group;}
}
$sthA->finish();
if (length($agentdirect_override) > 0) {$agent_only = $agentdirect_override;}
if (length($in_group_override) > 1)
{
$igo_valid=0;
### if in_group_override is set, make sure it's valid
$stmtA = "SELECT count(*) FROM vicidial_inbound_groups where group_id='$in_group_override' and active='Y';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='01139'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$igo_valid = $aryA[0];
}
$sthA->finish();
if ($igo_valid > 0)
{
$channel_group = $in_group_override;
if ($AGILOG) {$agi_string = "In-Group Override: $in_group_override"; &agi_output;}
}
}
}
if ( ($phone_code =~ /^1$/) && ($callerid =~ /^1/) && (length($callerid) > 10) )
{
$callerid =~ s/^1//gi;
if ($AGILOG) {$agi_string = "North America CID Check: $phone_code|$callerid|"; &agi_output;}
}
$originalCID = $callerid;
if ($call_handle_method =~ /^CLOSER/)
{
### allow for internal PRI/IAX/SIP transfer data string "90009*CL_uk3survy_*8301*10000123*universal*7275551212*1234*"
if ($extension =~ /^900\d\d\*|^9900\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$referring_extension = $EXT_vars[0]; # initial extension sent
$channel_group = $EXT_vars[1]; # name of the parked group "In-group"
$inbound_number = $EXT_vars[2]; # extension to send call to after parsing
$parked_by = $EXT_vars[3]; # leadID
$park_extension = $EXT_vars[4]; # filename of the on-hold music file
$phone_number = $EXT_vars[5]; # phone number of customer
$fronter = $EXT_vars[6]; # user of the fronter that transferred the call
if ($channel_group =~ /AGENTDIRECT/)
{
$agent_only = $EXT_vars[7]; # optional AGENTDIRECT user to queue call for
}
$CIDlead_id = $parked_by;
$fronter_call_seconds = $EXT_vars[8]; # not currently used
$PADlead_id = sprintf("%010s", $parked_by); while (length($PADlead_id) > 10) {chop($PADlead_id);}
# JmmddhhmmssLLLLLLLLL
$JqueryCID = "J$CIDdate$PADlead_id";
$callerid = $JqueryCID;
$VCcallerid = $JqueryCID;
### set the new call callerid to track the call
$Jnewcallerid = "\"$JqueryCID <$phone_number>\"";
$AGI->set_callerid($Jnewcallerid);
if ($AGILOG) {$agi_string = "callerID changed: $Jnewcallerid"; &agi_output;}
}
}
if ( ($call_handle_method =~ /^CID/) || ($call_handle_method =~ /^VID/) )
{
if (length($callerid)>0) {$phone_number = $callerid;}
else {$phone_number = '';}
if (length($calleridname)>0) {$VLcomments = $calleridname;}
else {$VLcomments = '';}
}
# if ($channel =~ /^SIP/) {$channel =~ s/-.*//gi;}
# if ($channel =~ /^Zap\//) {$channel =~ s/-\d$//gi;}
if (length($callerid)<10) {$callerid = $parked_by;}
if (length($pin)>0) {$callerid = $pin;}
if ($call_handle_method =~ /^ANI/)
{
$phone_number='';
### allow for external ANI to be collected on older RBS T1 circuits
if ($extension =~ /\*\d\d\d\d\d\d\d\d\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$phone_number = $EXT_vars[1];
if ($AGILOG) {$agi_string = "ANI found: |$phone_number|"; &agi_output;}
}
}
# When VID or VIDPROMPT, methods are not used, no Vendor Lead Code can be supplied. Fill it with inbound_number
if ($call_handle_method !~ /^VID/)
{$vendor_id = $inbound_number;}
foreach $i (sort keys %AGI)
{
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
}
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;}
if (length($pin) < 1) {$pin=$inbound_number;}
$fronter = $pin;
if ($AGILOG) {$agi_string = "+++++ INBOUND CALL VDCL STARTED : |$channel_group|$callerid-$pin|$now_date"; &agi_output;}
$VDADphone='';
$VDADphone_code='';
$VCcallerid = $channel_group;
if (length($VCcallerid)<2)
{$VCcallerid = 'ViciDial Inbound';}
if ($channel =~ /Local/i)
{
if ( ($inbound_number =~ /CXFER/) || ($call_handle_method =~ /^CLOSER/) )
{
if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: CXFER OVERRIDE- $priority"; &agi_output;}
if ($call_handle_method =~ /^CLOSER/)
{
### sleep for 99 hundredths of a second
usleep(1*990*1000);
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where lead_id='$CIDlead_id' and call_type='IN' and campaign_id='$channel_group' and channel NOT LIKE \"Local%\";";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02003'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$Pseudo_duplicate_count = $aryA[0];
$rec_count++;
}
$sthA->finish();
if ($Pseudo_duplicate_count > 0)
{
if ($AGILOG) {$agi_string = "+++++ INBOUND LOCAL DUPLICATE: EXITING- $priority"; &agi_output;}
exit;
}
}
}
else
{
if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;}
exit;
}
}
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = $aryA[0];
$DBext_context = $aryA[1];
$DBanswer_transfer_agent = $aryA[2];
$DBSERVER_GMT = $aryA[3];
$DBasterisk_version = $aryA[4];
$DBmax_vicidial_trunks = $aryA[5];
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### Grab inbound groups values from the database
$cbc=0;
$stmtA = "SELECT call_time_id,after_hours_action,after_hours_message_filename,after_hours_exten,after_hours_voicemail,welcome_message_filename,moh_context,onhold_prompt_filename,prompt_interval,agent_alert_exten,agent_alert_delay,drop_call_seconds,drop_action,drop_exten,next_agent_call,voicemail_ext,queue_priority,drop_inbound_group,afterhours_xfer_group,play_place_in_line,play_estimate_hold_time,hold_time_option,hold_time_option_seconds,hold_time_option_exten,hold_time_option_voicemail,hold_time_option_xfer_group,hold_time_option_callback_filename,hold_time_option_callback_list_id,hold_recall_xfer_group,no_delay_call_route,play_welcome_message,no_agent_no_queue,no_agent_action,no_agent_action_value,extension_appended_cidname,uniqueid_status_display,uniqueid_status_prefix,hold_time_option_minimum,hold_time_option_press_filename,hold_time_option_callmenu,onhold_prompt_no_block,onhold_prompt_seconds,hold_time_option_no_block,hold_time_option_prompt_seconds,hold_time_second_option,hold_time_third_option,wait_hold_option_priority,wait_time_option,wait_time_second_option,wait_time_third_option,wait_time_option_seconds,wait_time_option_exten,wait_time_option_voicemail,wait_time_option_xfer_group,wait_time_option_callmenu,wait_time_option_callback_filename,wait_time_option_callback_list_id,wait_time_option_press_filename,wait_time_option_no_block,wait_time_option_prompt_seconds,active,calculate_estimated_hold_seconds,add_lead_url,eht_minimum_prompt_filename,eht_minimum_prompt_no_block,eht_minimum_prompt_seconds,on_hook_ring_time,ingroup_recording_override,ingroup_rec_filename FROM vicidial_inbound_groups where group_id = '$channel_group';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02005'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$call_time_id = $aryA[0];
$after_hours_action = $aryA[1];
$after_hours_message_filename = $aryA[2];
$after_hours_exten = $aryA[3];
$after_hours_voicemail = $aryA[4];
$welcome_message_filename = $aryA[5];
$moh_context = $aryA[6];
$onhold_prompt_filename = $aryA[7];
$prompt_interval = $aryA[8];
$agent_alert_exten = $aryA[9];
$agent_alert_delay = $aryA[10];
$drop_call_seconds = $aryA[11];
$DROP_TIME = $drop_call_seconds;
$drop_action = $aryA[12];
$drop_exten = $aryA[13];
$CAMP_callorder = $aryA[14];
$VDADvoicemail_ext = $aryA[15];
# $VDADvoicemail_ext =~ s/\D//gi;
$queue_priority = $aryA[16];
$drop_inbound_group = $aryA[17];
$afterhours_xfer_group = $aryA[18];
$play_place_in_line = $aryA[19];
$play_estimate_hold_time = $aryA[20];
$hold_time_option = $aryA[21];
$hold_time_option_seconds = $aryA[22];
$hold_time_option_exten = $aryA[23];
$hold_time_option_voicemail = $aryA[24];
$hold_time_option_xfer_group = $aryA[25];
$hold_time_option_callback_filename = $aryA[26];
$hold_time_option_callback_list_id = $aryA[27];
$hold_recall_xfer_group = $aryA[28];
$no_delay_call_route = $aryA[29];
if ($hold_time_option =~ /DROP_ACTION/)
{$hold_time_option = $drop_action;}
$hold_time_option_SETTING = $hold_time_option;
$play_welcome_message = $aryA[30];
$no_agent_no_queue = $aryA[31];
$no_agent_action = $aryA[32];
$no_agent_action_value = $aryA[33];
$extension_appended_cidname = $aryA[34];
$uniqueid_status_display = $aryA[35];
$uniqueid_status_prefix = $aryA[36];
$hold_time_option_minimum = $aryA[37];
$hold_time_option_press_filename = $aryA[38];
$hold_time_option_callmenu = $aryA[39];
$onhold_prompt_no_block = $aryA[40];
$onhold_prompt_seconds = $aryA[41];
$hold_time_option_no_block = $aryA[42];
$hold_time_option_prompt_seconds = $aryA[43];
$hold_time_second_option = $aryA[44];
$hold_time_third_option = $aryA[45];
$wait_hold_option_priority = $aryA[46];
$wait_time_option = $aryA[47];
$wait_time_option_SETTING = $wait_time_option;
$wait_time_second_option = $aryA[48];
$wait_time_third_option = $aryA[49];
$wait_time_option_seconds = $aryA[50];
$wait_time_option_exten = $aryA[51];
$wait_time_option_voicemail = $aryA[52];
$wait_time_option_xfer_group = $aryA[53];
$wait_time_option_callmenu = $aryA[54];
$wait_time_option_callback_filename = $aryA[55];
$wait_time_option_callback_list_id = $aryA[56];
$wait_time_option_press_filename = $aryA[57];
$wait_time_option_no_block = $aryA[58];
$wait_time_option_prompt_seconds = $aryA[59];
$ingroup_active = $aryA[60];
$calculate_estimated_hold_seconds = $aryA[61];
$add_lead_url = $aryA[62];
$eht_minimum_prompt_filename = $aryA[63];
$eht_minimum_prompt_no_block = $aryA[64];
$eht_minimum_prompt_seconds = $aryA[65];
$on_hook_ring_time = $aryA[66];
$ingroup_recording_override = $aryA[67];
$campaign_rec_filename = $aryA[68];
$custom_call_id='';
if ($uniqueid_status_display =~ /ENABLED/)
{$custom_call_id = "$uniqueid";}
if ($uniqueid_status_display =~ /ENABLED_PREFIX/)
{$custom_call_id = "$uniqueid_status_prefix$uniqueid";}
}
$sthA->finish();
if ($wday==0) {$daySQL=',ct_sunday_start,ct_sunday_stop,sunday_afterhours_filename_override';}
if ($wday==1) {$daySQL=',ct_monday_start,ct_monday_stop,monday_afterhours_filename_override';}
if ($wday==2) {$daySQL=',ct_tuesday_start,ct_tuesday_stop,tuesday_afterhours_filename_override';}
if ($wday==3) {$daySQL=',ct_wednesday_start,ct_wednesday_stop,wednesday_afterhours_filename_override';}
if ($wday==4) {$daySQL=',ct_thursday_start,ct_thursday_stop,thursday_afterhours_filename_override';}
if ($wday==5) {$daySQL=',ct_friday_start,ct_friday_stop,friday_afterhours_filename_override';}
if ($wday==6) {$daySQL=',ct_saturday_start,ct_saturday_stop,saturday_afterhours_filename_override';}
### Grab call_times values from the database
$stmtA = "SELECT ct_default_start,ct_default_stop,default_afterhours_filename_override $daySQL FROM vicidial_call_times where call_time_id = '$call_time_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02006'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
@aryA = $sthA->fetchrow_array;
$ct_default_start = $aryA[0];
$ct_default_stop = $aryA[1];
$deafult_afterhours_filename_override = $aryA[2];
$ct_day_start = $aryA[3];
$ct_day_stop = $aryA[4];
$day_afterhours_filename_override = $aryA[5];
$sthA->finish();
if ( ($ct_day_start > 0) || ($ct_day_stop > 0) )
{
$ct_default_start = $ct_day_start;
$ct_default_stop = $ct_day_stop;
}
if ( (length($deafult_afterhours_filename_override) > 0) && ($deafult_afterhours_filename_override !~ /---NONE---/) )
{$after_hours_message_filename = $deafult_afterhours_filename_override;}
if ( (length($day_afterhours_filename_override) > 0) && ($day_afterhours_filename_override !~ /---NONE---/) )
{$after_hours_message_filename = $day_afterhours_filename_override;}
# send call to after hours action if in-group is set to inactive
if ($ingroup_active !~ /Y/)
{
$ct_default_start = 2400;
$ct_default_stop = 2400;
if ($AGILOG) {$agi_string = "IN-GROUP INACTIVE! Sending to After Hours Action: |$after_hours_action|$ingroup_active|"; &agi_output;}
}
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($call_handle_method =~ /DIGITID$/)
{
&enter_pin_number;
if (length($pin) > 0)
{$fronter = $pin;}
}
if ($call_handle_method =~ /^VIDPROMPT/)
{
$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/)
{
if ( ( ($call_handle_method =~ /^VID/) && (length($vendor_id)) < 3) || (length($phone_number) < 3) )
{
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$vendor_id','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','$local_gmt','$VLcomments');";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02007'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$cbc=0;
$stmtB = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $stmtA=$stmtB; $mysql_count='02008'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = $aryA[0];
$cbc++;
}
$sthA->finish();
### Start the Add-Lead-URL get proccess
if (length($add_lead_url) > 5)
{
$launch = $PATHhome . "/AST_send_URL.pl";
$launch .= " --SYSLOG" if ($SYSLOG);
$launch .= " --lead_id=" . $insert_lead_id;
$launch .= " --phone_number=" . $phone_number;
$launch .= " --user=";
$launch .= " --call_type=IN";
$launch .= " --campaign=" . $channel_group;
$launch .= " --uniqueid=" . $uniqueid;
$launch .= " --alt_dial=";
$launch .= " --function=INGROUP_ADD_LEAD_URL";
system($launch . ' &');
if ($AGILOG) {$agi_string = "$launch|"; &agi_output;}
}
if ($AGILOG) {$agi_string = "VDAD vicidial_list insert |$insert_lead_id|$stmtA|"; &agi_output;}
}
else
{
$listSQL = '';
if ($call_handle_method =~ /LOOKUPRL$/)
{$listSQL = "and list_id='$list_id'";}
else
{
if ($call_handle_method =~ /LOOKUPRC$/)
{
### Grab all lists associated with Scampaign_id
$cbc=0;
$SlistsSQL='';
$stmtA = "SELECT list_id FROM vicidial_lists where campaign_id='$Scampaign_id' limit 1000;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$SlistsSQL .= "'$aryA[0]',";
$cbc++;
}
$sthA->finish();
chop($SlistsSQL);
if (length($SlistsSQL)>3)
{$listSQL = "and list_id IN($SlistsSQL)";}
}
}
$cbc=0;
if ($call_handle_method =~ /^VID/)
{
$stmtA= "SELECT lead_id from vicidial_list where vendor_lead_code='$vendor_id' $listSQL order by last_local_call_time desc limit 1;";
}
else
{
$stmtA= "SELECT lead_id from vicidial_list where phone_number='$phone_number' $listSQL order by last_local_call_time desc limit 1;";
}
if ($AGILOG) {$agi_string = "VDAD vicidial_list search |$phone_number|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02010'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = $aryA[0];
$cbc++;
}
$sthA->finish();
if ($AGILOG) {$agi_string = "VDAD vicidial_list found |$insert_lead_id|$stmtA|"; &agi_output;}
}
else
{
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$vendor_id','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','$local_gmt','$VLcomments');";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02011'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$cbc=0;
$stmtB = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $stmtA=$stmtB; $mysql_count='02012'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = $aryA[0];
$cbc++;
}
$sthA->finish();
### Start the Add-Lead-URL get proccess
if (length($add_lead_url) > 5)
{
$launch = $PATHhome . "/AST_send_URL.pl";
$launch .= " --SYSLOG" if ($SYSLOG);
$launch .= " --lead_id=" . $insert_lead_id;
$launch .= " --phone_number=" . $phone_number;
$launch .= " --user=";
$launch .= " --call_type=IN";
$launch .= " --campaign=" . $channel_group;
$launch .= " --uniqueid=" . $uniqueid;
$launch .= " --alt_dial=";
$launch .= " --function=INGROUP_ADD_LEAD_URL";
system($launch . ' &');
if ($AGILOG) {$agi_string = "$launch|"; &agi_output;}
}
if ($AGILOG) {$agi_string = "VDAD vicidial_list insert |$insert_lead_id|$stmtA|"; &agi_output;}
}
}
}
else
{
if ($call_handle_method =~ /CLOSER/)
{
### Grab call lead parameters from vicidial_list table
$cbc=0;
$stmtA = "SELECT phone_number,phone_code,user,vendor_lead_code FROM vicidial_list where lead_id='$CIDlead_id' limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02013'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$campaign = "$channel_group";
if (length($phone_number) < 10)
{$phone_number = $aryA[0];}
$phone_code = $aryA[1];
$insert_lead_id = $CIDlead_id;
$fronter = $aryA[2];
$vendor_id = $aryA[3];
$cbc++;
}
$sthA->finish();
}
else
{
### insert a record into the vicidial_list table if no record was found above
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$vendor_id','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02014'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02015'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = $aryA[0];
$cbc++;
}
$sthA->finish();
### Start the Add-Lead-URL get proccess
if (length($add_lead_url) > 5)
{
$launch = $PATHhome . "/AST_send_URL.pl";
$launch .= " --SYSLOG" if ($SYSLOG);
$launch .= " --lead_id=" . $insert_lead_id;
$launch .= " --phone_number=" . $phone_number;
$launch .= " --user=";
$launch .= " --call_type=IN";
$launch .= " --campaign=" . $channel_group;
$launch .= " --uniqueid=" . $uniqueid;
$launch .= " --alt_dial=";
$launch .= " --function=INGROUP_ADD_LEAD_URL";
system($launch . ' &');
if ($AGILOG) {$agi_string = "$launch|"; &agi_output;}
}
}
}
##### BEGIN AFTER HOURS CHECK #####
$ct_stop_overflow=0; # allow for overflow time, past midnight
if ($ct_default_stop > 2400)
{$ct_stop_overflow = ($ct_default_stop - 2400);}
if ( ( ($hm < $ct_default_start) || ($hm > $ct_default_stop) ) && ($hm >= $ct_stop_overflow) )
{
$VHqueryCID = "VA$CIDdate$hour$min$sec$sec";
$stmtA = "INSERT INTO vicidial_closer_log set status='AFTHRS',start_epoch='$now_date_epoch',end_epoch='$now_date_epoch',length_in_sec='1',queue_seconds='0',lead_id = '$insert_lead_id',campaign_id='$channel_group',user='VDCL',list_id='$list_id',call_date='$now_date',phone_code='$phone_code',phone_number='$phone_number',comments='AFTER HOURS DROP',term_reason='AFTERHOURS',uniqueid='$uniqueid';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02016'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$stmtB = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtB ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $stmtA=$stmtB; $mysql_count='02017'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$insert_close_id = $aryA[0];
$cbc++;
}
$sthA->finish();
if ($AGILOG) {$agi_string = "-- AH VDCL vcl insert: |$affected_rows|$insert_lead_id|$insert_close_id|$hm|$ct_default_start|$ct_default_stop|$ct_stop_overflow\n|$stmtA|"; &agi_output;}
if ($VLEcount < 1)
{
$stmtA = "INSERT INTO vicidial_log_extended set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$callerid',custom_call_id='$custom_call_id';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02145'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- AH VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;}
$VLEcount++;
}
$stmtA = "UPDATE vicidial_list set status='AFTHRS' where lead_id = '$insert_lead_id';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02018'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- AH VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02019'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- AH VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;}
if ($AGILOG) {$agi_string = "-- AH action: |$after_hours_action|$after_hours_exten|$after_hours_message_filename|$after_hours_voicemail|"; &agi_output;}
if ($after_hours_action =~ /EXTENSION|VOICEMAIL|IN_GROUP/)
{
if ($after_hours_action =~ /EXTENSION/)
{
$DROPexten = "$after_hours_exten";
$CIDcampaign_cid='0000000000';
### Grab ID values from the database
$stmtA = "SELECT campaign_id,campaign_cid FROM vicidial_campaigns where closer_campaigns LIKE \"% $channel_group %\" and active='Y';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02113'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$CIDcampaign_id = $aryA[0];
$CIDcampaign_cid = $aryA[1];
}
$sthA->finish();
$newcallerid = "\"$callerid <$CIDcampaign_cid>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: \"$callerid\" \<$CIDcampaign_cid\> from $CIDcampaign_id"; &agi_output;}
}
if ($after_hours_action =~ /VOICEMAIL/)
{
if ( ($channel_group =~ /AGENTDIRECT/) && (length($agent_only) > 1) && ($after_hours_voicemail =~ /AGENTVMAIL/) )
{
### Grab user's voicemail ID from the database
$stmtA = "SELECT voicemail_id FROM vicidial_users where user='$agent_only';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02124'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$after_hours_voicemail = $aryA[0];
}
$sthA->finish();
}
$newcallerid = "\"$VCcallerid <$originalCID>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: $newcallerid"; &agi_output;}
$DROPexten = "$voicemail_dump_exten$after_hours_voicemail";
}
if ($after_hours_action =~ /IN_GROUP/)
{ # 90009*CL_uk3survy_*8301*10000123*universal*7275551212*1234*"
$DROPexten = "90009*$afterhours_xfer_group$S$S$insert_lead_id$S$S$phone_number$S$fronter$S";
}
if (length($DROPexten)>0)
{ ### if DROP extension is defined then send the dropped call there instead of hangup
if ($no_delay_call_route =~ /N/)
{
$AGI->stream_file('sip-silence'); # stop music-on-hold process
$AGI->stream_file('sip-silence');
### sleep for 99 hundredths of a second
usleep(1*990*1000);
}
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($AGILOG) {$agi_string = "exiting the VDAD app after hours, transferring call to $DROPexten"; &agi_output;}
print "SET CONTEXT $ext_context\n";
checkresult($result);
print "SET EXTENSION $DROPexten\n";
checkresult($result);
print "SET PRIORITY 1\n";
checkresult($result);
}
}
if ($after_hours_action =~ /HANGUP/)
{
### insert a NEW record to the vicidial_manager table to hangup the channel
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02020'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- VDCL call_hungup after hours: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
}
if ($after_hours_action =~ /MESSAGE/)
{
if (length($after_hours_message_filename) > 0)
{
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($after_hours_message_filename =~ /\|/)
{
@after_hours_message_filename_array = split(/\|/,$after_hours_message_filename);
$w=0;
foreach(@after_hours_message_filename_array)
{
if (length($after_hours_message_filename_array[$w])>0)
{
$AGI->stream_file("$after_hours_message_filename_array[$w]");
}
$w++;
}
}
else
{$AGI->stream_file("$after_hours_message_filename");}
}
### sleep for 99 hundredths of a second
usleep(1*990*1000);
### insert a NEW record to the vicidial_manager table to hangup the channel
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02021'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- AH VDCL call_hungup after hours: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
}
$dbhA->disconnect();
exit;
}
##### END AFTER HOURS CHECK #####
##### BEGIN NO AGENT NO QUEUE CHECK #####
if ($no_agent_no_queue =~ /Y|NO_PAUSED/)
{
$NPsql='';
$ADsql='';
if ($no_agent_no_queue =~ /NO_PAUSED/)
{$NPsql = "and status NOT IN('PAUSED')";}
if ( ($channel_group =~ /AGENTDIRECT/i) && (length($agent_only) > 1) )
{$ADsql = "and user='$agent_only'";}
$stmtA = "SELECT count(*) FROM vicidial_live_agents where closer_campaigns LIKE \"% $channel_group %\" $NPsql $ADsql;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02104'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$group_agents_count = $aryA[0];
}
$sthA->finish();
if ($group_agents_count < 1)
{
$VHqueryCID = "VA$CIDdate$hour$min$sec$sec";
$stmtA = "INSERT INTO vicidial_closer_log set status='NANQUE',start_epoch='$now_date_epoch',end_epoch='$now_date_epoch',length_in_sec='1',queue_seconds='0',lead_id = '$insert_lead_id',campaign_id='$channel_group',user='VDCL',list_id='$list_id',call_date='$now_date',phone_code='$phone_code',phone_number='$phone_number',comments='NO AGENT DROP',term_reason='NOAGENT',uniqueid='$uniqueid';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02105'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$stmtB = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtB ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $stmtA=$stmtB; $mysql_count='02017'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$insert_close_id = $aryA[0];
$cbc++;
}
$sthA->finish();
if ($AGILOG) {$agi_string = "-- NA VDCL vcl insert: |$affected_rows|$insert_lead_id|$insert_close_id|\n|$stmtA|"; &agi_output;}
if ($VLEcount < 1)
{
$stmtA = "INSERT INTO vicidial_log_extended set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$callerid',custom_call_id='$custom_call_id';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02146'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- NANQUE VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;}
$VLEcount++;
}
$stmtA = "UPDATE vicidial_list set status='NANQUE' where lead_id = '$insert_lead_id';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02106'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- NA VDCL vl update: |$affected_rows|$insert_lead_id|\n|$stmtA|"; &agi_output;}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$VARserver_ip' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02107'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- NA VDCL vac record deleted: |$affected_rows| $VDADcampaign|"; &agi_output;}
if ($no_agent_action =~ /CALLMENU|INGROUP|DID|EXTENSION|VOICEMAIL/)
{
if ($no_agent_action =~ /EXTENSION/)
{
if (length($no_agent_action_value) < 3)
{$no_agent_action_value = '8304,default';}
@EXno_agent_action_value = split(/,/,$no_agent_action_value);
$DROPexten = $EXno_agent_action_value[0];
$ext_context = $EXno_agent_action_value[1];
$CIDcampaign_cid='0000000000';
### Grab ID values from the database
$stmtA = "SELECT campaign_id,campaign_cid FROM vicidial_campaigns where closer_campaigns LIKE \"% $channel_group %\" and active='Y';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02114'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$CIDcampaign_id = $aryA[0];
$CIDcampaign_cid = $aryA[1];
}
$sthA->finish();
$newcallerid = "\"$callerid <$CIDcampaign_cid>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: \"$callerid\" \<$CIDcampaign_cid\> from $CIDcampaign_id"; &agi_output;}
}
if ($no_agent_action =~ /DID/)
{
$newcallerid = "\"$VCcallerid <$originalCID>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: $newcallerid"; &agi_output;}
if (length($no_agent_action_value) < 1)
{$no_agent_action_value = '6666';}
$DROPexten = $no_agent_action_value;
$ext_context = 'trunkinbound';
}
if ($no_agent_action =~ /CALLMENU/)
{
$newcallerid = "\"$VCcallerid <$originalCID>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: $newcallerid"; &agi_output;}
$DROPexten = 's';
$ext_context = $no_agent_action_value;
}
if ($no_agent_action =~ /VOICEMAIL/)
{
if ( ($channel_group =~ /AGENTDIRECT/) && (length($agent_only) > 1) && ($no_agent_action_value =~ /AGENTVMAIL/) )
{
### Grab user's voicemail ID from the database
$stmtA = "SELECT voicemail_id FROM vicidial_users where user='$agent_only';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02125'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$no_agent_action_value = $aryA[0];
}
$sthA->finish();
}
$newcallerid = "\"$VCcallerid <$originalCID>\"";
$AGI->set_callerid($newcallerid);
print STDERR "Setting CID \"$newcallerid\"\n";
checkresult($result);
if ($AGILOG) {$agi_string = "callerID changed: $newcallerid"; &agi_output;}
$DROPexten = "$voicemail_dump_exten$no_agent_action_value";
}
if ($no_agent_action =~ /INGROUP/)
{ # 90009*CL_uk3survy_*8301*10000123*universal*7275551212*1234*"
if (length($no_agent_action_value) < 10)
{$no_agent_action_value = 'SALESLINE,CID,LB,998,TESTCAMP,1';}
@IGno_agent_action_value = split(/,/,$no_agent_action_value);
$IGgroup_id = $IGno_agent_action_value[0];
$IGhandle_method = $IGno_agent_action_value[1];
$IGsearch_method = $IGno_agent_action_value[2];
$IGlist_id = $IGno_agent_action_value[3];
$IGcampaign_id = $IGno_agent_action_value[4];
$IGphone_code = $IGno_agent_action_value[5];
$DROPexten = "90009*$IGgroup_id$S$S$insert_lead_id$S$S$phone_number$S$fronter$S";
}
if (length($DROPexten)>0)
{ ### if DROP extension is defined then send the dropped call there instead of hangup
if ($no_delay_call_route =~ /N/)
{
$AGI->stream_file('sip-silence'); # stop music-on-hold process
$AGI->stream_file('sip-silence');
### sleep for 99 hundredths of a second
usleep(1*990*1000);
}
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($AGILOG) {$agi_string = "exiting the VDAD app no agent no queue, transferring call to $DROPexten"; &agi_output;}
print "SET CONTEXT $ext_context\n";
checkresult($result);
print "SET EXTENSION $DROPexten\n";
checkresult($result);
print "SET PRIORITY 1\n";
checkresult($result);
}
}
if ($no_agent_action =~ /MESSAGE/)
{
if (length($no_agent_action_value) > 0)
{
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($no_agent_action_value =~ /\|/)
{
@no_agent_action_value_array = split(/\|/,$no_agent_action_value);
$w=0;
foreach(@no_agent_action_value_array)
{
if (length($no_agent_action_value_array[$w])>0)
{
$AGI->stream_file("$no_agent_action_value_array[$w]");
}
$w++;
}
}
else
{$AGI->stream_file("$no_agent_action_value");}
}
### sleep for 99 hundredths of a second
usleep(1*990*1000);
### insert a NEW record to the vicidial_manager table to hangup the channel
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02021'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
if ($AGILOG) {$agi_string = "-- NA VDCL call_hungup after hours: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
}
$dbhA->disconnect();
exit;
}
}
##### END NO AGENT NO QUEUE CHECK #####
##### PLAY WELCOME MESSAGE #####
if ( ($welcome_message_filename !~ /---NONE---/) && (length($welcome_message_filename) > 0) && ( ($play_welcome_message =~ /ALWAYS/) || ( ($no_delay_call_route =~ /N/) && ($play_welcome_message =~ /YES_UNLESS_NODELAY/) ) ) )
{
if ($welcome_message_filename =~ /\|/)
{
@welcome_message_filename_array = split(/\|/,$welcome_message_filename);
$w=0;
foreach(@welcome_message_filename_array)
{
if (length($welcome_message_filename_array[$w])>0)
{
$AGI->stream_file("$welcome_message_filename_array[$w]");
}
$w++;
}
}
else
{$AGI->stream_file("$welcome_message_filename");}
}
if ($play_welcome_message =~ /IF_WAIT_ONLY/)
{$if_wait_play_welcome