Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot_server: Support trigger value private_message renamed to direct_message. #791

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

prakhar1144
Copy link
Member

CZO Discussion

The JSON payload that Zulip server POST for outgoing webhooks has trigger as one of the fields.

In zulip/zulip@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.

@prakhar1144
Copy link
Member Author

prakhar1144 commented Sep 21, 2023

I didn't rename private_message to direct_message in these places:

zulip/integrations/jabber/jabber_mirror_backend.py:                    self.private_message(message)
zulip/integrations/jabber/jabber_mirror_backend.py:    def private_message(self, msg: Dict[str, Any]) -> None:
zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py:    def test_private_message_error(self) -> None:
zulip_bots/zulip_bots/lib.py:def is_private_message_but_not_group_pm(
zulip_bots/zulip_bots/lib.py:        is_private_message = is_private_message_but_not_group_pm(message, restricted_client)
zulip_bots/zulip_bots/lib.py:        if is_private_message or is_mentioned:
zulip_bots/zulip_bots/tests/test_lib.py:    is_private_message_but_not_group_pm,
zulip_bots/zulip_bots/tests/test_lib.py:    def test_is_private_message_but_not_group_pm(self):
zulip_bots/zulip_bots/tests/test_lib.py:        self.assertFalse(is_private_message_but_not_group_pm(message, handler))
zulip_bots/zulip_bots/tests/test_lib.py:        self.assertFalse(is_private_message_but_not_group_pm(message, handler))
zulip_bots/zulip_bots/tests/test_lib.py:        self.assertTrue(is_private_message_but_not_group_pm(message, handler))
zulip_bots/zulip_bots/tests/test_lib.py:        self.assertFalse(is_private_message_but_not_group_pm(message, handler))

as they are related to message["type"] == "private". We should rename it while changing the type from private to direct.

This PR is restricted to handling the outgoing webhook issue we encountered.

@@ -201,7 +201,7 @@ 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"
is_direct_message = event["trigger"] in ["direct_message", "private_message"]
Copy link
Member Author

@prakhar1144 prakhar1144 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a TODO/compatibility comment here to remove private_message in future? I don't see it included in
Zulip PyPI packages release checklist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it would be valuable to put that kind of comment here to have a record why this is needed and to remove it at some point

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment:

    # TODO/compatibility: Remove the support for "private_message" as a valid
    # trigger value when one can no longer directly upgrade from 0.8.x to main.

@mateuszmandera
Copy link
Contributor

Looks good to me

The JSON payload that Zulip server POST for outgoing webhooks
has 'trigger' as one of the fields.

In zulip/zulip@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.
@timabbott timabbott merged commit ccda105 into zulip:main Sep 21, 2023
@timabbott
Copy link
Member

The compatibility comment was a great idea, but I changed it to state clearly the condition when we remove it -- namely when we no longer support pre-8.0 Zulip servers, since 8.0 will be the first Zulip server release with this change.

I think we can rename the is_private_message_but_not_group_pm to is_non_group_direct_message (and make its implementation check for both direct and private as types -- doing that now will be helpful down the line. API design discussion: https://chat.zulip.org/#narrow/stream/378-api-design/topic/.22private.22.20.3D.3E.20.22direct.22.20in.20message.20type/near/1644682.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants