From 05b15aadb92a7f61d2890d5fdfc2f45276f5ef8c Mon Sep 17 00:00:00 2001 From: jaywhy Date: Thu, 28 Sep 2006 01:58:05 +0000 Subject: [PATCH] Getting close to something that semi-works.. Which means in programmer talk, I'm not even close. git-svn-id: svn://192.168.202.10@310 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/branches/agc_30/lib/Astguiclient.pm | 9 +- .../branches/agc_30/lib/Astguiclient/AGI.pm | 109 +++++++++++------- .../agc_30/lib/Astguiclient/Campaign.pm | 9 +- .../agc_30/lib/Astguiclient/Campaign/Agent.pm | 10 +- .../agc_30/lib/Astguiclient/Daemon/AGI.pm | 2 +- .../branches/agc_30/lib/Astguiclient/VDAD.pm | 32 +++-- 6 files changed, 109 insertions(+), 62 deletions(-) diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient.pm b/agc_2-X/branches/agc_30/lib/Astguiclient.pm index 2028c789..0bbe0f17 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient.pm @@ -3,11 +3,13 @@ package Astguiclient; use strict; use DBI; -use Astguiclient::Config (); +use Astguiclient::Config; +use Astguiclient::Manager; +use Astguiclient::Campaign; use base 'Class::Accessor::Fast'; __PACKAGE__->mk_accessors( - qw( config dbi ) + qw( config dbi manager campaign ) ); =head1 NAME @@ -29,7 +31,8 @@ sub new { # Setup accessors; $self->config( Astguiclient::Config->new() ); - + $self->manager( Astguiclient::Manager->new() ); + $self->campaign( Astguiclient::Campaign->new() ); my $f = $self->config->file(); my $dsn = "DBI:mysql:datbase=$f->{'Database'}{'DB_name'};host=$f->{'Database'}{'Host'};port=$f->{'Database'}{'Port'}"; $self->dbi ( diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient/AGI.pm b/agc_2-X/branches/agc_30/lib/Astguiclient/AGI.pm index cc3b4a7a..9b2f7e64 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient/AGI.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient/AGI.pm @@ -2,9 +2,8 @@ package Astguiclient::AGI; use strict; use Time::HiRes qw( gettimeofday tv_interval usleep ); -use base qw/Astguiclient Class::Accessor::Fast/; +use base qw/Astguiclient/; -__PACKAGE__->mk_accessor(qw//); =head1 NAME @@ -32,23 +31,17 @@ sub call_log { my $dbh = $self->dbi; - if( $self->agi->{'extension'} =~ /h/i ) { - $dbh->do("UPDATE call_log SET end_time = NOW() WHERE uniqueid = ?", undef, $unique_id); - $dbh->do("DELETE FROM live_inbound WHERE uniqueid = ? AND server_ip = ?", undef, $unique_id, $self->file->{'server_ip'}); - - #NOTE: Not sure of the logic here. - #"UPDATE park_log set status='HUNGUP',hangup_time='$now_date',parked_sec='$parked_sec',talked_sec='$talked_sec' where uniqueid='$unique_id' and server_ip='$VARserver_ip'"; - #"SELECT UNIX_TIMESTAMP(parked_time),UNIX_TIMESTAMP(grab_time) FROM park_log where uniqueid='$unique_id' and server_ip='$VARserver_ip' LIMIT 1;"; - } else { - $dbh->do("INSERT INTO call_log - (uniqueid,channel,channel_group,type,server_ip,extension, - number_dialed,start_time,end_time,caller_code) - VALUES(?,?,?,?,?,?,?,?,'',?)", - undef, - $unique_id,$channel,$channel_group,$type,$VARserver_ip, - $extension,$number_dialed,$now_date,$now_date_epoch,$callerid - ); - } +# if( $self->agi->{'extension'} =~ /h/i ) { +# $dbh->do("UPDATE call_log SET end_time = NOW() WHERE uniqueid = ?", undef, $unique_id); +# } else { +# $dbh->do("INSERT INTO call_log +# SET uniqueid = ?, channel = ?, channel_group = ?, type = ?, server_ip = ?, +# extension = ?, number_dialed = ?,start_time = ?, end_time = ?, caller_code = ?" +# undef, +# $unique_id,$channel,$channel_group,$type,$VARserver_ip, +# $extension,$number_dialed,$now_date,$now_date_epoch,$callerid +# ); +# } } =head2 vdad_transfer @@ -76,74 +69,102 @@ Send the calls out to the reps that are logged in. sub vdad_transfer { my $self = shift; - my %campaign = $self->campaign($campaign_id); + # Caller id houses the leadid and campaignid, sent by place_call() + my($lead_id, $campaign_id) = split(/:/, $self->agi->{callerid}); + + my $campaign = $self->campaign->find( id => $campaign_id ); # When a call is answered, this timer begins. my $drop_start_timer; # Time for the start of the loop - my $start_time = [gettimeofday] + my $start_timer = [gettimeofday]; # Amount of time you should wait for answer before hanging up(how many rings essentially) - my $call_wait_time = '30' + my $call_wait_time = '30'; - TRANSFER: while( tv_interval( $start_time, [gettimeofday] ) > $call_wait_time ) { + TRANSFER: while( tv_interval( $start_timer, [gettimeofday] ) > $call_wait_time ) { my $status = $self->agi->check_status(); # Line is down or busy. if( ( $status < 3 ) || ( $status == 7 ) ) { - $self->_log_call( $status ); - last; + last TRANSFER; } elsif( $status == 6 ) { # Line is answered - $start_timer = [gettimeofday]; + $drop_start_timer = [gettimeofday]; } - $self->_transfer_to_agent(); + $self->_transfer_to_agent( $campaign ); - if( tv_interval( $start_timer, [gettimeofday] ) { - $self->_send_to_voicemail(); + if( tv_interval( $drop_start_timer, [gettimeofday] ) ) { + $self->_send_to_voicemail( $campaign ); last; } + + usleep(1*990*1000); } - $self->_log_call( $call_status ); +#XXX $self->_log_call( $call_status ); } sub _log_call { my($self, $call_status) = @_; - if( lc($call_status) eq 'drop' ) { - $self->dbh->do("DELETE FROM vicidial_auto_calls where callerid = ?", undef, $callerid); - } +#XXX +# if( lc($call_status) eq 'drop' ) { +# $self->dbh->do("DELETE FROM vicidial_auto_calls where callerid = ?", undef, $callerid); +# } - $self->dbh->do("UPDATE vicidial_log set status = ?,end_time = NOW() WHERE uniqueid = ?", undef, $status, $unique_id); - $self->dbh->do("UPDATE vicidial_list set status='DROP' where lead_id = '$CIDlead_id'"); +# $self->dbh->do("UPDATE vicidial_log set status = ?,end_time = NOW() WHERE uniqueid = ?", undef, $status, $unique_id); +# $self->dbh->do("UPDATE vicidial_list set status='DROP' where lead_id = '$CIDlead_id'"); } +=head2 _send_to_voicemail + +Transfer a call to voicemail of the campaign. + +=cut + sub _send_to_voicemail { - my $self = shift; + my( $self, $campaign ) = @_; - $self->agi->set_context( $ext_context ); - $self->agi->set_extension( $drop_exten ); + $self->_transfer( $campaign->{voicemail_ext} ); } +=head2 _transfer + +Transfers a call. + +=cut + +sub _transfer { + my( $self, $ext ) = @_; + + $self->agi->set_context( 'default' ); + $self->agi->set_extension( $ext ); +} + +=head2 _transfer_to_agent + +Transfer the call to an available agent. + +=cut + sub _transfer_to_agent { - my $self = shift; + my( $self, $campaign ) = @_; my($conf_exten, $user, $extension) = $self->dbi->selectrow_arary(" SELECT conf_exten,extension FROM vicidial_live_agents - WHERE status = 'QUEUE' and server_ip = ? and campaign_id = ? and callerid = ? and channel= ? + WHERE status = 'QUEUE' and server_ip = ? and campaign_id = ? ORDER BY last_call_time limit 1", undef, - #XXX + $self->config->server->server_ip, $campaign->{campaign_id}, ); - $self->agi->set_context( $ext_context ); - $self->agi->set_extension( $drop_exten ); + $self->_transfer( $extension ); - $dbh->do("UPDATE vicidial_auto_calls set status='XFER' WHERE callerid = ?", undef, $callerid); + #XXX$self->dbh->do("UPDATE vicidial_auto_calls set status='XFER' WHERE callerid = ?", undef, $callerid); } diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign.pm b/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign.pm index 39d6a56b..16352e40 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign.pm @@ -1,6 +1,12 @@ package Astguiclient::Campaign; use strict; +use Astguiclient::Campaign::Record; + +#NOTE: I'm really unsure where to put this. I guess this will work. +#NOTE: What do these all mean should document them all here. I'm +#NOTE: even really unsure. +our $ACTIVE_AGENTS = "'LIVE','XFER','SENT','RINGING'"; =head1 name @@ -70,6 +76,7 @@ sub find { my $sth = $self->dbi->prepare( $sql ); $sth->execute(); + my(@records); while( my $ref = $sth->fetchrow_hashref() ) { push( @records, Astguiclient::Campaign::Record->new( $ref ) ); } @@ -90,7 +97,7 @@ sub hopper { my $sth = $self->dbi->prepare("SELECT vicidial_list.lead_id, vicidial_list.phone_code, vicidial_list.phone_number FROM vicidial_list INNER JOIN vicidial_lists ON vicidial_list.list_id = vicidial_lists.list_id WHERE vicidial_lists.campaign_id = ? AND vicidial_list.called_since_last_reset = 'N' - ORDER by lead_id asc LIMIT $count") + ORDER by lead_id asc LIMIT $count"); $sth->execute( $self->{campaign_id} ); my(@hopper); while( my $ref = $sth->fetchrow_array() ) { diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign/Agent.pm b/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign/Agent.pm index a37347bc..21020510 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign/Agent.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient/Campaign/Agent.pm @@ -3,7 +3,7 @@ package Astguiclient::Campaign::Agent; use strict; use base qw(Class::Accessor::Fast); -__PACKAGE__->mk_accessor( qw/ active total list / ); +__PACKAGE__->mk_accessors( qw/ active total list / ); =head1 name @@ -18,9 +18,7 @@ Astguiclient::Campaign::Agent - . sub new { my $class = shift; my %args = @_; - my $self = bless \%args, $class; - $self->load() return $self; } @@ -68,7 +66,7 @@ sub find { } } my $sth = Astguiclient->dbi->prepare(); - $sth->execute( @bind_params ) + $sth->execute( @bind_params ); my @records; while( my $ref = $sth->fetchrow_hashref() ) { push( @records, $ref ); @@ -90,12 +88,12 @@ sub active { if( !wantarray ) { # Return a count of the live agents. return Astguiclient->dbi->selectrow_array("SELECT count(*) FROM vicidial_live_agents - WHERE campaign_id = ? STATUS IN ( $ACTIVE_STATUS )", + WHERE campaign_id = ? STATUS IN ( $Astguiclient::ACTIVE_AGENTS )", undef, $self->{id} ); } else { - $self->find( conditions => "STATUS in ( $ACTIVE_STATUS )" ); + $self->find( conditions => "STATUS in ( $Astguiclient::ACTIVE_AGENTS )" ); } } diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient/Daemon/AGI.pm b/agc_2-X/branches/agc_30/lib/Astguiclient/Daemon/AGI.pm index df0927a1..9ce4fa70 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient/Daemon/AGI.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient/Daemon/AGI.pm @@ -1,4 +1,4 @@ -package Astguiclient::Server; +package Astguiclient::Daemon::AGI; use strict; use vars qw(@ISA); diff --git a/agc_2-X/branches/agc_30/lib/Astguiclient/VDAD.pm b/agc_2-X/branches/agc_30/lib/Astguiclient/VDAD.pm index 04b6bf71..6582b24f 100644 --- a/agc_2-X/branches/agc_30/lib/Astguiclient/VDAD.pm +++ b/agc_2-X/branches/agc_30/lib/Astguiclient/VDAD.pm @@ -3,11 +3,9 @@ package Astguiclient::VDAD; use strict; use base qw/Astguiclient Class::Accessor::Fast/; -__PACKAGE__->mk_accessor(qw//); - =head1 NAME -Astguiclient::VDAD - . +Astguiclient::VDAD - Vicidial module =head1 DESCRIPTION @@ -26,6 +24,10 @@ sub new { =cut +=head2 auto_dial + +=cut + sub auto_dial { my $self = shift; @@ -33,10 +35,7 @@ sub auto_dial { my @campaigns = $self->campaign->find('active_agents'); foreach my $campaign (@campaigns) { - # Find the number of calls to place for this campaign. - my $num_calls = $campaign->agent->idle() * $campaign->{auto_dial_level}; - - $self->place_calls( $campaign->{campaign_id} ); + $self->place_calls( $campaign ); } } @@ -48,7 +47,26 @@ Place calls. sub place_calls { my $self = shift; + my $campaign = shift; + # Find the number of calls to place for this campaign. + my $num_calls = $campaign->agent->idle() * $campaign->{auto_dial_level}; + + # Load a list of numbers up for this campaign. + my @list = $campaign->hopper( $num_calls ); + + foreach my $item (@list) { + $self->manager->sendcommand( + 'Channel' => $item->{dial_string}, + 'Context' => 'default', #NOTE: Should we get this from servers? Why not just have a default context? + 'Exten' => $campaign->{campaign_vdad_exten}, + 'Timeout' => '30', #NOTE: Get from somewhere else. + 'Action' => 'Originate', + 'Callerid' => "$item->{lead_id}:$campaign->{campaign_id}", + 'Priority' => '1', + ); + + } } =head1 AUTHOR