From ccda105d1d4b477dc13de8272a7917fda5156abf Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Thu, 21 Sep 2023 15:37:23 +0530 Subject: [PATCH] bot_server: Support trigger private_message renamed to direct_message. The JSON payload that Zulip server POST for outgoing webhooks has 'trigger' as one of the fields. In https://github.com/zulip/zulip/commit/c4e4737, we renamed the 'private_message' value to 'direct_message'. This commit adds support to the botserver for handling 'direct_message' as a trigger value. It still supports 'private_message' for self-hosted server compatibility. --- zulip_botserver/zulip_botserver/server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index 17d051180..100bc1d16 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -201,7 +201,9 @@ def handle_bot() -> str: bot_handler = app.config.get("BOT_HANDLERS", {})[bot] message_handler = app.config.get("MESSAGE_HANDLERS", {})[bot] is_mentioned = event["trigger"] == "mention" - is_private_message = event["trigger"] == "private_message" + # TODO/compatibility: Remove the support for "private_message" as a valid + # trigger value once we no longer support pre-8.0 Zulip servers. + is_direct_message = event["trigger"] in ["direct_message", "private_message"] message = event["message"] message["full_content"] = message["content"] # Strip at-mention botname from the message @@ -212,7 +214,7 @@ def handle_bot() -> str: if message["content"] is None: return json.dumps(dict(response_not_required=True)) - if is_private_message or is_mentioned: + if is_direct_message or is_mentioned: message_handler.handle_message(message=message, bot_handler=bot_handler) return json.dumps(dict(response_not_required=True))