|
|
@@ -539,6 +539,15 @@ async def amiDeviceChannel(device):
|
|
|
return message.channel
|
|
|
return None
|
|
|
|
|
|
+async def getUserChannel(user):
|
|
|
+ device = await getUserDevice(user)
|
|
|
+ if device in NONEs:
|
|
|
+ return False
|
|
|
+ channel = await amiDeviceChannel(device)
|
|
|
+ if channel in NONEs:
|
|
|
+ return False
|
|
|
+ return channel
|
|
|
+
|
|
|
async def setQueueStates(user, device, state):
|
|
|
for queue in [_q for _q, _ma in app.cache['queues'].items() for _m in _ma if _m.user == user]:
|
|
|
await amiSetVar('DEVICE_STATE(Custom:QUEUE{}*{})'.format(device, queue), state)
|
|
|
@@ -657,11 +666,8 @@ class AtXfer(Resource):
|
|
|
async def get(self, userA, userB):
|
|
|
'''Attended call transfer
|
|
|
'''
|
|
|
- device = await getUserDevice(userA)
|
|
|
- if device in NONEs:
|
|
|
- return noUserDevice(userA)
|
|
|
- channel = await amiDeviceChannel(device)
|
|
|
- if channel in NONEs:
|
|
|
+ channel = await getUserChannel(userA)
|
|
|
+ if not channel:
|
|
|
return noUserChannel(userA)
|
|
|
reply = await manager.send_action({'Action':'Atxfer',
|
|
|
'Channel':channel,
|
|
|
@@ -682,11 +688,8 @@ class BXfer(Resource):
|
|
|
async def get(self, userA, userB):
|
|
|
'''Blind call transfer
|
|
|
'''
|
|
|
- device = await getUserDevice(userA)
|
|
|
- if device in NONEs:
|
|
|
- return noUserDevice(userA)
|
|
|
- channel = await amiDeviceChannel(device)
|
|
|
- if channel in NONEs:
|
|
|
+ channel = await getUserChannel(userA)
|
|
|
+ if not channel:
|
|
|
return noUserChannel(userA)
|
|
|
reply = await manager.send_action({'Action':'BlindTransfer',
|
|
|
'Channel':channel,
|
|
|
@@ -698,6 +701,25 @@ class BXfer(Resource):
|
|
|
else:
|
|
|
return errorReply(reply.message)
|
|
|
|
|
|
+@app.route('/hangup/<user>')
|
|
|
+class BXfer(Resource):
|
|
|
+ @app.param('user', 'User to hangup', 'path')
|
|
|
+ @app.response(HTTPStatus.OK, 'Json reply')
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
+ async def get(self, userA, userB):
|
|
|
+ '''Blind call transfer
|
|
|
+ '''
|
|
|
+ channel = await getUserChannel(userA)
|
|
|
+ if not channel:
|
|
|
+ return noUserChannel(userA)
|
|
|
+ reply = await manager.send_action({'Action':'Hangup',
|
|
|
+ 'Channel':channel})
|
|
|
+ if isinstance(reply, Message):
|
|
|
+ if reply.success:
|
|
|
+ return successfullyHungup(user)
|
|
|
+ else:
|
|
|
+ return errorReply(reply.message)
|
|
|
+
|
|
|
@app.route('/users/states')
|
|
|
class UsersStates(Resource):
|
|
|
@app.response(HTTPStatus.OK, 'JSON reply with user:state map or error message')
|
|
|
@@ -775,7 +797,7 @@ class UsersDevices(Resource):
|
|
|
device = await getUserDevice(user)
|
|
|
if ((device in NONEs) or (device == user)):
|
|
|
device = None
|
|
|
- data[user]=device
|
|
|
+ data[user]=device.replace('{}&'.format(user), '')
|
|
|
return successReply(data)
|
|
|
|
|
|
@app.route('/device/<device>/<user>/on')
|