Hal De 4 anni fa
parent
commit
150b51f3bf
2 ha cambiato i file con 37 aggiunte e 11 eliminazioni
  1. 33 11
      app/app.py
  2. 4 0
      app/utils.py

+ 33 - 11
app/app.py

@@ -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')

+ 4 - 0
app/utils.py

@@ -148,6 +148,10 @@ def successfullyTransfered(userA, userB):
   return successReply({'userA':userA,'userB':userB},
                       'Call was successfully transfered from user {} to user {}'.format(userA, userB))
 
+def successfullyHungup(user):
+  return successReply({'user':user},
+                      'Call was successfully hungup for user {}'.format(user))
+
 def successfullyBound(user, device):
   return successReply({'user':user,'device':device},
                       'User {} is successfully bound to device {}'.format(user, device))