Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flexydial
/
hdfc-beu-v2
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4cbac761
authored
2019-07-15 12:45:07 +0530
by
Manish Mihsra
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Changed diallines hangup condition and created new function to connect calls in Predictive
1 parent
9c31f85c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
385 additions
and
211 deletions
application/app/Jobs/KPAMIListen.php
application/app/Jobs/KPAMIListen.php
View file @
4cbac76
...
...
@@ -75,7 +75,8 @@ class KPAMIListen implements IEventListener
while
(
true
)
{
usleep
(
2000
*
1000
);
$this
->
redirectIncoming
();
$this
->
connectAvailCalls
();
//$this->redirectIncoming();
}
return
;
}
...
...
@@ -431,11 +432,6 @@ class KPAMIListen implements IEventListener
$cause
=
$event
->
getKey
(
"Cause"
);
$causetxt
=
$event
->
getKey
(
"Cause-txt"
);
//Log::info("<<<<<<<<<<<<<<<<<<=====Start");
//Log::info("eventname");
//Log::info("eventname=====".$eventname);
//Log::info("exten=====".$exten);
//Log::info("context=====".$context);
if
(
$accountcode
!=
""
)
{
...
...
@@ -508,6 +504,31 @@ class KPAMIListen implements IEventListener
{
$nowts
=
microtime
(
true
)
*
1000
;
$dialline
=
Dialline
::
find
(
$crmcall
->
dialline_id
);
if
(
$dialline
&&
(
$dialline
->
channel
==
$channel
||
$dialline
->
status
==
"AutoCall"
))
{
$dialline
->
status
=
"Free"
;
$dialline
->
conf
=
""
;
$dialline
->
number
=
""
;
$dialline
->
uniqueid
=
""
;
$dialline
->
channel
=
""
;
$dialline
->
regexstr
=
""
;
$dialline
->
did
=
""
;
$dialline
->
save
();
$tsip
=
Sipid
::
find
(
$crmcall
->
sipid_id
);
if
(
!
empty
(
$tsip
))
{
$tsip
->
patched
=
0
;
$tsip
->
save
();
$newqueue
=
new
Kqueue
();
$newqueue
->
sipNotify
(
$tsip
,
"dialerUI"
,
"hangup"
,
"c"
,
$crmcall
->
id
.
"~"
.
$crmcall
->
number
.
"~"
.
base64_encode
(
$channel
));
}
}
$crmcall
->
setTs
(
'ts_Recend'
,
$nowts
);
$crmcall
->
state
=
$eventname
;
...
...
@@ -567,34 +588,6 @@ class KPAMIListen implements IEventListener
}
}
$dialline
=
Dialline
::
find
(
$crmcall
->
dialline_id
);
if
(
$dialline
&&
(
$dialline
->
channel
==
$channel
||
$dialline
->
status
==
"AutoCall"
)
)
{
$dialline
->
status
=
"Free"
;
$dialline
->
conf
=
""
;
$dialline
->
number
=
""
;
$dialline
->
uniqueid
=
""
;
$dialline
->
channel
=
""
;
$dialline
->
regexstr
=
""
;
$dialline
->
did
=
""
;
$dialline
->
save
();
$tsip
=
Sipid
::
find
(
$crmcall
->
sipid_id
);
if
(
!
empty
(
$tsip
))
{
$tsip
->
patched
=
0
;
$tsip
->
save
();
$newqueue
=
new
Kqueue
();
$newqueue
->
sipNotify
(
$tsip
,
"dialerUI"
,
"hangup"
,
"c"
,
$crmcall
->
id
.
"~"
.
$crmcall
->
number
.
"~"
.
base64_encode
(
$channel
));
}
//$newqueue=new Kqueue();
//$newqueue->sipNotify($tsip,"dialerUI","hangup","c",$crmcall->id."~".$crmcall->number."~".base64_encode($channel));
}
$crmcall
->
addEventLog
(
$nowts
,
"
$accountcode
:HangupEvent :
$eventname
$channelstate
:
$channelstatedesc
$uniqueid
$exten
:
$priority
$channel
$cause
:
$causetxt
"
);
$crmcall
->
save
();
...
...
@@ -1420,34 +1413,33 @@ class KPAMIListen implements IEventListener
}
private
function
redirectIncoming
()
private
function
connectAvailCalls
()
{
$diallines
=
Dialline
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
In
(
"status"
,[
"Inbound"
,
"Auto"
]
)
->
where
(
"conf"
,
"="
,
""
)
->
get
();
$diallines
=
Dialline
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"Auto"
)
->
where
(
"conf"
,
"="
,
""
)
->
get
();
if
(
$diallines
)
{
foreach
(
$diallines
as
$dialline
)
{
$lastUpdatedTime
=
strtotime
(
date
(
"Y-m-d H:i:s"
))
-
strtotime
(
$dialline
->
updated_at
);
if
(
$lastUpdatedTime
<
8
)
continue
;
if
(
$lastUpdatedTime
<
5
)
continue
;
exec
(
"/usr/sbin/asterisk -rx 'core show channels'"
,
$allChnnlsArr
);
/*
exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr);
$cnt = 0;
foreach
(
$allChnnlsArr
as
$allChnnls
)
{
if
(
stristr
(
$allChnnls
,
substr
(
stripslashes
(
$dialline
->
channel
),
0
,
20
)))
{
$cnt
++
;
}
}
foreach($allChnnlsArr as $allChnnls)
{
if(stristr($allChnnls, substr(stripslashes($dialline->channel),0, 20)))
{
$cnt++;
}
}
if
(
$cnt
==
0
)
{
Log
::
useFiles
(
storage_path
()
.
"/logs/Predictive/predictive_"
.
date
(
"Y_m_d"
)
.
".log"
);
Log
::
info
(
$dialline
);
if($cnt == 0)
{
Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
Log::info($dialline);
$dialline
->
status
=
"Free"
;
$dialline->status="Free";
$dialline->conf="";
$dialline->number="";
$dialline->uniqueid="";
...
...
@@ -1456,115 +1448,40 @@ class KPAMIListen implements IEventListener
$dialline->regexstr="";
$dialline->save();
continue
;
}
continue;
}*/
echo
$dialline
->
number
.
" waiting
\n
"
;
$crmcall
=
CRMCall
::
where
(
"uniqueid"
,
"like"
,
"%"
.
$dialline
->
uniqueid
.
"%"
)
->
first
();
if
(
$crmcall
)
{
echo
"Callid : "
.
$crmcall
->
id
.
" :
$crmcall->did
\n
"
;
$nowts
=
microtime
(
true
)
*
1000
;
$crmcalldata
=
json_decode
(
$crmcall
->
data
,
true
);
if
(
!
isset
(
$crmcalldata
[
"userbusyfile"
]))
$crmcalldata
[
"userbusyfile"
]
=
0
;
$playnoroute
=
env
(
'playnoroute'
,
public_path
(
"assets/sounds/astring"
));
$playnoroutelen
=
env
(
'playnoroutelen'
,
4
);
$playnouser
=
env
(
'playnouser'
,
public_path
(
"assets/sounds/astring"
));
$playnouserlen
=
env
(
'playnouserlen'
,
4
);
$playuserbusy
=
env
(
'playuserbusy'
,
public_path
(
"assets/sounds/astring"
));
$playuserbusylen
=
env
(
'playuserbusylen'
,
4
);
if
(
$crmcall
->
client
==
"."
)
{
$wakka
=
new
KHRMSLib
();
$users
=
$wakka
->
searchPhone
(
"mobile"
,
$crmcall
->
number
);
if
(
!
empty
(
$users
))
{
$ppldata
=
unserialize
(
$users
[
0
][
'peopledata'
]);
$crmcall
->
crm_id
=
$users
[
0
][
'id'
];
$crmcall
->
number
=
$users
[
0
][
'mobile'
];
$crmcall
->
client
=
(
$ppldata
[
'client'
]
?
$ppldata
[
'client'
]
:
""
);
$crmcall
->
department
=
(
$ppldata
[
'department'
]
?
$ppldata
[
'department'
]
:
""
);
$crmcall
->
call_flag
=
"C"
;
$wakka
->
setPersonKey
(
$crmcall
->
crm_id
,
"dialer_lastcall"
,
date
(
"Y-m-d H:i:s"
));
echo
$users
[
0
][
'id'
]
.
" -- ID Found
\n
"
;
}
else
{
$crmcall
->
crm_id
=
0
;
$crmcall
->
client
=
""
;
$crmcall
->
department
=
""
;
$crmcall
->
call_flag
=
"C"
;
echo
"User Not Found!!
\n
"
;
}
$crmcall
->
save
();
}
$sipids
=
array
();
if
(
$crmcall
->
client
!=
""
)
{
$sipids
=
Sipid
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"1"
)
->
where
(
"clients"
,
"like"
,
"%"
.
$crmcall
->
client
.
"%"
)
->
where
(
"clients"
,
"like"
,
"%"
.
$crmcall
->
did
.
"%"
)
->
orderBy
(
"updated_at"
,
"desc"
)
->
get
();
}
else
if
(
$crmcall
->
did
!=
""
)
{
$sipids
=
Sipid
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"1"
)
->
where
(
"clients"
,
"like"
,
"%"
.
$crmcall
->
did
.
"%"
)
->
orderBy
(
"updated_at"
,
"desc"
)
->
get
();
}
else
{
$sipids
=
Sipid
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"1"
)
->
orderBy
(
"updated_at"
,
"desc"
)
->
get
();
//send to all?
}
$sipids
=
Sipid
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"1"
)
->
where
(
"ready"
,
"="
,
"1"
)
->
where
(
"prepare_call"
,
"="
,
"1"
)
->
orderBy
(
"updated_at"
,
"desc"
)
->
get
();
if
(
!
empty
(
$sipids
))
{
echo
"sipids found "
;
//create map?
$first_r
=
0
;
$first_w
=
0
;
$first_a
=
0
;
$allsipids
=
array
();
foreach
(
$sipids
as
$sipid
)
{
//if($sipid->ready==1)
if
(
$sipid
->
ready
==
1
&&
$sipid
->
prepare_call
==
0
&&
$dialline
->
status
==
"Inbound"
)
{
$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
;
}
}
else
{
$allsipids
[]
=
$sipid
;
}
}
foreach
(
$sipids
as
$sipid
)
{
if
(
$sipid
->
ready
==
1
&&
$sipid
->
prepare_call
==
1
&&
$dialline
->
status
==
"Auto"
)
{
$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
;
}
}
else
$clientsarr
=
json_decode
(
$sipid
->
clients
,
true
);
if
(
$crmcall
->
client
==
""
)
$first_a
=
$sipid
;
else
{
$allsipids
[]
=
$sipid
;
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
;
}
}
...
...
@@ -1577,7 +1494,7 @@ class KPAMIListen implements IEventListener
if
(
$found
)
{
$alreadyconf
=
Dialline
::
where
(
'server'
,
'='
,
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"
Inbound
"
)
->
where
(
"conf"
,
"="
,
"1000"
.
$found
->
id
)
->
get
();
$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
"
;
...
...
@@ -1589,7 +1506,48 @@ class KPAMIListen implements IEventListener
{
echo
"sipids :
$found->id
\n
"
;
//get ts_Wait
$userEntry
=
User
::
find
(
$found
->
user
);
if
(
!
empty
(
$userEntry
)){
if
(
$userEntry
->
current_dialmode
!=
"Predictive"
||
$found
->
ready
!=
1
)
return
;
}
exec
(
"/usr/sbin/asterisk -rx 'core show channels'"
,
$allChnnlsArr
);
$cnt
=
0
;
foreach
(
$allChnnlsArr
as
$allChnnls
)
{
if
(
stristr
(
$allChnnls
,
substr
(
stripslashes
(
$dialline
->
channel
),
0
,
20
)))
{
$cnt
++
;
}
}
if
(
$cnt
==
0
)
{
Log
::
useFiles
(
storage_path
()
.
"/logs/Predictive/predictive_"
.
date
(
"Y_m_d"
)
.
".log"
);
Log
::
info
(
$crmcall
->
id
);
Log
::
info
(
$dialline
);
$dialline
->
status
=
"Free"
;
$dialline
->
conf
=
""
;
$dialline
->
number
=
""
;
$dialline
->
uniqueid
=
""
;
$dialline
->
src_channel
=
""
;
$dialline
->
channel
=
""
;
$dialline
->
regexstr
=
""
;
$dialline
->
save
();
continue
;
}
$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
();
...
...
@@ -1610,18 +1568,11 @@ class KPAMIListen implements IEventListener
$crmcall
->
save
();
$dialline
->
user_id
=
$found
->
user
;
$dialline
->
conf
=
"1000"
.
$found
->
id
;
$dialline
->
save
();
if
(
$crmcall
->
crm_id
>
0
){
DB
::
table
(
'records'
)
->
where
(
'id'
,
$crmcall
->
crm_id
)
->
update
([
'filter_condition'
=>
'3'
,
'usr_id'
=>
$found
->
user
]);
}
$found
->
ready
=
0
;
$found
->
prepare_call
=
0
;
$found
->
patched
=
1
;
$found
->
save
();
$recfile
=
$crmcall
->
newRecFilePath
();
...
...
@@ -1631,82 +1582,305 @@ class KPAMIListen implements IEventListener
//start recording
$newqueue
=
new
Kqueue
();
$newqueue
->
recordChannel
(
$dialline
->
server
,
$dialline
->
channel
,
$recfile
);
$newqueue
=
new
Kqueue
();
$newqueue
->
userToConf
(
$found
);
$newqueue
=
new
Kqueue
();
$newqueue
->
channelRedirectToExten
(
$found
->
server
,
$dialline
->
channel
,
"1000"
.
$found
->
id
,
"kstychDialer"
,
"1"
);
//notify UI (only the sip id)
$newqueue
=
new
Kqueue
();
$newqueue
->
sipNotify
(
$found
,
"dialerUI"
,
"dialstart"
,
"c"
,
$crmcall
->
number
);
$newqueue
=
new
Kqueue
();
$newqueue
->
sipNotify
(
$found
,
"incomingCall"
,
$crmcall
->
id
,
$crmcall
->
crm_id
,
$crmcall
->
number
.
"@"
.
$dialline
->
channel
);
}
else
{
if
(
!
empty
(
$allsipids
))
{
foreach
(
$allsipids
as
$tsip
)
{
//$newqueue=new Kqueue();
//$newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
if
(
$dialline
->
status
!=
"Auto"
)
{
$newqueue
=
new
Kqueue
();
$newqueue
->
sipNotify
(
$tsip
,
"popupalert"
,
" Incoming Calls"
,
$crmcall
->
number
.
"|"
.
$crmcall
->
client
,
""
);
}
}
}
else
{
//play no users available
if
(
$crmcalldata
[
"userbusyfile"
]
<
$nowts
)
{
$crmcalldata
[
"userbusyfile"
]
=
$nowts
+
((
$playnouserlen
+
2
)
*
1000
);
$crmcall
->
data
=
json_encode
(
$crmcalldata
);
$crmcall
->
save
();
}
}
//no ready user, send notifications
}
}
else
{
//no users online
//play no routes file
if
(
$crmcalldata
[
"userbusyfile"
]
<
$nowts
)
{
$crmcalldata
[
"userbusyfile"
]
=
$nowts
+
((
$playnoroutelen
+
2
)
*
1000
);
$crmcall
->
data
=
json_encode
(
$crmcalldata
);
$crmcall
->
save
();
//$newqueue=new Kqueue();
//$newqueue->playfile($playnoroute,$dialline->channel,"kstychDialerINB",$dialline->server);
}
}
}
else
{
//$dialline->status='Free';
//$dialline->save();
}
//if client was matched then find users by client
//else find users by DID
//ele everyone
}
}
}
// private function redirectIncoming()
// {
// $diallines=Dialline::where('server','=',$this->sipip)->whereIn("status",["Inbound","Auto"])->where("conf","=","")->get();
// if($diallines)
// {
// foreach($diallines as $dialline)
// {
// $lastUpdatedTime = strtotime(date("Y-m-d H:i:s")) - strtotime($dialline->updated_at);
// if($lastUpdatedTime < 8) continue;
// exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr);
// $cnt = 0;
// foreach($allChnnlsArr as $allChnnls)
// {
// if(stristr($allChnnls, substr(stripslashes($dialline->channel),0, 20)))
// {
// $cnt++;
// }
// }
// if($cnt == 0)
// {
// Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
// Log::info($dialline);
// $dialline->status="Free";
// $dialline->conf="";
// $dialline->number="";
// $dialline->uniqueid="";
// $dialline->src_channel="";
// $dialline->channel="";
// $dialline->regexstr="";
// $dialline->save();
// continue;
// }
// echo $dialline->number." waiting\n";
// $crmcall=CRMCall::where("uniqueid","like","%".$dialline->uniqueid."%")->first();
// if($crmcall)
// {
// echo "Callid : ".$crmcall->id." : $crmcall->did\n";
// $nowts=microtime(true)*1000;
// $crmcalldata=json_decode($crmcall->data,true);
// if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0;
// $playnoroute=env('playnoroute',public_path("assets/sounds/astring"));
// $playnoroutelen=env('playnoroutelen',4);
// $playnouser=env('playnouser',public_path("assets/sounds/astring"));
// $playnouserlen=env('playnouserlen',4);
// $playuserbusy=env('playuserbusy',public_path("assets/sounds/astring"));
// $playuserbusylen=env('playuserbusylen',4);
// if($crmcall->client==".")
// {
// $wakka = new KHRMSLib();
// $users=$wakka->searchPhone("mobile",$crmcall->number);
// if(!empty($users))
// {
// $ppldata=unserialize($users[0]['peopledata']);
// $crmcall->crm_id=$users[0]['id'];
// $crmcall->number=$users[0]['mobile'];
// $crmcall->client=($ppldata['client']?$ppldata['client']:"");
// $crmcall->department=($ppldata['department']?$ppldata['department']:"");
// $crmcall->call_flag="C";
// $wakka->setPersonKey($crmcall->crm_id,"dialer_lastcall",date("Y-m-d H:i:s"));
// echo $users[0]['id']." -- ID Found\n";
// }
// else
// {
// $crmcall->crm_id=0;
// $crmcall->client="";
// $crmcall->department="";
// $crmcall->call_flag="C";
// echo "User Not Found!!\n";
// }
// $crmcall->save();
// }
// $sipids=array();
// if($crmcall->client!="")
// {
// $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->client."%")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
// }
// else if($crmcall->did!="")
// {
// $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
// }
// else
// {
// $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->orderBy("updated_at","desc")->get();//send to all?
// }
// if(!empty($sipids))
// {
// echo "sipids found ";
// //create map?
// $first_r=0;$first_w=0;$first_a=0;$allsipids=array();
// foreach($sipids as $sipid)
// {
// //if($sipid->ready==1)
// if($sipid->ready==1&&$sipid->prepare_call==0&&$dialline->status=="Inbound")
// {
// $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;
// }
// }
// else
// {
// $allsipids[]=$sipid;
// }
// }
// foreach($sipids as $sipid)
// {
// if($sipid->ready==1&&$sipid->prepare_call==1&&$dialline->status=="Auto")
// {
// $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;
// }
// }
// else
// {
// $allsipids[]=$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)->whereIn("status",["Inbound","Auto"])->where("conf","=","1000".$found->id)->get();
// if(sizeof($alreadyconf)>0)
// {
// echo $found->id." : Found but Already in Conf!!!\n";
// $found=false;
// }
// }
// if($found)
// {
// echo "sipids : $found->id \n";
// //get ts_Wait
// $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();
// $dialline->user_id = $found->user;
// $dialline->conf = "1000".$found->id;
// $dialline->save();
// if($crmcall->crm_id>0){
// DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]);
// }
// $found->ready=0;
// $found->prepare_call=0;
// $found->patched=1;
// $found->save();
// $recfile=$crmcall->newRecFilePath();
// $crmcall->setTs('ts_Recstart',$nowts);
// $crmcall->save();
// //start recording
// $newqueue=new Kqueue();
// $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile);
// $newqueue=new Kqueue();
// $newqueue->userToConf($found);
// $newqueue=new Kqueue();
// $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1");
// //notify UI (only the sip id)
// $newqueue=new Kqueue();
// $newqueue->sipNotify($found,"dialerUI","dialstart","c",$crmcall->number);
// $newqueue=new Kqueue();
// $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel);
// }
// else
// {
// if(!empty($allsipids))
// {
// foreach($allsipids as $tsip)
// {
// //$newqueue=new Kqueue();
// //$newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
// if($dialline->status!="Auto")
// {
// $newqueue=new Kqueue();
// $newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
// }
// }
// }
// else
// {
// //play no users available
// if($crmcalldata["userbusyfile"]<$nowts)
// {
// $crmcalldata["userbusyfile"]=$nowts+(($playnouserlen+2)*1000);
// $crmcall->data=json_encode($crmcalldata);
// $crmcall->save();
// }
// }
// //no ready user, send notifications
// }
// }
// else
// {
// //no users online
// //play no routes file
// if($crmcalldata["userbusyfile"]<$nowts)
// {
// $crmcalldata["userbusyfile"]=$nowts+(($playnoroutelen+2)*1000);
// $crmcall->data=json_encode($crmcalldata);
// $crmcall->save();
// //$newqueue=new Kqueue();
// //$newqueue->playfile($playnoroute,$dialline->channel,"kstychDialerINB",$dialline->server);
// }
// }
// }
// else
// {
// //$dialline->status='Free';
// //$dialline->save();
// }
// //if client was matched then find users by client
// //else find users by DID
// //ele everyone
// }
// }
// }
private
function
sendAMICommands
()
{
$queues
=
Kqueue
::
where
(
"type"
,
"="
,
"SIP_"
.
$this
->
sipip
)
->
where
(
"status"
,
"="
,
"New"
)
->
take
(
5
)
->
get
();
$queues
=
Kqueue
::
where
(
"type"
,
"="
,
"SIP_"
.
$this
->
sipip
)
->
take
(
5
)
->
get
();
if
(
!
$queues
->
isEmpty
())
foreach
(
$queues
as
$i
=>
$tqueue
)
{
...
...
@@ -1718,7 +1892,7 @@ class KPAMIListen implements IEventListener
$notify
->
setVariable
(
'kstych-Data'
,
"
$data[1]|$data[2]|$data[3]|$data[4]
"
);
$res
=
$this
->
_client
->
send
(
$notify
);
}
else
if
(
$tqueue
->
key
==
"originate"
)
elseif
(
$tqueue
->
key
==
"originate"
)
{
$originateMsg
=
new
OriginateAction
(
$data
[
'fromext'
]);
$originateMsg
->
setContext
(
$data
[
'context'
]);
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment