Fixed webhook event management

This commit is contained in:
Fabio Manganiello 2020-05-09 01:47:12 +02:00
parent 80d5a6ad19
commit aa66b81b7b
3 changed files with 9 additions and 9 deletions

View file

@ -18,7 +18,7 @@ __routes__ = [
@hook.route('/hook/<hook_name>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']) @hook.route('/hook/<hook_name>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@authenticate(skip_auth_methods=['session']) @authenticate(skip_auth_methods=['session'])
def hook(hook_name): def _hook(hook_name):
""" Endpoint for custom webhooks """ """ Endpoint for custom webhooks """
event_args = { event_args = {
@ -29,6 +29,7 @@ def hook(hook_name):
} }
if event_args['data']: if event_args['data']:
# noinspection PyBroadException
try: try:
event_args['data'] = json.loads(event_args['data']) event_args['data'] = json.loads(event_args['data'])
except: except:
@ -37,12 +38,11 @@ def hook(hook_name):
event = WebhookEvent(**event_args) event = WebhookEvent(**event_args)
try: try:
response = send_message(event) send_message(event)
return Response(json.dumps({'status': 'ok', **event_args}), return Response(json.dumps({'status': 'ok', **event_args}), mimetype='application/json')
mimetype='application/json')
except Exception as e: except Exception as e:
logger().error('Error while dispatching webhook event {}: {}'. logger().exception(e)
format(event, str(e))) logger().error('Error while dispatching webhook event {}: {}'.format(event, str(e)))
abort(500, str(e)) abort(500, str(e))

View file

@ -40,6 +40,7 @@ class Event(Message):
self.disable_web_clients_notification = disable_web_clients_notification self.disable_web_clients_notification = disable_web_clients_notification
for arg, value in self.args.items(): for arg, value in self.args.items():
if arg != 'args':
self.__setattr__(arg, value) self.__setattr__(arg, value)
@classmethod @classmethod

View file

@ -20,8 +20,7 @@ class WebhookEvent(Event):
:type args: dict :type args: dict
""" """
super().__init__(hook=hook, method=method, data=data, super().__init__(hook=hook, method=method, data=data, args=args or {}, *argv, **kwargs)
args=args or {}, *argv, **kwargs)
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: