diff --git a/platypush/backend/http/app/routes/hook.py b/platypush/backend/http/app/routes/hook.py index bcf33c500..8d49530cb 100644 --- a/platypush/backend/http/app/routes/hook.py +++ b/platypush/backend/http/app/routes/hook.py @@ -6,6 +6,7 @@ from flask.wrappers import Response from platypush.backend.http.app import template_folder from platypush.backend.http.app.utils import logger, send_message from platypush.config import Config +from platypush.event.hook import EventCondition from platypush.message.event.http.hook import WebhookEvent @@ -17,6 +18,16 @@ __routes__ = [ ] +def matches_condition(event: WebhookEvent, hook): + if isinstance(hook, dict): + condition = hook.get('condition', {}) + else: + condition = hook.condition + + condition = EventCondition.build(condition) + return event.matches_condition(condition) + + @hook.route( '/hook/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'] ) @@ -43,10 +54,7 @@ def hook_route(hook_name): matching_hooks = [ hook for hook in Config.get_event_hooks().values() - if hook.condition.type == WebhookEvent - and hook.condition.args.get('hook') == hook_name - and request.method.lower() - == hook.condition.args.get('method', request.method).lower() + if matches_condition(event, hook) ] try: