DialerLib.php
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace App\Jobs;
use Auth;
use Request;
use App\Models\User;
use App\Models\CRMCall;
use App\Models\AgentNumber;
use App\Models\Dialline;
use App\Models\Kqueue;
use Response;
use Log;
use Hash;
Use Config;
class DialerLib
{
/**
* To Create New CRM call entry based on calling details
*/
public function createCRMCallEntry($crmdata, $ppldata)
{
$nowts = microtime(true) * 1000;
//start the call log
$crmcall = new CRMCall();
$crmdata['number'] = $this->arrayKey('number', $crmdata);
$crmcall->number = $this->arrayKey('mobile', $ppldata, $crmdata['number']);
$crmcall->user_id = $this->arrayKey('user_id', $crmdata, '0');
$crmcall->sipid_id = $this->arrayKey('sipid_id', $crmdata, '0');
$crmcall->crm_id = $ppldata['crm_id'];
$crmcall->client = $ppldata['client'];
$crmcall->department = $this->arrayKey('department', $ppldata);
$crmcall->state = 'New';
$crmcall->type = $crmdata['type']; //"MOutbound";
$crmcall->dialline_id = $crmdata['dialline_id'];
$crmcall->setTs('ts_Wait', $nowts);
$crmcall->setTs('ts_Call', $nowts);
$crmcall->did = $this->arrayKey('did', $crmdata);
$tdata = array();
$crmcall->data = json_encode($tdata);
$crmcall->save();
return $crmcall;
}
function arrayKey($key, $arraydata, $defaultval = '')
{
return (array_key_exists($key, $arraydata)) ? $arraydata[$key] : $defaultval;
}
function createAgentcallEntry($user)
{
$sipid = $this->mobileAgentlogin($user);
if ($sipid) {
$dialline = Dialline::where('enabled', '1')->where('status', 'Free')->where('server','=', env('app_ip'))->where('dspan','2')->first();
//$dialline = Dialline::where('enabled', '1')->where('status', 'Free')->where('server', '10.14.130.50')->first();
if ($dialline) {
$dialline->status = "Agent";
$dialline->number = $sipid->number;
$dialline->save();
$crmcall = new CRMCall();
$crmcall->number = $sipid->number;
$crmcall->sipid_id = $sipid->id;
$crmcall->user_id = $user->id;
$crmcall->userstatus = "AgentCall";
$crmcall->usersubstatus = "AgentCall";
$crmcall->dialline_id = $dialline->id;
$crmcall->save();
$sipid->ready = 2;
$sipid->save();
$dialline->call_id = $crmcall->id;
$dialline->user_id = $user->id;
$dialline->save();
$newqueue = new Kqueue();
$newqueue->userToMobileAgent($sipid, $dialline);
} else {
return "error";
}
return $sipid;
}
return "error";
}
function mobileAgentlogin($user)
{
$sipid = AgentNumber::where('user_id', $user->id)->first();
if ($sipid == null) $sipid = new AgentNumber();
if ($sipid && $user->phone!='') {
$sipid->number = $user->phone;
$sipid->campaign = $user->campaign;
$sipid->server = env(app_ip);
$sipid->user_id = $user->id;
$sipid->save();
return $sipid;
}
return "Error";
}
function updateDiallinesFree($dialline){
if($dialline && $dialline->status != 'Free'){
$dialline->call_id = 0;
$dialline->user_id = 0;
$dialline->status = "Free";
$dialline->conf = "";
$dialline->number = "";
$dialline->uniqueid = "";
$dialline->src_channel = "";
$dialline->channel = "";
$dialline->regexstr = "";
$dialline->save();
return $dialline;
}
return $dialline;
}
}