|
@@ -804,5 +804,57 @@ class CEL(Resource):
|
|
|
cel = await getCEL(start, end)
|
|
cel = await getCEL(start, end)
|
|
|
return successReply(cel)
|
|
return successReply(cel)
|
|
|
|
|
|
|
|
|
|
+@app.route('/calls')
|
|
|
|
|
+class Calls(Resource):
|
|
|
|
|
+ @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 and ddmmyyyyHHMMSS', 'query')
|
|
|
|
|
+ @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 and ddmmyyyyHHMMSS', 'query')
|
|
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON reply')
|
|
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
|
|
+ async def get(self):
|
|
|
|
|
+ '''Returns aggregated call data JSON.
|
|
|
|
|
+ All request arguments are optional.
|
|
|
|
|
+ '''
|
|
|
|
|
+ calls = []
|
|
|
|
|
+ start = parseDatetime(request.args.get('start'))
|
|
|
|
|
+ end = parseDatetime(request.args.get('end'))
|
|
|
|
|
+ cdr = await getCDR(start, end)
|
|
|
|
|
+ for _call in cdr:
|
|
|
|
|
+ _call0 = _call['id'][0]
|
|
|
|
|
+ context = _call0['dcontext']
|
|
|
|
|
+ call = {'id':_call['id'],
|
|
|
|
|
+ 'start':_call0['calldate'],
|
|
|
|
|
+ 'type': None,
|
|
|
|
|
+ 'numberA': None,
|
|
|
|
|
+ 'numberB': None,
|
|
|
|
|
+ 'line': None,
|
|
|
|
|
+ 'duration': None,
|
|
|
|
|
+ 'waiting': None,
|
|
|
|
|
+ 'status':'NO ANSWER',
|
|
|
|
|
+ 'url': None }
|
|
|
|
|
+ for _c, _r in (('disposition','status'),
|
|
|
|
|
+ ('src','numberA'),
|
|
|
|
|
+ ('recordingfile','url')):
|
|
|
|
|
+ if _c in _call0:
|
|
|
|
|
+ call[_r] = _call0[_c]
|
|
|
|
|
+ src = _call0['src'] if 'src' in _call0 else None
|
|
|
|
|
+ dst = _call0['dst'] if 'dst' in _call0 else None
|
|
|
|
|
+ if src in (*app.cache['ustates'].keys(), *app.cache['devices']):
|
|
|
|
|
+ if dst in (*app.cache['ustates'].keys(),
|
|
|
|
|
+ *app.cache['devices'],
|
|
|
|
|
+ *app.cache['queues'].keys()):
|
|
|
|
|
+ call['type'] = 'local'
|
|
|
|
|
+ else:
|
|
|
|
|
+ call['type'] = 'out'
|
|
|
|
|
+ call['numberB'] = _call0['dst']
|
|
|
|
|
+ else:
|
|
|
|
|
+ call['type'] = 'in'
|
|
|
|
|
+ if 'did' in _call0:
|
|
|
|
|
+ call['line'] = _call0['did']
|
|
|
|
|
+ if len(_call['id'] > 1):
|
|
|
|
|
+ for step in _call['id'][1:]:
|
|
|
|
|
+ pass
|
|
|
|
|
+ calls.append(call)
|
|
|
|
|
+ return successReply(calls)
|
|
|
|
|
+
|
|
|
manager.connect()
|
|
manager.connect()
|
|
|
app.run(loop=main_loop, host='0.0.0.0', port=app.config['PORT'])
|
|
app.run(loop=main_loop, host='0.0.0.0', port=app.config['PORT'])
|