|
@@ -193,7 +193,7 @@ async def newchannelCallback(mngr: Manager, msg: Message):
|
|
|
user = None
|
|
user = None
|
|
|
device = None
|
|
device = None
|
|
|
uid = None
|
|
uid = None
|
|
|
- if msg.context in ('from-pstn'):
|
|
|
|
|
|
|
+ if msg.context.startswith('from-pstn'):
|
|
|
app.cache['calls'][msg.uniqueid]=msg
|
|
app.cache['calls'][msg.uniqueid]=msg
|
|
|
elif ((msg.context in ('from-queue')) and
|
|
elif ((msg.context in ('from-queue')) and
|
|
|
(msg.linkedid in app.cache['calls']) and
|
|
(msg.linkedid in app.cache['calls']) and
|
|
@@ -203,7 +203,7 @@ async def newchannelCallback(mngr: Manager, msg: Message):
|
|
|
user = msg.exten
|
|
user = msg.exten
|
|
|
device = app.cache['devicemap'][user]
|
|
device = app.cache['devicemap'][user]
|
|
|
uid = msg.linkedid
|
|
uid = msg.linkedid
|
|
|
- elif ((msg.context in ('from-internal')) and
|
|
|
|
|
|
|
+ elif ((msg.context.startswith('from-internal')) and
|
|
|
(msg.exten in app.cache['devicemap'])):
|
|
(msg.exten in app.cache['devicemap'])):
|
|
|
user = msg.exten
|
|
user = msg.exten
|
|
|
device = app.cache['devicemap'][user]
|
|
device = app.cache['devicemap'][user]
|
|
@@ -256,27 +256,11 @@ async def getVariableFromChannel(callid,channel,variable_source,variable_destina
|
|
|
app.cache['cel_calls'][callid][variable_destination] = value
|
|
app.cache['cel_calls'][callid][variable_destination] = value
|
|
|
else:
|
|
else:
|
|
|
app.logger.warning('can\'t get {} for {} from channel'.format(variable_source,callid))
|
|
app.logger.warning('can\'t get {} for {} from channel'.format(variable_source,callid))
|
|
|
-
|
|
|
|
|
@manager.register_event('CEL')
|
|
@manager.register_event('CEL')
|
|
|
async def celCallback(mngr: Manager, msg: Message):
|
|
async def celCallback(mngr: Manager, msg: Message):
|
|
|
#app.logger.warning('CEL {}'.format(msg))
|
|
#app.logger.warning('CEL {}'.format(msg))
|
|
|
lid = msg.LinkedID
|
|
lid = msg.LinkedID
|
|
|
- if (msg.EventName == 'ATTENDEDTRANSFER'):
|
|
|
|
|
- #app.logger.warning('CEL {}'.format(msg))
|
|
|
|
|
- extra = json.loads(msg.Extra)
|
|
|
|
|
- if ('transferee_channel_uniqueid' in extra) and ('channel2_uniqueid' in extra):
|
|
|
|
|
- first = extra['transferee_channel_uniqueid']; #unique
|
|
|
|
|
- second = extra['channel2_uniqueid'] #linked
|
|
|
|
|
- firstname = extra['transferee_channel_name']
|
|
|
|
|
- secondname = extra['channel2_name']
|
|
|
|
|
- if (True or msg.CallerIDrdnis == '78124254209'):
|
|
|
|
|
- res = await amiStopMixMonitor(firstname);
|
|
|
|
|
- filename = "transfer-{}-{}-{}".format(msg.Exten, msg.CallerIDnum, msg.LinkedID);
|
|
|
|
|
- res = await amiStartMixMonitor(firstname,filename);#2022/03/11/external-2534-1934-20220311-122726-1647001646.56557.wav
|
|
|
|
|
- res = await amiChannelSetVar(firstname,"CDR(recordingfile)","{}.wav".format(filename))
|
|
|
|
|
- #await amiStopMixMonitor(secondname);
|
|
|
|
|
- app.cache['cel_calls'][lid]['transfers'].append((first,second)) #no cdr in db here
|
|
|
|
|
- #app.logger.warning('first {} {}'.format(first,second))
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if ((msg.EventName == 'CHAN_START') and (lid == msg.UniqueID)): #save first msg
|
|
if ((msg.EventName == 'CHAN_START') and (lid == msg.UniqueID)): #save first msg
|
|
|
app.cache['cel_calls'][lid] = msg
|
|
app.cache['cel_calls'][lid] = msg
|
|
@@ -315,6 +299,31 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
if firstMessage.CallerIDnum in app.cache['usermap']:
|
|
if firstMessage.CallerIDnum in app.cache['usermap']:
|
|
|
cid = app.cache['usermap'][firstMessage.CallerIDnum]
|
|
cid = app.cache['usermap'][firstMessage.CallerIDnum]
|
|
|
uid = firstMessage.LinkedID
|
|
uid = firstMessage.LinkedID
|
|
|
|
|
+
|
|
|
|
|
+ if (msg.EventName == 'ATTENDEDTRANSFER'):
|
|
|
|
|
+ #app.logger.warning('CEL {}'.format(msg))
|
|
|
|
|
+ extra = json.loads(msg.Extra)
|
|
|
|
|
+ if ('transferee_channel_uniqueid' in extra) and ('channel2_uniqueid' in extra):
|
|
|
|
|
+ first = extra['transferee_channel_uniqueid']; #unique
|
|
|
|
|
+ second = extra['channel2_uniqueid'] #linked
|
|
|
|
|
+ firstname = extra['transferee_channel_name']
|
|
|
|
|
+ secondname = extra['transfer_target_channel_name'].replace(";1",";2")
|
|
|
|
|
+ thirdname = extra['channel2_name'].replace(";1",";2")
|
|
|
|
|
+ if (True or msg.CallerIDrdnis == '78124254209' or msg.CallerIDani == '10001'):
|
|
|
|
|
+ if secondname != firstMessage.channel:
|
|
|
|
|
+ await amiStopMixMonitor(secondname)
|
|
|
|
|
+ if thirdname != firstMessage.channel:
|
|
|
|
|
+ await amiStopMixMonitor(thirdname)
|
|
|
|
|
+ if (True or msg.CallerIDrdnis == '78124254209'):
|
|
|
|
|
+ if firstname != firstMessage.channel:
|
|
|
|
|
+ res = await amiStopMixMonitor(firstname)
|
|
|
|
|
+ filename = "transfer-{}-{}-{}".format(msg.Exten, msg.CallerIDnum, msg.LinkedID);
|
|
|
|
|
+ res = await amiStartMixMonitor(firstname,filename);#2022/03/11/external-2534-1934-20220311-122726-1647001646.56557.wav
|
|
|
|
|
+ res = await amiChannelSetVar(firstname,"CDR(recordingfile)","{}.wav".format(filename))
|
|
|
|
|
+ ttime = datetime.strptime(msg.EventTime,"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ app.cache['cel_calls'][lid]['transfers'].append((first,second,ttime)) #no cdr in db here
|
|
|
|
|
+ #app.logger.warning('first {} {}'.format(first,second))
|
|
|
|
|
+
|
|
|
if (msg.EventName == 'CHAN_START') and (lid != msg.UniqueID) and (not msg.Channel.startswith('Local/')):
|
|
if (msg.EventName == 'CHAN_START') and (lid != msg.UniqueID) and (not msg.Channel.startswith('Local/')):
|
|
|
if (msg.CallerIDnum!=''): # or (firstMessage.Context == 'from-pstn') or (firstMessage.get('groupCall',False))):#all calls
|
|
if (msg.CallerIDnum!=''): # or (firstMessage.Context == 'from-pstn') or (firstMessage.get('groupCall',False))):#all calls
|
|
|
device = msg.CallerIDnum
|
|
device = msg.CallerIDnum
|
|
@@ -336,7 +345,7 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
reply = await doCallback(device, _cb)
|
|
reply = await doCallback(device, _cb)
|
|
|
if ((msg.Application == 'Queue') and
|
|
if ((msg.Application == 'Queue') and
|
|
|
(msg.EventName == 'APP_START') and
|
|
(msg.EventName == 'APP_START') and
|
|
|
- (firstMessage.Context == 'from-internal') and
|
|
|
|
|
|
|
+ (firstMessage.Context.startswith('from-internal')) and
|
|
|
(cid is not None) and (len(cid) < 7)):
|
|
(cid is not None) and (len(cid) < 7)):
|
|
|
app.cache['cel_calls'][lid]['groupCall'] = True
|
|
app.cache['cel_calls'][lid]['groupCall'] = True
|
|
|
app.cache['cel_calls'][lid]['queueName'] = msg.Exten
|
|
app.cache['cel_calls'][lid]['queueName'] = msg.Exten
|
|
@@ -420,9 +429,9 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
app.cache['cel_calls'][lid]["answer_time"]=msg.EventTime
|
|
app.cache['cel_calls'][lid]["answer_time"]=msg.EventTime
|
|
|
if (msg.EventName == 'LINKEDID_END'):
|
|
if (msg.EventName == 'LINKEDID_END'):
|
|
|
for t in firstMessage['transfers']:
|
|
for t in firstMessage['transfers']:
|
|
|
- #app.logger.warning('first {}'.format(t))
|
|
|
|
|
- (f,s) = t
|
|
|
|
|
- await db.execute(query='update cdr set transfer_from=(select distinct linkedid from cdr where uniqueid=:first) where linkedid=:second;',values={'first': f,'second': s})
|
|
|
|
|
|
|
+ app.logger.warning('transfer {}'.format(t))
|
|
|
|
|
+ (f,s,tt) = t
|
|
|
|
|
+ await db.execute(query='update cdr set transfer_from=(select distinct linkedid from cdr where uniqueid=:first), transfer_time=:ttime where linkedid=:second;',values={'first': f,'second': s,'ttime':tt})
|
|
|
if ("c2c_start_time" in app.cache['cel_calls'][lid]):
|
|
if ("c2c_start_time" in app.cache['cel_calls'][lid]):
|
|
|
call = app.cache['cel_calls'][lid]
|
|
call = app.cache['cel_calls'][lid]
|
|
|
start = datetime.strptime(call["c2c_start_time"],"%Y-%m-%d %H:%M:%S")
|
|
start = datetime.strptime(call["c2c_start_time"],"%Y-%m-%d %H:%M:%S")
|
|
@@ -566,7 +575,7 @@ async def getCallInfo(callid):
|
|
|
if row['recordingfile'] is not None and row['recordingfile'] != '':
|
|
if row['recordingfile'] is not None and row['recordingfile'] != '':
|
|
|
row['recordingfile'] = '/static/records/{d.year}/{d.month:02}/{d.day:02}/{filename}'.format(d=row['calldate'],
|
|
row['recordingfile'] = '/static/records/{d.year}/{d.month:02}/{d.day:02}/{filename}'.format(d=row['calldate'],
|
|
|
filename=row['recordingfile'])
|
|
filename=row['recordingfile'])
|
|
|
- #app.logger.warning('event row {}'.format(row))
|
|
|
|
|
|
|
+ app.logger.warning('event row {}'.format(row))
|
|
|
events.add(row)
|
|
events.add(row)
|
|
|
record = events.simple()
|
|
record = events.simple()
|
|
|
return record
|
|
return record
|
|
@@ -596,12 +605,12 @@ async def getUserCDR(user,
|
|
|
if start is None:
|
|
if start is None:
|
|
|
start=(end - td(hours=24))
|
|
start=(end - td(hours=24))
|
|
|
_linked_q += f''' AND calldate BETWEEN "{start}" AND "{end}" GROUP BY linkedid'''
|
|
_linked_q += f''' AND calldate BETWEEN "{start}" AND "{end}" GROUP BY linkedid'''
|
|
|
- if None not in (limit, offset):
|
|
|
|
|
|
|
+ if None not in (limit, offset): #This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
|
|
|
_linked_q += f''' LIMIT {offset},{limit}'''
|
|
_linked_q += f''' LIMIT {offset},{limit}'''
|
|
|
start1 = (start-td(hours=4))
|
|
start1 = (start-td(hours=4))
|
|
|
end1 = (end+td(hours=4))
|
|
end1 = (end+td(hours=4))
|
|
|
- _q = f'''SELECT * FROM cdr WHERE linkedid in ({_linked_q}) and calldate BETWEEN "{start1}" AND "{end1}";'''
|
|
|
|
|
- app.logger.warning('SQL: {}'.format(_q))
|
|
|
|
|
|
|
+ _q = f'''SELECT * FROM cdr WHERE linkedid in (select * from ({_linked_q}) tmp) and calldate BETWEEN "{start1}" AND "{end1}";'''
|
|
|
|
|
+ #app.logger.warning('SQL: {}'.format(_q))
|
|
|
_cdr = {}
|
|
_cdr = {}
|
|
|
async for row in db.iterate(query=_q):
|
|
async for row in db.iterate(query=_q):
|
|
|
if (row['disposition']=='FAILED' and row['lastapp']=='Queue'):
|
|
if (row['disposition']=='FAILED' and row['lastapp']=='Queue'):
|