Fixed webhook event management
This commit is contained in:
parent
80d5a6ad19
commit
aa66b81b7b
3 changed files with 9 additions and 9 deletions
|
@ -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))
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ class Event(Message):
|
|||
self.disable_web_clients_notification = disable_web_clients_notification
|
||||
|
||||
for arg, value in self.args.items():
|
||||
if arg != 'args':
|
||||
self.__setattr__(arg, value)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue