0fa8f57b by Manish Mihsra

Created new function to connect calls and modify some small changes

1 parent 3bb592c9
......@@ -1473,10 +1473,9 @@ class KPAMIListen implements IEventListener
if($crmcall)
{
$nowts=microtime(true)*1000;
$crmcalldata=json_decode($crmcall->data,true);
if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0;
$sipids=array();
$sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("ready","=","1")->where("prepare_call","=","1")->orderBy("updated_at","desc")->get();
......@@ -1485,127 +1484,115 @@ class KPAMIListen implements IEventListener
{
echo "sipids found ";
$first_r=0;$first_w=0;$first_a=0;$allsipids=array();
foreach($sipids as $sipid)
{
$clientsarr=json_decode($sipid->clients,true);
if($crmcall->client=="")$first_a=$sipid;
else
{
if($clientsarr['a']!="")$clientaarr = explode(",", $clientsarr['a']);
if(isset($clientsarr['a'])&&in_array($crmcall->client, $clientaarr))$first_a=$sipid;
if($clientsarr['w']!="")$clientwarr = explode(",", $clientsarr['w']);
if(isset($clientsarr['w'])&&in_array($crmcall->client, $clientwarr))$first_w=$sipid;
if($clientsarr['r']!="")$clientrarr = explode(",", $clientsarr['r']);
if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid;
}
}
echo "Notifying Total ::".sizeof($allsipids)."\n";
$found=false;
if($first_a)$found=$first_a;
else if($first_w)$found=$first_w;
else if($first_r)$found=$first_r;
if($found)
{
$alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","1000".$found->id)->get();
if(sizeof($alreadyconf)>0)
{
echo $found->id." : Found but Already in Conf!!!\n";
$found=false;
}
$this->connectToAvailableSip($sipid, $dialline, $crmcall);
}
if($found)
{
echo "sipids : $found->id \n";
$userEntry = User::find($found->user);
if(!empty($userEntry)){
if($userEntry->current_dialmode != "Predictive" || $found->ready != 1 || $dialline->regexstr != $userEntry->sel_campaign) return;
}
}
}
}
}
}
exec("/usr/sbin/asterisk -rx 'core show channel $dialline->channel'",$channelArr);
private function connectToAvailableSip($sipid, $dialline, $crmcall)
{
$nowts=microtime(true)*1000;
$found=$sipid;
if(count($channelArr) == 1)
{
Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
Log::info($crmcall->id);Log::info($dialline);
if($found)
{
$alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","1000".$found->id)->get();
if(sizeof($alreadyconf)>0)
{
echo $found->id." : Found but Already in Conf!!!\n";
$found=false;
}
}
$dialline->status="Free";
$dialline->conf="";
$dialline->number="";
$dialline->uniqueid="";
$dialline->src_channel="";
$dialline->channel="";
$dialline->regexstr="";
$dialline->save();
if($found)
{
echo "sipids : $found->id \n";
continue;
}
$userEntry = User::find($found->user);
$recfile=$crmcall->newRecFilePath();
if(!empty($userEntry)){
if($userEntry->current_dialmode != "Predictive" || $found->ready != 1) return;
}
//start recording
$newqueue=new Kqueue();
$newqueue->recordChannel($dialline->server,$dialline->channel,$recfile);
exec("/usr/sbin/asterisk -rx 'core show channel $dialline->channel'",$channelArr);
$newqueue=new Kqueue();
$newqueue->userToConf($found);
if(count($channelArr) == 1)
{
Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
Log::info($crmcall->id);Log::info($dialline);
$newqueue=new Kqueue();
$newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1");
$dialline->status="Free";
$dialline->conf="";
$dialline->number="";
$dialline->uniqueid="";
$dialline->src_channel="";
$dialline->channel="";
$dialline->regexstr="";
$dialline->save();
$dialline->user_id = $found->user;
$dialline->conf = "1000".$found->id;
$dialline->save();
continue;
}
$found->ready=0;
$found->prepare_call=0;
$found->patched=1;
$found->save();
$recfile=$crmcall->newRecFilePath();
$userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first();
$ts_Wait=$userlog->getLastTs($found->id,$nowts);
$userlog->save();
$crmcall->user_id=$found->user;
$crmcall->sipid_id=$found->id;
if($ts_Wait<=$crmcall->ts_Wait) //user waiting
{
$crmcall->ts_Wait=$ts_Wait;
$crmcall->setTs('ts_Talk',$nowts);
}
else //call waiting
{
$crmcall->ts_Wait-=($nowts-$ts_Wait);
$crmcall->setTs('ts_Talk',$nowts);
}
//start recording
$newqueue=new Kqueue();
$newqueue->recordChannel($dialline->server,$dialline->channel,$recfile);
$crmcall->save();
$newqueue=new Kqueue();
$newqueue->userToConf($found);
if($crmcall->crm_id>0){
DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]);
}
$crmcall->setTs('ts_Recstart',$nowts);
$crmcall->save();
$newqueue=new Kqueue();
$newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel);
}
}
}
}
$newqueue=new Kqueue();
$newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1");
$dialline->user_id = $found->user;
$dialline->conf = "1000".$found->id;
$dialline->save();
$found->ready=0;
$found->prepare_call=0;
$found->patched=1;
$found->save();
$userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first();
$ts_Wait=$userlog->getLastTs($found->id,$nowts);
$userlog->save();
$crmcall->user_id=$found->user;
$crmcall->sipid_id=$found->id;
if($ts_Wait<=$crmcall->ts_Wait) //user waiting
{
$crmcall->ts_Wait=$ts_Wait;
$crmcall->setTs('ts_Talk',$nowts);
}
else //call waiting
{
$crmcall->ts_Wait-=($nowts-$ts_Wait);
$crmcall->setTs('ts_Talk',$nowts);
}
$crmcall->save();
if($crmcall->crm_id>0){
DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]);
}
$crmcall->setTs('ts_Recstart',$nowts);
$crmcall->save();
$newqueue=new Kqueue();
$newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel);
}
}
// private function redirectIncoming()
// {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!