|
@@ -77,9 +77,19 @@ class AuthMiddleware:
|
|
|
|
|
|
|
|
app.asgi_app = AuthMiddleware(app.asgi_app)
|
|
app.asgi_app = AuthMiddleware(app.asgi_app)
|
|
|
|
|
|
|
|
-#@manager.register_event('*')
|
|
|
|
|
-#async def ami_callback(mngr: Manager, msg: Message):
|
|
|
|
|
-# print("GOT MSG:", msg)
|
|
|
|
|
|
|
+@manager.register_event('ExtensionStatus')
|
|
|
|
|
+async def extensionStatusCallback(mngr: Manager, msg: Message):
|
|
|
|
|
+ user = msg.exten
|
|
|
|
|
+ hint = msg.hint
|
|
|
|
|
+ state = msg.statustext.lower()
|
|
|
|
|
+ print('ExtensionStatus', user, hint, state)
|
|
|
|
|
+
|
|
|
|
|
+@manager.register_event('PresenceStatus')
|
|
|
|
|
+async def presenceStatusCallback(mngr: Manager, msg: Message):
|
|
|
|
|
+ user = msg.exten
|
|
|
|
|
+ hint = msg.hint
|
|
|
|
|
+ state = msg.status.lower()
|
|
|
|
|
+ print('PresenceStatus', user, hint, state)
|
|
|
|
|
|
|
|
@app.route('/openapi.json')
|
|
@app.route('/openapi.json')
|
|
|
async def openapi():
|
|
async def openapi():
|
|
@@ -108,7 +118,7 @@ async def ui():
|
|
|
async def action():
|
|
async def action():
|
|
|
_payload = await request.get_data()
|
|
_payload = await request.get_data()
|
|
|
reply = await manager.send_action(json.loads(_payload))
|
|
reply = await manager.send_action(json.loads(_payload))
|
|
|
- return reply
|
|
|
|
|
|
|
+ return str(reply)
|
|
|
|
|
|
|
|
@app.route('/ami/getvar/<string:variable>')
|
|
@app.route('/ami/getvar/<string:variable>')
|
|
|
async def amiGetVar(variable):
|
|
async def amiGetVar(variable):
|
|
@@ -247,6 +257,26 @@ async def amiPresenceState(user):
|
|
|
return reply.state
|
|
return reply.state
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
+async def amiPresenceStateList():
|
|
|
|
|
+ states = {}
|
|
|
|
|
+ reply = await manager.send_action({'Action':'PresenceStateList'})
|
|
|
|
|
+ if len(reply) >= 2:
|
|
|
|
|
+ for message in reply:
|
|
|
|
|
+ if message.event == 'PresenceStateChange':
|
|
|
|
|
+ user = re.search('CustomPresence:(\d+)', message.presentity).group(1)
|
|
|
|
|
+ states[user] = message.status
|
|
|
|
|
+ return states
|
|
|
|
|
+
|
|
|
|
|
+async def amiExtensionStateList():
|
|
|
|
|
+ states = {}
|
|
|
|
|
+ reply = await manager.send_action({'Action':'ExtensionStateList'})
|
|
|
|
|
+ if len(reply) >= 2:
|
|
|
|
|
+ for message in reply:
|
|
|
|
|
+ if ((message.event == 'ExtensionStatus') and
|
|
|
|
|
+ (message.context == 'ext-local')):
|
|
|
|
|
+ states[message.exten] = message.statustext.lower()
|
|
|
|
|
+ return states
|
|
|
|
|
+
|
|
|
async def amiCommand(command):
|
|
async def amiCommand(command):
|
|
|
'''AMI Command
|
|
'''AMI Command
|
|
|
Runs specified command using AMI action Command in background.
|
|
Runs specified command using AMI action Command in background.
|
|
@@ -367,6 +397,30 @@ async def setUserDeviceStates(user, device, queues, ast):
|
|
|
_cf = await amiDBGet('CF', user)
|
|
_cf = await amiDBGet('CF', user)
|
|
|
await amiSetVar('DEVICE_STATE(Custom:DEVCF{})'.format(device), 'INUSE' if _cf != '' else 'NOT_INUSE')
|
|
await amiSetVar('DEVICE_STATE(Custom:DEVCF{})'.format(device), 'INUSE' if _cf != '' else 'NOT_INUSE')
|
|
|
|
|
|
|
|
|
|
+async def getUsersStates():
|
|
|
|
|
+ states = {}
|
|
|
|
|
+ uStates = await amiExtensionStateList()
|
|
|
|
|
+ pStates = await amiPresenceStateList()
|
|
|
|
|
+ for user, uState in uStates.items():
|
|
|
|
|
+ if (uState == 'idle') and (user in pStates.keys()):
|
|
|
|
|
+ if pStates[user] in ('not_set','available', 'xa', 'chat'):
|
|
|
|
|
+ states[user] = 'available'
|
|
|
|
|
+ else:
|
|
|
|
|
+ states[user] = pStates[user]
|
|
|
|
|
+ else:
|
|
|
|
|
+ states[user] = uState
|
|
|
|
|
+ return states
|
|
|
|
|
+
|
|
|
|
|
+@app.route('/users/states')
|
|
|
|
|
+class UsersStates(Resource):
|
|
|
|
|
+ @app.response(HTTPStatus.OK, 'JSON map of form {user1:state1, user2:state2, ...}')
|
|
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
|
|
+ async def get(self):
|
|
|
|
|
+ '''Returns all users with their states.
|
|
|
|
|
+ Possible states are: available, away, dnd, inuse, busy, unavailable, ringing, inuse&ringing, hold, inuse&hold
|
|
|
|
|
+ '''
|
|
|
|
|
+ return await getUsersStates()
|
|
|
|
|
+
|
|
|
@app.route('/user/<user>/presence')
|
|
@app.route('/user/<user>/presence')
|
|
|
class UserPresenceState(Resource):
|
|
class UserPresenceState(Resource):
|
|
|
@app.param('user', 'User to query for presence state', 'path')
|
|
@app.param('user', 'User to query for presence state', 'path')
|