Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N
-- Grab cluster distinct prefixes (outbound ones)
SELECT DISTINCT(dial_prefix) FROM vicidial_campaigns;
-- Generate SQL query
SELECT number_dialed FROM call_log WHERE number_dialed IN ('prefix_1+phone_number','prefix_2+phone_number',''prefix_3+phone_number');
#!/usr/bin/perl
#################################################################################################
# #
# Insert into call_log for Outbound calls #
# #
# Ergest Basha 05.08.2023 #
# #
#################################################################################################
use strict;
use warnings;
use DBI;
use Config::IniFiles;
use POSIX qw(strftime);
use sigtrap;
use sigtrap qw(handler my_handler normal-signals stack-trace error-signals);
my $datetime = strftime ("%Y-%m-%d %H:%M:%S", localtime time) ;
###################################################### DB connection ###########################################################
my $cfg = Config::IniFiles -> new( -file => '/etc/pronto.ini' );
my $dbinst = $cfg -> val('AST', 'DBINST');
my $dbhost = $cfg -> val('AST', 'DBHOST');
my $dbuser = $cfg -> val('AST', 'DBUSER');
my $dbpass = $cfg -> val('AST', 'DBPASS');
my $dbhA = DBI->connect( "dbi:mysql:$dbinst:$dbhost",$dbuser,$dbpass,
{ RaiseError => 0,
PrintError => 1,
AutoCommit => 0,
}
) or die $DBI::errstr;
###################################################### DB connection ###########################################################
############################### Kalohen te dhenat nga kanali (asterisk) te scripti ####################
(my $empty_field, my $data ) = @ARGV;
my @data_array = split /--/, $data;
my $uniqueid = $data_array[0];
my $channel = $data_array[1];
my $type = $data_array[2];
my $extension = $data_array[3];
my $number_dialed = $data_array[4];
my $caller_code = $data_array[5];
my $start_epoch = $data_array[6];
########################################### Kalohen te dhenat nga kanali (asterisk) te scripti ##########################################
############################### Kur perdorim strict variablat duhet te deklarohen para se te perdoren #####################
my $channel_group = 'OUTBOUND';
my $server_ip = '192.168.100.14';
my $start_time = $datetime;
############################### Kur perdorim strict variablat duhet te deklarohen para se te perdoren #####################
################################## Inseron te dhena te tabela call_log ##############
my $query_insert_data = "INSERT INTO call_log ( uniqueid ,
channel ,
channel_group ,
type ,
server_ip ,
extension ,
number_dialed ,
caller_code ,
start_time ,
start_epoch )
VALUES(?,?,?,?,?,?,?,?,?,?)";
my $statement_data = $dbhA->prepare($query_insert_data);
$statement_data->execute( $uniqueid ,
$channel ,
$channel_group ,
$type ,
$server_ip ,
$extension ,
$number_dialed ,
$caller_code ,
$start_time ,
$start_epoch );
$statement_data->finish();
################################## Inseron te dhena te tabela call_log ##############
################## Close DB connection ##################
warn $DBI::errstr if $DBI::err;
$dbhA->commit();
$dbhA->disconnect();
################## Close DB connection ##################
#!/usr/bin/perl
#################################################################################################
# #
# Update call_log for Outbound calls #
# #
# Ergest Basha 05.08.2023 #
# #
#################################################################################################
use strict;
use warnings;
use DBI;
use Config::IniFiles;
use POSIX qw(strftime);
use sigtrap;
use sigtrap qw(handler my_handler normal-signals stack-trace error-signals);
my $datetime = strftime ("%Y-%m-%d %H:%M:%S", localtime time) ;
###################################################### DB connection ###########################################################
my $cfg = Config::IniFiles -> new( -file => '/etc/pronto.ini' );
my $dbinst = $cfg -> val('AST', 'DBINST');
my $dbhost = $cfg -> val('AST', 'DBHOST');
my $dbuser = $cfg -> val('AST', 'DBUSER');
my $dbpass = $cfg -> val('AST', 'DBPASS');
my $dbhA = DBI->connect( "dbi:mysql:$dbinst:$dbhost",$dbuser,$dbpass,
{ RaiseError => 0,
PrintError => 1,
AutoCommit => 0,
}
) or die $DBI::errstr;
###################################################### DB connection ###########################################################
############################### Kalohen te dhenat nga kanali (asterisk) te scripti ####################
(my $empty_field, my $data ) = @ARGV;
my @data_array = split /--/, $data;
my $uniqueid = $data_array[0];
my $number_dialed = $data_array[1];
my $end_epoch = $data_array[2];
########################################### Kalohen te dhenat nga kanali (asterisk) te scripti ##########################################
################################## update-on tabelen call_log ne mbyllje te telefonates ##############
my $query_insert_data = "update call_log set end_epoch = ? , end_time = ? where uniqueid = ? limit 2";
my $statement_data = $dbhA->prepare($query_insert_data);
$statement_data->bind_param(1,$end_epoch) ;
$statement_data->bind_param(2,$end_time) ;
$statement_data->bind_param(3,$uniqueid) ;
$statement_data->execute();
$statement_data->finish();
################################## update-on tabelen call_log ne mbyllje te telefonates ##############
################## Close DB connection ##################
warn $DBI::errstr if $DBI::err;
$dbhA->commit();
$dbhA->disconnect();
################## Close DB connection ##################
exten => _744441100XX!,1,AGI(it_agi/clean_extension.agi,,${EXTEN:6})
exten => _744441100XX!,n,Set(number_dialed=${ClientNumber})
exten => _744441100XX!,n,AGI(it_agi/it-out-number-translation.agi,,${number_dialed})
exten => _744441100XX!,n,Set(Numero=${numero})
exten => _744441100XX!,n,Set(caller_code=${CALLERID(num)})
exten => _744441100XX!,n,AGI(it_agi/out_call_log_insert.agi,,${UNIQUEID}--${CHANNEL}--${CUT(CHANNEL,/,1)}--${EXTEN}--${number_dialed}--${caller_code}--${EPOCH})
exten => _744441100XX!,n,Set(${CALLERID(name)}=${CALLERID(num)})
exten => _744441100XX!,n,Set(filename=${CALLERID(num)}-${number_dialed}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten => _744441100XX!,n,Monitor(gsm,/var/spool/asterisk/monitorDONE/GSM/${filename},m)
exten => _744441100XX!,n,Set(tipo_chiam=PreOutboundVicidial)
exten => _744441100XX!,n,AGI(it_agi/pre_data_out_vicidial.agi,,${UNIQUEID}--${caller_code}--${tipo_chiam}--${number_dialed})
exten => _744441100XX!,n,GotoIf($["${linea}" = "bt"]?btonly)
exten => _744441100XX!,n,GotoIf($["${linea}" = "9"]?albanoonly)
exten => _744441100XX!,n,Set(CALLERID(num)=39${CALLERID(num)})
exten => _744441100XX!,n,Dial(${trunkvici}/90039${numero},,tTo)
exten => _744441100XX!,n,GotoIf($[$["${DIALSTATUS}" != "ANSWER"] & $["${DIALSTATUS}" != "BUSY"]]?bt:ok)
exten => _744441100XX!,n(ok),Hangup()
exten => _744441100XX!,n(bt),Set(CALLERID(num)=${CALLERID(num):2})
exten => _744441100XX!,n,NoOp(${DIALSTATUS})
exten => _744441100XX!,n,Dial(${trunkvici}/0039${numero},,tTo)
exten => _744441100XX!,n,Hangup()
exten => _744441100XX!,n(btonly),Dial(${trunkvici}/0039${numero},,tTo)
exten => _744441100XX!,n,Hangup()
exten => _744441100XX!,n(albanoonly),Set(CALLERID(num)=39${CALLERID(num)})
exten => _744441100XX!,n,Dial(${trunkvici}/90039${numero},,tTo)
exten => _744441100XX!,n,Hangup()
[it_out_mbyllje_gesti]
exten => h,1,Set(Mbyllje=Outbound Vicidial)
exten => h,n,Set(tipo_chiam=OutboundVicidial)
exten => h,n,AGI(it_agi/out_call_log_update.agi,,${UNIQUEID}--${numero}--${EPOCH}--${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME}-----${HANGUPCAUSE(${HANGUPCAUSE_KEYS()},tech)})
exten => h,n,AGI(it_agi/data_out_vicidial.agi,,${UNIQUEID}--${DIALSTATUS}--${ANSWEREDTIME}--${tipo_chiam}--${number_dialed}--${caller_code})
exten => h,n,Hangup()
exten => h,n,GotoIf($[$["${stato}" = "IT"] & $["${tipo_chiam}" = "PreOutboundVicidial"]]?it_out_mbyllje_gesti,${EXTEN},1:)
exten => _744441100XX!,1,AGI(it_agi/clean_extension.agi,,${EXTEN:6})
exten => _744441100XX!,n,Set(number_dialed=${ClientNumber})
exten => _744441100XX!,n,AGI(it_agi/it-out-number-translation.agi,,${number_dialed})
exten => _744441100XX!,n,Set(Numero=${numero})
exten => _744441100XX!,n,Set(caller_code=${CALLERID(num)})
exten => _744441100XX!,n,AGI(it_agi/out_call_log_insert.agi,,${UNIQUEID}--${CHANNEL}--${CUT(CHANNEL,/,1)}--${EXTEN}--${number_dialed}--${caller_code}--${EPOCH})
......
.....
exten => h,1,Set(tipo_chiam=InboundZoiper)
exten => h,n,AGI(agi://127.0.0.1:4577/call_log--HVcauses--PRI-----NODEBUG-----${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME}-----${HANGUPCAUSE(${HANGUPCAUSE_KEYS()},tech)})
..........
...........
yes please, a suggestion would be nice.If you want a clean and easy way of updating call_log number_dialed, you can edit Inbound and Outbound AGI and vdc_db_query.php for manuals if you are looking for a super small change. Something along the lines of regexing out outbound prefixes.
It's not dialplan level so the number_dialed will be overwritten but yeah I can provide an example of what I mean if you want
exten => h,1,AGI(agi://127.0.0.1:4577/call_log--HVcauses--PRI-----NODEBUG-----${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME}-----${HANGUPCAUSE(${HANGUPCAUSE_KEYS()},tech)})
; Bashas Awesome Hangup Handler
exten => h,2,AGI(bashas_awesome_hangup_handler_script_that_scrubs_prefixes_from_places.pl,param1-----param2-----etc)
exten => _7421[1-9]XX!,n,Set(number_dialed=${EXTEN:4})
exten => _7421[1-9]XX!,n,Set(number_dialed_call_log=${EXTEN})
The query I used are as follows,
########################### vicidial_log ###########################################
my $sthD = $dbhA->prepare( "select uniqueid ,
lead_id ,
campaign_id ,
call_date ,
length_in_sec ,
status ,
phone_number ,
user ,
user_group ,
term_reason
from vicidial_log
where phone_number = ?
order by insert_record_dt desc limit 1" );
$sthD->bind_param( 1, $number_dialed );
$sthD->execute();
my @row = $sthD->fetchrow_array();
my $vl_uniqueid = $row[0];
my $vl_lead_id = $row[1];
my $campaign_id = $row[2];
my $vl_call_date = $row[3];
my $vl_length_in_sec = $row[4];
my $status = $row[5];
my $phone_number = $row[6];
my $user = $row[7];
my $user_group = $row[8];
my $vl_term_reason = $row[9];
$sthD->finish();
my $vl_campaign_id = $campaign_id ;
my $vl_status = $status ;
my $vl_phone_number = $phone_number ;
my $vl_user = $user ;
my $vl_user_group = $user_group ;
########################### vicidial_log ###########################################
########################### call_log ###############################################
my $sthB = $dbhA->prepare( "select uniqueid ,
extension ,
number_dialed ,
caller_code ,
start_time ,
end_time ,
length_in_sec ,
start_epoch
from call_log
where number_dialed = ?
order by insert_record_dt desc limit 1" );
$sthB->bind_param( 1, $number_dialed_call_log );
$sthB->execute();
@row = $sthB->fetchrow_array();
my $cl_uniqueid = $row[0];
my $cl_extension = $row[1];
my $cl_number_dialed = $row[2];
my $cl_caller_code = $row[3];
my $start_time = $row[4];
my $cl_end_time = $row[5];
my $length_in_sec = $row[6];
my $start_epoch = $row[7];
$sthB->finish();
my $cl_start_time = $start_time ;
my $cl_length_in_sec = $length_in_sec ;
my $cl_start_epoch = $start_epoch ;
########################### call_log ###############################################
########################### get recording ########################################
my $sthC = $dbhA->prepare( "SELECT recording_id ,
start_time ,
end_time ,
length_in_sec ,
filename ,
location ,
lead_id ,
user ,
vicidial_id
FROM recording_log
WHERE filename like ?
ORDER BY recording_id desc LIMIT 1" );
$sthC->bind_param( 1, "$number_dialed%" );
$sthC->execute();
@row = $sthC->fetchrow_array();
$recording_id = $row[0];
$rl_start_time = $row[1];
$rl_end_time = $row[2];
$rl_length_in_sec = $row[3];
$filename = $row[4];
$rl_location = $row[5];
$rl_lead_id = $row[6];
$rl_user = $row[7];
$rl_vicidial_id = $row[8];
$sthC->finish();
my $rl_recording_id = $recording_id;
$rl_filename = $filename;
########################### get recording ########################################
vicidial_log --- KEY `phone_insdt` (`phone_number`,`insert_record_dt`)
call_log --- KEY `nr_ins_dt` (`number_dialed`,`insert_record_dt`)
recording_log --- KEY `filename` (`filename`)
Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 84 guests