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

View file

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

View file

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