Skip to content

Commit 08e2121

Browse files
author
Steve Howell
committed
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`.
1 parent 839bbf0 commit 08e2121

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

zulip_bots/zulip_bots/lib.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
200200
print("\n\t{}".format(bot_details['description']))
201201
print(message_handler.usage())
202202

203-
def handle_message(message):
203+
def handle_message(message, flags):
204204
# type: (Dict[str, Any]) -> None
205205
logging.info('waiting for next message')
206206

207-
# is_mentioned is true if the bot is mentioned at ANY position (not necessarily
208-
# the first @mention in the message).
209-
is_mentioned = message['is_mentioned']
207+
# `mentioned` will be in `flags` if the bot is mentioned at ANY position
208+
# (not necessarily the first @mention in the message).
209+
is_mentioned = 'mentioned' in flags
210210
is_private_message = is_private_message_from_another_user(message, restricted_client.user_id)
211211

212212
# Strip at-mention botname from the message
@@ -227,4 +227,10 @@ def handle_message(message):
227227
signal.signal(signal.SIGINT, exit_gracefully)
228228

229229
logging.info('starting message handling...')
230-
client.call_on_each_message(handle_message)
230+
231+
def event_callback(event):
232+
# type: (Dict[str, str]) -> None
233+
if event['type'] == 'message':
234+
handle_message(event['message'], event['flags'])
235+
236+
client.call_on_each_event(event_callback, ['message'])

0 commit comments

Comments
 (0)