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`.
This commit is contained in:
Steve Howell 2017-10-20 16:35:21 -07:00
parent 839bbf0db4
commit 08e212138d

View file

@ -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("\n\t{}".format(bot_details['description']))
print(message_handler.usage()) print(message_handler.usage())
def handle_message(message): def handle_message(message, flags):
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any]) -> None
logging.info('waiting for next message') logging.info('waiting for next message')
# is_mentioned is true if the bot is mentioned at ANY position (not necessarily # `mentioned` will be in `flags` if the bot is mentioned at ANY position
# the first @mention in the message). # (not necessarily the first @mention in the message).
is_mentioned = message['is_mentioned'] is_mentioned = 'mentioned' in flags
is_private_message = is_private_message_from_another_user(message, restricted_client.user_id) is_private_message = is_private_message_from_another_user(message, restricted_client.user_id)
# Strip at-mention botname from the message # 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) signal.signal(signal.SIGINT, exit_gracefully)
logging.info('starting message handling...') 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'])