@@ -234,12 +234,23 @@ def zdaemon_slack_router(triggers, ack, say, message):
234
234
# print ("zdaemon_slack_router event: %s[%s]/%s" %
235
235
# (message['type'], message['channel_type'],
236
236
# message['subtype'] if 'subtype' in message else 'None'))
237
+ # -- and/or --
238
+ # print(message)
237
239
238
-
239
- bridge_bot_message = False
240
+ bot_message = False # A message from any bot
241
+ bridge_bot_message = False # A message specifically from the bridge bot
240
242
if ('subtype' in message and
241
- message ['subtype' ] == 'bot_message' and
243
+ message ['subtype' ] == 'bot_message' or
242
244
'bot_id' in message ):
245
+ # Classic bots use the 'bot_message' subtype, but modern apps do not.
246
+ # Regardless, all bots should include a bot_id.
247
+ #
248
+ # This check is therefore slightly more conservative than we need,
249
+ # but we really don't want to find ourselves handling bot messages
250
+ # unexpectedly.
251
+ bot_message = True
252
+
253
+ if (bot_message and 'bot_id' in message ):
243
254
# Need to look up the bot and add the user id to the message.
244
255
userid = get_slack_bot_userid (message ['bot_id' ])
245
256
message ['user' ] = userid
@@ -254,6 +265,9 @@ def zdaemon_slack_router(triggers, ack, say, message):
254
265
# so only do true messages (no subtype) and replies for now. (note: slack doesn't actually appear
255
266
# to send the message_replied subtype as of Sep 2024)
256
267
#
268
+ # Note: You really want to do this first before any other check, since we might get a bot
269
+ # loop via the other sanity checks below.
270
+ #
257
271
# This gets rid of bot_message explicity (so we avoid loops with other bots), which is nice,
258
272
# but also removes troublesome things like message_changed and message_deleted which would
259
273
# need their own very specific handling.
@@ -270,14 +284,14 @@ def zdaemon_slack_router(triggers, ack, say, message):
270
284
# channel. These seem to be paried with a message_changed, which thankfully don't
271
285
# seem to be relevant for our purposes.
272
286
#
273
- # Note: You really want to do this first before any other check, since we might get a bot
274
- # loop via the other sanity checks below.
287
+ # Apologies for the complexity of this check. It could almost certainly be better.
275
288
if ('subtype' in message and
276
- (message ['subtype' ] not in ['thread_broadcast' ,
277
- 'message_replied' ,
278
- 'file_share' ,
279
- 'bot_message' ] or
280
- (message ['subtype' ] == 'bot_message' and not bridge_bot_message ))):
289
+ (message ['subtype' ] not in ['thread_broadcast' ,
290
+ 'message_replied' ,
291
+ 'file_share' ,
292
+ 'bot_message' ] or
293
+ (message ['subtype' ] == 'bot_message' and not bridge_bot_message )) or
294
+ bot_message and not bridge_bot_message ):
281
295
# DEBUG
282
296
# print("zdaemon_slack_router ignoring message: %s" % message)
283
297
return
0 commit comments