Skip to content

Commit 105db19

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 105db19

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

zulip_bots/zulip_bots/lib.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,14 @@ 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+
print(message, flags)
210+
is_mentioned = 'mentioned' in flags
210211
is_private_message = is_private_message_from_another_user(message, restricted_client.user_id)
211212

212213
# Strip at-mention botname from the message
@@ -227,4 +228,10 @@ def handle_message(message):
227228
signal.signal(signal.SIGINT, exit_gracefully)
228229

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

0 commit comments

Comments
 (0)