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'])
|
@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))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ 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():
|
||||||
self.__setattr__(arg, value)
|
if arg != 'args':
|
||||||
|
self.__setattr__(arg, value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build(cls, msg):
|
def build(cls, msg):
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue