Created new function to connect calls and modify some small changes
Showing
1 changed file
with
92 additions
and
105 deletions
| ... | @@ -1473,10 +1473,9 @@ class KPAMIListen implements IEventListener | ... | @@ -1473,10 +1473,9 @@ class KPAMIListen implements IEventListener |
| 1473 | 1473 | ||
| 1474 | if($crmcall) | 1474 | if($crmcall) |
| 1475 | { | 1475 | { |
| 1476 | $nowts=microtime(true)*1000; | ||
| 1477 | $crmcalldata=json_decode($crmcall->data,true); | 1476 | $crmcalldata=json_decode($crmcall->data,true); |
| 1478 | if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0; | 1477 | if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0; |
| 1479 | 1478 | ||
| 1480 | $sipids=array(); | 1479 | $sipids=array(); |
| 1481 | 1480 | ||
| 1482 | $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("ready","=","1")->where("prepare_call","=","1")->orderBy("updated_at","desc")->get(); | 1481 | $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 | ... | @@ -1485,127 +1484,115 @@ class KPAMIListen implements IEventListener |
| 1485 | { | 1484 | { |
| 1486 | echo "sipids found "; | 1485 | echo "sipids found "; |
| 1487 | 1486 | ||
| 1488 | $first_r=0;$first_w=0;$first_a=0;$allsipids=array(); | ||
| 1489 | |||
| 1490 | foreach($sipids as $sipid) | 1487 | foreach($sipids as $sipid) |
| 1491 | { | 1488 | { |
| 1492 | $clientsarr=json_decode($sipid->clients,true); | 1489 | $this->connectToAvailableSip($sipid, $dialline, $crmcall); |
| 1493 | if($crmcall->client=="")$first_a=$sipid; | ||
| 1494 | else | ||
| 1495 | { | ||
| 1496 | if($clientsarr['a']!="")$clientaarr = explode(",", $clientsarr['a']); | ||
| 1497 | if(isset($clientsarr['a'])&&in_array($crmcall->client, $clientaarr))$first_a=$sipid; | ||
| 1498 | if($clientsarr['w']!="")$clientwarr = explode(",", $clientsarr['w']); | ||
| 1499 | if(isset($clientsarr['w'])&&in_array($crmcall->client, $clientwarr))$first_w=$sipid; | ||
| 1500 | if($clientsarr['r']!="")$clientrarr = explode(",", $clientsarr['r']); | ||
| 1501 | if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid; | ||
| 1502 | } | ||
| 1503 | } | ||
| 1504 | |||
| 1505 | echo "Notifying Total ::".sizeof($allsipids)."\n"; | ||
| 1506 | |||
| 1507 | $found=false; | ||
| 1508 | if($first_a)$found=$first_a; | ||
| 1509 | else if($first_w)$found=$first_w; | ||
| 1510 | else if($first_r)$found=$first_r; | ||
| 1511 | |||
| 1512 | if($found) | ||
| 1513 | { | ||
| 1514 | $alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","1000".$found->id)->get(); | ||
| 1515 | if(sizeof($alreadyconf)>0) | ||
| 1516 | { | ||
| 1517 | echo $found->id." : Found but Already in Conf!!!\n"; | ||
| 1518 | $found=false; | ||
| 1519 | } | ||
| 1520 | } | 1490 | } |
| 1521 | 1491 | } | |
| 1522 | if($found) | 1492 | } |
| 1523 | { | 1493 | } |
| 1524 | echo "sipids : $found->id \n"; | 1494 | } |
| 1525 | 1495 | } | |
| 1526 | $userEntry = User::find($found->user); | ||
| 1527 | |||
| 1528 | if(!empty($userEntry)){ | ||
| 1529 | if($userEntry->current_dialmode != "Predictive" || $found->ready != 1 || $dialline->regexstr != $userEntry->sel_campaign) return; | ||
| 1530 | } | ||
| 1531 | 1496 | ||
| 1532 | exec("/usr/sbin/asterisk -rx 'core show channel $dialline->channel'",$channelArr); | 1497 | private function connectToAvailableSip($sipid, $dialline, $crmcall) |
| 1498 | { | ||
| 1499 | $nowts=microtime(true)*1000; | ||
| 1500 | $found=$sipid; | ||
| 1533 | 1501 | ||
| 1534 | if(count($channelArr) == 1) | 1502 | if($found) |
| 1535 | { | 1503 | { |
| 1536 | Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log"); | 1504 | $alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","1000".$found->id)->get(); |
| 1537 | Log::info($crmcall->id);Log::info($dialline); | 1505 | if(sizeof($alreadyconf)>0) |
| 1506 | { | ||
| 1507 | echo $found->id." : Found but Already in Conf!!!\n"; | ||
| 1508 | $found=false; | ||
| 1509 | } | ||
| 1510 | } | ||
| 1538 | 1511 | ||
| 1539 | $dialline->status="Free"; | 1512 | if($found) |
| 1540 | $dialline->conf=""; | 1513 | { |
| 1541 | $dialline->number=""; | 1514 | echo "sipids : $found->id \n"; |
| 1542 | $dialline->uniqueid=""; | ||
| 1543 | $dialline->src_channel=""; | ||
| 1544 | $dialline->channel=""; | ||
| 1545 | $dialline->regexstr=""; | ||
| 1546 | $dialline->save(); | ||
| 1547 | 1515 | ||
| 1548 | continue; | 1516 | $userEntry = User::find($found->user); |
| 1549 | } | ||
| 1550 | 1517 | ||
| 1551 | $recfile=$crmcall->newRecFilePath(); | 1518 | if(!empty($userEntry)){ |
| 1519 | if($userEntry->current_dialmode != "Predictive" || $found->ready != 1) return; | ||
| 1520 | } | ||
| 1552 | 1521 | ||
| 1553 | //start recording | 1522 | exec("/usr/sbin/asterisk -rx 'core show channel $dialline->channel'",$channelArr); |
| 1554 | $newqueue=new Kqueue(); | ||
| 1555 | $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile); | ||
| 1556 | 1523 | ||
| 1557 | $newqueue=new Kqueue(); | 1524 | if(count($channelArr) == 1) |
| 1558 | $newqueue->userToConf($found); | 1525 | { |
| 1526 | Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log"); | ||
| 1527 | Log::info($crmcall->id);Log::info($dialline); | ||
| 1559 | 1528 | ||
| 1560 | $newqueue=new Kqueue(); | 1529 | $dialline->status="Free"; |
| 1561 | $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1"); | 1530 | $dialline->conf=""; |
| 1531 | $dialline->number=""; | ||
| 1532 | $dialline->uniqueid=""; | ||
| 1533 | $dialline->src_channel=""; | ||
| 1534 | $dialline->channel=""; | ||
| 1535 | $dialline->regexstr=""; | ||
| 1536 | $dialline->save(); | ||
| 1562 | 1537 | ||
| 1563 | $dialline->user_id = $found->user; | 1538 | continue; |
| 1564 | $dialline->conf = "1000".$found->id; | 1539 | } |
| 1565 | $dialline->save(); | ||
| 1566 | 1540 | ||
| 1567 | $found->ready=0; | 1541 | $recfile=$crmcall->newRecFilePath(); |
| 1568 | $found->prepare_call=0; | ||
| 1569 | $found->patched=1; | ||
| 1570 | $found->save(); | ||
| 1571 | 1542 | ||
| 1572 | $userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first(); | 1543 | //start recording |
| 1573 | $ts_Wait=$userlog->getLastTs($found->id,$nowts); | 1544 | $newqueue=new Kqueue(); |
| 1574 | $userlog->save(); | 1545 | $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile); |
| 1575 | |||
| 1576 | $crmcall->user_id=$found->user; | ||
| 1577 | $crmcall->sipid_id=$found->id; | ||
| 1578 | |||
| 1579 | if($ts_Wait<=$crmcall->ts_Wait) //user waiting | ||
| 1580 | { | ||
| 1581 | $crmcall->ts_Wait=$ts_Wait; | ||
| 1582 | $crmcall->setTs('ts_Talk',$nowts); | ||
| 1583 | } | ||
| 1584 | else //call waiting | ||
| 1585 | { | ||
| 1586 | $crmcall->ts_Wait-=($nowts-$ts_Wait); | ||
| 1587 | $crmcall->setTs('ts_Talk',$nowts); | ||
| 1588 | } | ||
| 1589 | 1546 | ||
| 1590 | $crmcall->save(); | 1547 | $newqueue=new Kqueue(); |
| 1591 | 1548 | $newqueue->userToConf($found); | |
| 1592 | 1549 | ||
| 1593 | if($crmcall->crm_id>0){ | 1550 | $newqueue=new Kqueue(); |
| 1594 | DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]); | 1551 | $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1"); |
| 1595 | 1552 | ||
| 1596 | } | 1553 | $dialline->user_id = $found->user; |
| 1597 | 1554 | $dialline->conf = "1000".$found->id; | |
| 1598 | $crmcall->setTs('ts_Recstart',$nowts); | 1555 | $dialline->save(); |
| 1599 | $crmcall->save(); | 1556 | |
| 1600 | 1557 | $found->ready=0; | |
| 1601 | $newqueue=new Kqueue(); | 1558 | $found->prepare_call=0; |
| 1602 | $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel); | 1559 | $found->patched=1; |
| 1603 | } | 1560 | $found->save(); |
| 1604 | } | 1561 | |
| 1605 | } | 1562 | $userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first(); |
| 1606 | } | 1563 | $ts_Wait=$userlog->getLastTs($found->id,$nowts); |
| 1564 | $userlog->save(); | ||
| 1565 | |||
| 1566 | $crmcall->user_id=$found->user; | ||
| 1567 | $crmcall->sipid_id=$found->id; | ||
| 1568 | |||
| 1569 | if($ts_Wait<=$crmcall->ts_Wait) //user waiting | ||
| 1570 | { | ||
| 1571 | $crmcall->ts_Wait=$ts_Wait; | ||
| 1572 | $crmcall->setTs('ts_Talk',$nowts); | ||
| 1573 | } | ||
| 1574 | else //call waiting | ||
| 1575 | { | ||
| 1576 | $crmcall->ts_Wait-=($nowts-$ts_Wait); | ||
| 1577 | $crmcall->setTs('ts_Talk',$nowts); | ||
| 1607 | } | 1578 | } |
| 1579 | |||
| 1580 | $crmcall->save(); | ||
| 1581 | |||
| 1582 | |||
| 1583 | if($crmcall->crm_id>0){ | ||
| 1584 | DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]); | ||
| 1585 | |||
| 1586 | } | ||
| 1587 | |||
| 1588 | $crmcall->setTs('ts_Recstart',$nowts); | ||
| 1589 | $crmcall->save(); | ||
| 1590 | |||
| 1591 | $newqueue=new Kqueue(); | ||
| 1592 | $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel); | ||
| 1608 | } | 1593 | } |
| 1594 | |||
| 1595 | } | ||
| 1609 | 1596 | ||
| 1610 | // private function redirectIncoming() | 1597 | // private function redirectIncoming() |
| 1611 | // { | 1598 | // { | ... | ... |
-
Please register or sign in to post a comment