|
|
@@ -208,7 +208,7 @@ async def newchannelCallback(mngr: Manager, msg: Message):
|
|
|
'callerId': cid,
|
|
|
'did': did,
|
|
|
'callId': uid})
|
|
|
-
|
|
|
+
|
|
|
@manager.register_event('CEL')
|
|
|
async def celCallback(mngr: Manager, msg: Message):
|
|
|
if (msg.EventName == 'CHAN_START') and (msg.LinkedID == msg.UniqueID): #save first msg
|
|
|
@@ -219,10 +219,10 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
cid = first_message.CallerIDnum
|
|
|
uid = first_message.LinkedID
|
|
|
if cid is not None and len(cid)<7: #for local calls only
|
|
|
- if (msg.EventName == 'CHAN_START') and msg.Context in ('from-queue') and ('HTTP_CLIENT' in app.config): #start dial
|
|
|
+ if (msg.EventName == 'CHAN_START') and msg.Context in ('from-queue') and ('HTTP_CLIENT' in app.config): #start dial
|
|
|
app.cache['cel_calls'][msg.LinkedID]['channels'][msg.Exten] = msg.Channel
|
|
|
app.logger.warning('NEW CALLING LIST {}'.format(','.join(app.cache['cel_calls'][uid]['channels'].keys())))
|
|
|
-
|
|
|
+
|
|
|
row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
values={'device': cid})
|
|
|
if (row is not None) and (row['url'].startswith('http')):
|
|
|
@@ -233,12 +233,12 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
reply = await app.config['HTTP_CLIENT'].post(row['url'],
|
|
|
json=values)
|
|
|
else:
|
|
|
- app.logger.warning('no url for {}'.format(cid))
|
|
|
+ app.logger.warning('no url for {}'.format(cid))
|
|
|
if (msg.EventName == 'CHAN_END') and msg.Context in ('from-queue') and ('HTTP_CLIENT' in app.config) and ('answered' not in first_message):#end dial
|
|
|
called = msg.CallerIDname
|
|
|
app.cache['cel_calls'][uid]['channels'].pop(called, False)
|
|
|
app.logger.warning('NEW CALLING LIST {}'.format(','.join(app.cache['cel_calls'][uid]['channels'].keys())))
|
|
|
-
|
|
|
+
|
|
|
row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
values={'device': cid})
|
|
|
if (row is not None) and (row['url'].startswith('http')):
|
|
|
@@ -252,7 +252,7 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
called = msg.Exten
|
|
|
app.cache['cel_calls'][msg.LinkedID]['answered']=1;
|
|
|
app.logger.warning('answered {}'.format(called))
|
|
|
-
|
|
|
+
|
|
|
row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
values={'device': cid})
|
|
|
if (row is not None) and (row['url'].startswith('http')):
|
|
|
@@ -263,7 +263,7 @@ async def celCallback(mngr: Manager, msg: Message):
|
|
|
if (msg.EventName == 'LINKEDID_END'):
|
|
|
app.cache['cel_calls'].pop(msg.LinkedID,False);
|
|
|
app.logger.warning('Left Calls {}'.format(','.join(app.cache['cel_calls'].keys())))
|
|
|
-
|
|
|
+
|
|
|
|
|
|
async def getCDR(start=None,
|
|
|
end=None,
|
|
|
@@ -1222,5 +1222,93 @@ class DeviceCallback(Resource):
|
|
|
url = row['url']
|
|
|
return successCallbackURL(device, url)
|
|
|
|
|
|
+@app.route('/group/ringing/callback')
|
|
|
+class GroupRingingCallback(Resource):
|
|
|
+ @authRequired
|
|
|
+ @app.param('url', 'used to set the Callback url for the group ringing callback', 'query')
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON data {"url":url}')
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
+ async def get(self, device):
|
|
|
+ '''Returns and sets groupRinging callback url.
|
|
|
+ '''
|
|
|
+ if not request.admin:
|
|
|
+ abort(401)
|
|
|
+ url = request.args.get('url', None)
|
|
|
+ if url is not None:
|
|
|
+ await db.execute(query='REPLACE INTO callback_urls (device, url) VALUES (:device, :url)',
|
|
|
+ values={'device': 'groupRinging','url': url})
|
|
|
+ else:
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
+ values={'device': 'groupRinging'})
|
|
|
+ if row is not None:
|
|
|
+ url = row['url']
|
|
|
+ return successCommonCallbackURL('groupRinging', url)
|
|
|
+
|
|
|
+@app.route('/group/answered/callback')
|
|
|
+class GroupAnsweredCallback(Resource):
|
|
|
+ @authRequired
|
|
|
+ @app.param('url', 'used to set the Callback url for the group answered callback', 'query')
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON data {"url":url}')
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
+ async def get(self, device):
|
|
|
+ '''Returns and sets groupAnswered callback url.
|
|
|
+ '''
|
|
|
+ if not request.admin:
|
|
|
+ abort(401)
|
|
|
+ url = request.args.get('url', None)
|
|
|
+ if url is not None:
|
|
|
+ await db.execute(query='REPLACE INTO callback_urls (device, url) VALUES (:device, :url)',
|
|
|
+ values={'device': 'groupAnswered','url': url})
|
|
|
+ else:
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
+ values={'device': 'groupAnswered'})
|
|
|
+ if row is not None:
|
|
|
+ url = row['url']
|
|
|
+ return successCommonCallbackURL('groupAnswered', url)
|
|
|
+
|
|
|
+@app.route('/queue/enter/callback')
|
|
|
+class QueueEnterCallback(Resource):
|
|
|
+ @authRequired
|
|
|
+ @app.param('url', 'used to set the Callback url for the queue enter callback', 'query')
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON data {"url":url}')
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
+ async def get(self, device):
|
|
|
+ '''Returns and sets queueEnter callback url.
|
|
|
+ '''
|
|
|
+ if not request.admin:
|
|
|
+ abort(401)
|
|
|
+ url = request.args.get('url', None)
|
|
|
+ if url is not None:
|
|
|
+ await db.execute(query='REPLACE INTO callback_urls (device, url) VALUES (:device, :url)',
|
|
|
+ values={'device': 'queueEnter','url': url})
|
|
|
+ else:
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
+ values={'device': 'queueEnter'})
|
|
|
+ if row is not None:
|
|
|
+ url = row['url']
|
|
|
+ return successCommonCallbackURL('queueEnter', url)
|
|
|
+
|
|
|
+@app.route('/queue/leave/callback')
|
|
|
+class QueueLeaveCallback(Resource):
|
|
|
+ @authRequired
|
|
|
+ @app.param('url', 'used to set the Callback url for the queue leave callback', 'query')
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON data {"url":url}')
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
+ async def get(self, device):
|
|
|
+ '''Returns and sets queueLeave callback url.
|
|
|
+ '''
|
|
|
+ if not request.admin:
|
|
|
+ abort(401)
|
|
|
+ url = request.args.get('url', None)
|
|
|
+ if url is not None:
|
|
|
+ await db.execute(query='REPLACE INTO callback_urls (device, url) VALUES (:device, :url)',
|
|
|
+ values={'device': 'queueLeave','url': url})
|
|
|
+ else:
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
+ values={'device': 'queueLeave'})
|
|
|
+ if row is not None:
|
|
|
+ url = row['url']
|
|
|
+ return successCommonCallbackURL('queueLeave', url)
|
|
|
+
|
|
|
manager.connect()
|
|
|
app.run(loop=main_loop, host='0.0.0.0', port=app.config['PORT'])
|