From 08e212138d8b389f054ca9ce12a799ca91798cfd Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 20 Oct 2017 16:35:21 -0700 Subject: [PATCH] Look for `mentioned` in `flags`. The Zulip server, starting in 1.7, no longer sends `is_mentioned` in the message payload, and it was buggy in earlier versions, so now we check `flags`. --- zulip_bots/zulip_bots/lib.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index 5c5b63d..ef316ed 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -200,13 +200,13 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name): print("\n\t{}".format(bot_details['description'])) print(message_handler.usage()) - def handle_message(message): + def handle_message(message, flags): # type: (Dict[str, Any]) -> None logging.info('waiting for next message') - # is_mentioned is true if the bot is mentioned at ANY position (not necessarily - # the first @mention in the message). - is_mentioned = message['is_mentioned'] + # `mentioned` will be in `flags` if the bot is mentioned at ANY position + # (not necessarily the first @mention in the message). + is_mentioned = 'mentioned' in flags is_private_message = is_private_message_from_another_user(message, restricted_client.user_id) # Strip at-mention botname from the message @@ -227,4 +227,10 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name): signal.signal(signal.SIGINT, exit_gracefully) logging.info('starting message handling...') - client.call_on_each_message(handle_message) + + def event_callback(event): + # type: (Dict[str, str]) -> None + if event['type'] == 'message': + handle_message(event['message'], event['flags']) + + client.call_on_each_event(event_callback, ['message'])