5ee2c380 by Manish Mihsra

Added new code for Incoming pop alert and registering campaign when inbound call comes up

1 parent c286f211
...@@ -277,7 +277,6 @@ class KPAMIListen implements IEventListener ...@@ -277,7 +277,6 @@ class KPAMIListen implements IEventListener
277 $dialline=Dialline::where('server','=',$this->sipip)->where("dialstr","=",env("sip_dialstr"))->where("status","=","Free")->first(); 277 $dialline=Dialline::where('server','=',$this->sipip)->where("dialstr","=",env("sip_dialstr"))->where("status","=","Free")->first();
278 if($dialline) 278 if($dialline)
279 { 279 {
280
281 $nowts=microtime(true)*1000; 280 $nowts=microtime(true)*1000;
282 281
283 //start the call log 282 //start the call log
...@@ -288,9 +287,7 @@ class KPAMIListen implements IEventListener ...@@ -288,9 +287,7 @@ class KPAMIListen implements IEventListener
288 287
289 $crmcall->did=$exten; 288 $crmcall->did=$exten;
290 289
291 $crmcall->crm_id=0; 290 $this->checkMobileNumberExist($crmcall);
292 $crmcall->client=".";
293 $crmcall->department="";
294 291
295 $crmcall->state='Inbound'; 292 $crmcall->state='Inbound';
296 $crmcall->type="Inbound"; 293 $crmcall->type="Inbound";
...@@ -299,6 +296,7 @@ class KPAMIListen implements IEventListener ...@@ -299,6 +296,7 @@ class KPAMIListen implements IEventListener
299 $crmcall->dialline_id=$dialline->id; 296 $crmcall->dialline_id=$dialline->id;
300 297
301 $crmcall->setTs('ts_Wait',$nowts); 298 $crmcall->setTs('ts_Wait',$nowts);
299 $crmcall->setTs('ts_cTalk',$nowts);
302 300
303 $crmcall->group=$dialline->group; 301 $crmcall->group=$dialline->group;
304 302
...@@ -313,7 +311,9 @@ class KPAMIListen implements IEventListener ...@@ -313,7 +311,9 @@ class KPAMIListen implements IEventListener
313 $dialline->status='Inbound'; 311 $dialline->status='Inbound';
314 $dialline->uniqueid=$uniqueid; 312 $dialline->uniqueid=$uniqueid;
315 $dialline->number=$phonenumber; 313 $dialline->number=$phonenumber;
314 $dialline->src_channel=$channel;
316 $dialline->channel=$channel; 315 $dialline->channel=$channel;
316 $dialline->regexstr=$crmcall->client;
317 $dialline->save(); 317 $dialline->save();
318 318
319 /*$userStatus=User::where("updated_at",">",date("Y-m-d"))->where("exten","like","%".substr($exten,-4)."%")->where("usertype","!=","Admin")->where('presence', '=', '1')->select('*')->get(); 319 /*$userStatus=User::where("updated_at",">",date("Y-m-d"))->where("exten","like","%".substr($exten,-4)."%")->where("usertype","!=","Admin")->where('presence', '=', '1')->select('*')->get();
...@@ -687,11 +687,15 @@ class KPAMIListen implements IEventListener ...@@ -687,11 +687,15 @@ class KPAMIListen implements IEventListener
687 $dialline=Dialline::find($crmcall->dialline_id); 687 $dialline=Dialline::find($crmcall->dialline_id);
688 if($dialline) 688 if($dialline)
689 { 689 {
690 $dialline->call_id=0;
691 $dialline->user_id=0;
690 $dialline->status="Free"; 692 $dialline->status="Free";
691 $dialline->conf=""; 693 $dialline->conf="";
692 $dialline->number=""; 694 $dialline->number="";
693 $dialline->uniqueid=""; 695 $dialline->uniqueid="";
696 $dialline->src_channel="";
694 $dialline->channel=""; 697 $dialline->channel="";
698 $dialline->did="";
695 $dialline->save(); 699 $dialline->save();
696 } 700 }
697 701
...@@ -1176,7 +1180,6 @@ class KPAMIListen implements IEventListener ...@@ -1176,7 +1180,6 @@ class KPAMIListen implements IEventListener
1176 1180
1177 $crmcall->addEventLog($nowts,"$accountcode:$accountcodearr[1] : $eventname $dchannelstate:$dchannelstatedesc $duniqueid $dexten:$dpriority $dchannel $dialstatus"); 1181 $crmcall->addEventLog($nowts,"$accountcode:$accountcodearr[1] : $eventname $dchannelstate:$dchannelstatedesc $duniqueid $dexten:$dpriority $dchannel $dialstatus");
1178 1182
1179
1180 $crmcall->save(); 1183 $crmcall->save();
1181 } 1184 }
1182 1185
...@@ -1445,6 +1448,7 @@ class KPAMIListen implements IEventListener ...@@ -1445,6 +1448,7 @@ class KPAMIListen implements IEventListener
1445 //TODO: Need to create static values for modes 1448 //TODO: Need to create static values for modes
1446 $status = array('Auto', 'Inbound'); //NOTE: Be Careful before changing indexes 1449 $status = array('Auto', 'Inbound'); //NOTE: Be Careful before changing indexes
1447 $mode = ""; 1450 $mode = "";
1451 $campaignUserIds = [];
1448 1452
1449 $diallines=Dialline::where('server','=',$this->sipip)->whereIn("status", $status)->where("conf","=","")->get(); 1453 $diallines=Dialline::where('server','=',$this->sipip)->whereIn("status", $status)->where("conf","=","")->get();
1450 if($diallines) 1454 if($diallines)
...@@ -1464,9 +1468,7 @@ class KPAMIListen implements IEventListener ...@@ -1464,9 +1468,7 @@ class KPAMIListen implements IEventListener
1464 { 1468 {
1465 $mode = "Predictive"; 1469 $mode = "Predictive";
1466 1470
1467 $campaignUserIds = User::where('presence', '=', "1") 1471 $campaignUserIds = $this->getUsersAvailableInCampaign($dialline->regexstr);
1468 ->where('sel_campaign', '=', $dialline->regexstr)
1469 ->select('id')->get()->toArray();
1470 1472
1471 $sipid=Sipid::where('server', '=', $this->sipip) 1473 $sipid=Sipid::where('server', '=', $this->sipip)
1472 ->whereIn("user", $campaignUserIds) 1474 ->whereIn("user", $campaignUserIds)
...@@ -1480,14 +1482,7 @@ class KPAMIListen implements IEventListener ...@@ -1480,14 +1482,7 @@ class KPAMIListen implements IEventListener
1480 { 1482 {
1481 $mode = "Incoming"; 1483 $mode = "Incoming";
1482 1484
1483 $this->checkMobileNumberExist($crmcall); 1485 $sipid = $this->getSipid($dialline->regexstr);
1484
1485 $sipid=Sipid::where('server', '=', $this->sipip)
1486 ->where("user", "!=", "0")
1487 ->where("status", "=", "1")
1488 ->where("ready", "=", "1")
1489 ->orderBy("updated_at", "ssc")
1490 ->first();
1491 } 1486 }
1492 1487
1493 if(!empty($sipid)) 1488 if(!empty($sipid))
...@@ -1498,17 +1493,94 @@ class KPAMIListen implements IEventListener ...@@ -1498,17 +1493,94 @@ class KPAMIListen implements IEventListener
1498 } 1493 }
1499 else if($mode == "Incoming") 1494 else if($mode == "Incoming")
1500 { 1495 {
1496 $this->showIncomingPopupAlert($dialline->regexstr, $crmcall);
1497 }
1498 }
1499 }
1500 }
1501 }
1502
1503 private function showIncomingPopupAlert($client, $crmcall)
1504 {
1505 $flag = "alert";
1506
1507 $sipids = $this->getSipid($client, $flag);
1508
1509 foreach($sipids as $sipid)
1510 {
1501 $newqueue=new Kqueue(); 1511 $newqueue=new Kqueue();
1502 $newqueue->sipNotify($sipid,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,$crmcall->did); 1512 $newqueue->sipNotify($sipid,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,$crmcall->did);
1503 } 1513 }
1504 } 1514 }
1515
1516 private function getSipid($client, $flag=null)
1517 {
1518 $data = [];
1519 $campaignUserIds = [];
1520
1521 if($client!="")$campaignUserIds = $this->getUsersAvailableInCampaign($client);
1522
1523 if($flag == null)
1524 {
1525 if(!empty($campaignUserIds))
1526 {
1527 $sipid=Sipid::where('server', '=', $this->sipip)
1528 ->whereIn("user", $campaignUserIds)
1529 ->where("status", "=", "1")
1530 ->where("ready", "=", "1")
1531 ->orderBy("updated_at", "asc")
1532 ->first();
1533 }
1534 else
1535 {
1536 $sipid=Sipid::where('server', '=', $this->sipip)
1537 ->where("user", "!=", "0")
1538 ->where("status", "=", "1")
1539 ->where("ready", "=", "1")
1540 ->orderBy("updated_at", "asc")
1541 ->first();
1542 }
1543
1544 $data = $sipid;
1545 }
1546 else
1547 {
1548 if(!empty($campaignUserIds))
1549 {
1550 $sipids=Sipid::where('server', '=', $this->sipip)
1551 ->whereIn("user", $campaignUserIds)
1552 ->where("status", "=", "1")
1553 ->orderBy("updated_at", "asc")
1554 ->get();
1555 }
1556 else
1557 {
1558 $sipids=Sipid::where('server', '=', $this->sipip)
1559 ->where("user", "!=", "0")
1560 ->where("status", "=", "1")
1561 ->orderBy("updated_at", "asc")
1562 ->get();
1505 } 1563 }
1564
1565 $data = $sipids;
1506 } 1566 }
1567
1568 return $data;
1507 } 1569 }
1508 1570
1509 private function checkMobileNumberExist($crmcall) 1571 private function getUsersAvailableInCampaign($client)
1510 { 1572 {
1511 if($crmcall->client==".") 1573 $data = [];
1574
1575 $data = User::where('presence', '=', "1")
1576 ->where('sel_campaign', '=', $client)
1577 ->select('id')->get()
1578 ->toArray();
1579
1580 return $data;
1581 }
1582
1583 private function checkMobileNumberExist($crmcall)
1512 { 1584 {
1513 $wakka = new KHRMSLib(); 1585 $wakka = new KHRMSLib();
1514 $users=$wakka->searchPhone("mobile", $crmcall->number, ""); 1586 $users=$wakka->searchPhone("mobile", $crmcall->number, "");
...@@ -1536,7 +1608,6 @@ class KPAMIListen implements IEventListener ...@@ -1536,7 +1608,6 @@ class KPAMIListen implements IEventListener
1536 1608
1537 return; 1609 return;
1538 } 1610 }
1539 }
1540 1611
1541 private function connectToAvailableSip($sipid, $dialline, $crmcall, $mode) 1612 private function connectToAvailableSip($sipid, $dialline, $crmcall, $mode)
1542 { 1613 {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!