|
@@ -254,6 +254,8 @@ async def getVariableFromChannel(callid,channel,variable_source,variable_destina
|
|
|
if (value):
|
|
if (value):
|
|
|
app.logger.warning('set {}={} for {} from channel'.format(variable_destination,value,callid))
|
|
app.logger.warning('set {}={} for {} from channel'.format(variable_destination,value,callid))
|
|
|
app.cache['cel_calls'][callid][variable_destination] = value
|
|
app.cache['cel_calls'][callid][variable_destination] = value
|
|
|
|
|
+ else:
|
|
|
|
|
+ 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):
|
|
@@ -282,7 +284,7 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
app.cache['cel_calls'][lid]['all_channels'] = {}
|
|
app.cache['cel_calls'][lid]['all_channels'] = {}
|
|
|
app.cache['cel_calls'][lid]['transfers'] = []
|
|
app.cache['cel_calls'][lid]['transfers'] = []
|
|
|
#app.cache['cel_calls'][lid]['mix_monitors'] = []
|
|
#app.cache['cel_calls'][lid]['mix_monitors'] = []
|
|
|
- if (msg.Context=='from-internal'):
|
|
|
|
|
|
|
+ if (msg.Context.startswith('from-internal')):
|
|
|
sip_call_id = await amiChannelGetVar(msg.Channel,"PJSIP_HEADER(read,UniqueId)")
|
|
sip_call_id = await amiChannelGetVar(msg.Channel,"PJSIP_HEADER(read,UniqueId)")
|
|
|
#if( False and not sip_call_id):
|
|
#if( False and not sip_call_id):
|
|
|
# sip_call_id = await amiChannelGetVar(msg.Channel,"PJSIP_HEADER(read,Call-ID)")
|
|
# sip_call_id = await amiChannelGetVar(msg.Channel,"PJSIP_HEADER(read,Call-ID)")
|
|
@@ -292,6 +294,18 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
await getVariableFromPJSIP(lid,msg.Channel,"CallerNumber","ANumber")
|
|
await getVariableFromPJSIP(lid,msg.Channel,"CallerNumber","ANumber")
|
|
|
#await getVariableFromPJSIP(lid,msg.Channel,"CallerNumber")
|
|
#await getVariableFromPJSIP(lid,msg.Channel,"CallerNumber")
|
|
|
await getVariableFromPJSIP(lid,msg.Channel,"BNumber")
|
|
await getVariableFromPJSIP(lid,msg.Channel,"BNumber")
|
|
|
|
|
+ if (len(msg.Exten)>=7):
|
|
|
|
|
+ device = msg.CallerIDnum
|
|
|
|
|
+ user = device
|
|
|
|
|
+ if device in app.cache['usermap']:
|
|
|
|
|
+ user = app.cache['usermap'][device]
|
|
|
|
|
+ start = datetime.strptime(msg.EventTime,"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ _cb = {'webhook_name': "outgoing_start",
|
|
|
|
|
+ 'callId':msg.LinkedID,
|
|
|
|
|
+ 'ANumber': user,
|
|
|
|
|
+ 'BNumber': msg.Exten}
|
|
|
|
|
+ app.logger.warning('outgoing cb {}'.format(_cb))
|
|
|
|
|
+ reply = await doCallback(device, _cb)
|
|
|
else:
|
|
else:
|
|
|
await getVariableFromChannel(lid,msg.Channel,"ALERT_INFO","AlertInfo")
|
|
await getVariableFromChannel(lid,msg.Channel,"ALERT_INFO","AlertInfo")
|
|
|
|
|
|
|
@@ -427,6 +441,28 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
_cb['speakingTime'] = (end-answer).total_seconds()
|
|
_cb['speakingTime'] = (end-answer).total_seconds()
|
|
|
app.logger.warning('c2c cb {}'.format(_cb))
|
|
app.logger.warning('c2c cb {}'.format(_cb))
|
|
|
reply = await doCallback(call["c2c_device"], _cb)
|
|
reply = await doCallback(call["c2c_device"], _cb)
|
|
|
|
|
+ elif (firstMessage.Context.startswith('from-internal') and len(firstMessage.Exten)>=7):
|
|
|
|
|
+ call = app.cache['cel_calls'][lid]
|
|
|
|
|
+ device = firstMessage.CallerIDnum
|
|
|
|
|
+ user = device
|
|
|
|
|
+ if device in app.cache['usermap']:
|
|
|
|
|
+ user = app.cache['usermap'][device]
|
|
|
|
|
+ start = datetime.strptime(firstMessage.EventTime,"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ end = datetime.strptime(msg.EventTime,"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ _cb = {'webhook_name': "outgoing_end",
|
|
|
|
|
+ 'callId':msg.LinkedID,
|
|
|
|
|
+ 'speakingTime': 0,
|
|
|
|
|
+ 'waitingTime': (end-start).total_seconds(),
|
|
|
|
|
+ 'answered': False,
|
|
|
|
|
+ 'ANumber': user,
|
|
|
|
|
+ 'BNumber': firstMessage.Exten}
|
|
|
|
|
+ if "answer_time" in call:
|
|
|
|
|
+ answer = datetime.strptime(call["answer_time"],"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
+ _cb["answered"] = True
|
|
|
|
|
+ _cb['waitingTime'] = (answer-start).total_seconds()
|
|
|
|
|
+ _cb['speakingTime'] = (end-answer).total_seconds()
|
|
|
|
|
+ app.logger.warning('outgoing cb {}'.format(_cb))
|
|
|
|
|
+ reply = await doCallback(device, _cb)
|
|
|
app.cache['cel_calls'].pop(lid, False)
|
|
app.cache['cel_calls'].pop(lid, False)
|
|
|
app.cache['cel_queue_calls'].pop(lid, False)
|
|
app.cache['cel_queue_calls'].pop(lid, False)
|
|
|
|
|
|
|
@@ -543,27 +579,29 @@ async def getUserCDR(user,
|
|
|
limit=None,
|
|
limit=None,
|
|
|
offset=None,
|
|
offset=None,
|
|
|
order='ASC'):
|
|
order='ASC'):
|
|
|
- _q = f'''SELECT * FROM cdr AS c INNER JOIN (SELECT linkedid FROM cdr WHERE'''
|
|
|
|
|
|
|
+ _linked_q = f'''SELECT linkedid from cdr WHERE'''
|
|
|
if direction:
|
|
if direction:
|
|
|
direction=direction.lower()
|
|
direction=direction.lower()
|
|
|
if direction in ('in', True, '1', 'incoming', 'inbound'):
|
|
if direction in ('in', True, '1', 'incoming', 'inbound'):
|
|
|
direction = 'inbound'
|
|
direction = 'inbound'
|
|
|
- _q += f''' dst="{user}"'''
|
|
|
|
|
|
|
+ _linked_q += f''' dst="{user}"'''
|
|
|
elif direction in ('out', False, '0', 'outgoing', 'outbound'):
|
|
elif direction in ('out', False, '0', 'outgoing', 'outbound'):
|
|
|
direction = 'outbound'
|
|
direction = 'outbound'
|
|
|
- _q += f''' cnum="{user}"'''
|
|
|
|
|
|
|
+ _linked_q += f''' cnum="{user}"'''
|
|
|
else:
|
|
else:
|
|
|
direction = None
|
|
direction = None
|
|
|
- _q += f''' (cnum="{user}" or dst="{user}")'''
|
|
|
|
|
|
|
+ _linked_q += f''' (cnum="{user}" or dst="{user}")'''
|
|
|
if end is None:
|
|
if end is None:
|
|
|
end = dt.now()
|
|
end = dt.now()
|
|
|
if start is None:
|
|
if start is None:
|
|
|
start=(end - td(hours=24))
|
|
start=(end - td(hours=24))
|
|
|
- _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):
|
|
|
- _q += f''' LIMIT {offset},{limit}'''
|
|
|
|
|
- _q += f''') AS c2 ON c.linkedid = c2.linkedid;'''
|
|
|
|
|
- #app.logger.warning('SQL: {}'.format(_q))
|
|
|
|
|
|
|
+ _linked_q += f''' LIMIT {offset},{limit}'''
|
|
|
|
|
+ start1 = (start-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))
|
|
|
_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'):
|
|
@@ -1289,6 +1327,31 @@ class Originate_test(Resource):
|
|
|
# else:
|
|
# else:
|
|
|
# return errorReply(reply.message)
|
|
# return errorReply(reply.message)
|
|
|
|
|
|
|
|
|
|
+@app.route('/registration_call/<numberB>')
|
|
|
|
|
+class registration_call(Resource):
|
|
|
|
|
+ @authRequired
|
|
|
|
|
+ @app.param('numberB', 'User calling ', 'path')
|
|
|
|
|
+ @app.response(HTTPStatus.OK, 'Json reply')
|
|
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
|
|
+ async def get(self, numberB):
|
|
|
|
|
+ if (not request.admin):
|
|
|
|
|
+ abort(401)
|
|
|
|
|
+ numberB = re.sub('\D', '', numberB);
|
|
|
|
|
+ row = await db.fetch_one(query='SELECT phone FROM phone_registration WHERE active=1 order by rand() limit 1');
|
|
|
|
|
+ numberA = row['phone'];
|
|
|
|
|
+ _act = { 'Action':'Originate',
|
|
|
|
|
+ 'Channel':'Local/{}@regcall-legA'.format(numberB),
|
|
|
|
|
+ 'Context':'regcall-legB',
|
|
|
|
|
+ 'Exten':numberB,
|
|
|
|
|
+ 'Priority': '1',
|
|
|
|
|
+ 'Async':'true',
|
|
|
|
|
+ 'Callerid': '{} <{}>'.format(numberA, numberA)
|
|
|
|
|
+ }
|
|
|
|
|
+ app.logger.warning(_act)
|
|
|
|
|
+ await manager.send_action(_act)
|
|
|
|
|
+ return successfullyOriginated(numberA, numberB)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@app.route('/autocall/<numberA>/<numberB>')
|
|
@app.route('/autocall/<numberA>/<numberB>')
|
|
|
class Autocall(Resource):
|
|
class Autocall(Resource):
|
|
|
@authRequired
|
|
@authRequired
|