|
@@ -108,7 +108,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.getdict()
|
|
|
|
|
|
|
+ return reply
|
|
|
|
|
|
|
|
@app.route('/ami/getvar/<string:variable>')
|
|
@app.route('/ami/getvar/<string:variable>')
|
|
|
async def amiGetVar(variable):
|
|
async def amiGetVar(variable):
|
|
@@ -231,6 +231,22 @@ async def amiSetHint(context, user, hint):
|
|
|
return True
|
|
return True
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
+async def amiPresenceState(user):
|
|
|
|
|
+ '''AMI PresenceState request for CustomPresence provider
|
|
|
|
|
+
|
|
|
|
|
+ Parameters:
|
|
|
|
|
+ user (string): user
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ string: One of: not_set, unavailable, available, away, xa, chat or dnd
|
|
|
|
|
+ '''
|
|
|
|
|
+ reply = await manager.send_action({'Action': 'PresenceState',
|
|
|
|
|
+ 'Provider': 'CustomPresence:{}'.format(user)})
|
|
|
|
|
+ app.logger.warning('PresenceState({})'.format(user))
|
|
|
|
|
+ if (isinstance(reply, Message) and reply.success):
|
|
|
|
|
+ return reply.state
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
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.
|
|
@@ -351,11 +367,53 @@ 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')
|
|
|
|
|
|
|
|
|
|
+@app.route('/user/<user>/presence')
|
|
|
|
|
+class UserPresenceState(Resource):
|
|
|
|
|
+ @app.param('user', 'User to query for presence state', 'path')
|
|
|
|
|
+ @app.response(HTTPStatus.OK, 'Presence state string')
|
|
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
|
|
+ @app.response(HTTPStatus.NOT_FOUND, 'User does not exist')
|
|
|
|
|
+ @app.response(HTTPStatus.BAD_REQUEST, 'AMI error')
|
|
|
|
|
+ async def get(self, user):
|
|
|
|
|
+ '''Returns user's presence state.
|
|
|
|
|
+ One of: not_set | unavailable | available | away | xa | chat | dnd
|
|
|
|
|
+ '''
|
|
|
|
|
+ cidnum = await getUserCID(user) # Check if user exists in astdb
|
|
|
|
|
+ if cidnum is None:
|
|
|
|
|
+ return '', HTTPStatus.NOT_FOUND
|
|
|
|
|
+ state = await amiPresenceState(user)
|
|
|
|
|
+ if state is None:
|
|
|
|
|
+ return '', HTTPStatus.BAD_REQUEST
|
|
|
|
|
+ return state
|
|
|
|
|
+
|
|
|
|
|
+@app.route('/user/<user>/presence/<state>')
|
|
|
|
|
+class SetUserPresenceState(Resource):
|
|
|
|
|
+ @app.param('user', 'Target user to set the presence state', 'path')
|
|
|
|
|
+ @app.param('state',
|
|
|
|
|
+ 'The presence state to set for user, one of: not_set, unavailable, available, away, xa, chat or dnd',
|
|
|
|
|
+ 'path')
|
|
|
|
|
+ @app.response(HTTPStatus.OK, 'Successfuly set the presence state')
|
|
|
|
|
+ @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
|
|
+ @app.response(HTTPStatus.NOT_FOUND, 'User does not exist')
|
|
|
|
|
+ @app.response(HTTPStatus.BAD_REQUEST, 'Wrong state string ot other AMI error')
|
|
|
|
|
+ async def get(self, user, state):
|
|
|
|
|
+ '''Sets user's presence state.
|
|
|
|
|
+ Allowed states: not_set | unavailable | available | away | xa | chat | dnd
|
|
|
|
|
+ '''
|
|
|
|
|
+ cidnum = await getUserCID(user) # Check if user exists in astdb
|
|
|
|
|
+ if cidnum is None:
|
|
|
|
|
+ return '', HTTPStatus.NOT_FOUND
|
|
|
|
|
+ if await amiSetVar('PRESENCE_STATE(CustomPresence:{})'.format(user),
|
|
|
|
|
+ state):
|
|
|
|
|
+ return ''
|
|
|
|
|
+ else:
|
|
|
|
|
+ return '', HTTPStatus.BAD_REQUEST
|
|
|
|
|
+
|
|
|
@app.route('/device/<device>/<user>/on')
|
|
@app.route('/device/<device>/<user>/on')
|
|
|
@app.route('/user/<user>/<device>/on')
|
|
@app.route('/user/<user>/<device>/on')
|
|
|
class UserDeviceBind(Resource):
|
|
class UserDeviceBind(Resource):
|
|
|
@app.param('device', 'Device number to bind to', 'path')
|
|
@app.param('device', 'Device number to bind to', 'path')
|
|
|
- @app.param('user', 'User user to bind', 'path')
|
|
|
|
|
|
|
+ @app.param('user', 'User to bind to device', 'path')
|
|
|
@app.response(HTTPStatus.OK, 'JSON reply with fields "success" and "result"')
|
|
@app.response(HTTPStatus.OK, 'JSON reply with fields "success" and "result"')
|
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
async def get(self, device, user):
|
|
async def get(self, device, user):
|