Skip to content

Commit 09cd766

Browse files
Fix: [AEA-5868] - fix for bots only replying to applicable threads (#205)
## Summary **Remove items from this list if they are not relevant. Remove this line once this has been done** - Routine Change - ❗ Breaking Change - 🤖 Operational or Infrastructure Change - ✨ New Feature - ⚠️ Potential issues that might be caused by this change ### Details Add any summary information of what is in the change. **Remove this line if you have nothing to add.** ## Pull Request Naming Pull requests should be named using the following format: ```text Tag: [AEA-NNNN] - Short description ``` Tag can be one of: - `Fix` - for a bug fix. (Patch release) - `Update` - either for a backwards-compatible enhancement or for a rule change that adds reported problems. (Patch release) - `New` - implemented a new feature. (Minor release) - `Breaking` - for a backwards-incompatible enhancement or feature. (Major release) - `Docs` - changes to documentation only. (Patch release) - `Build` - changes to build process only. (No release) - `Upgrade` - for a dependency upgrade. (Patch release) - `Chore` - for refactoring, adding tests, etc. (anything that isn't user-facing). (Patch release) If the current release is x.y.z then - a patch release increases z by 1 - a minor release increases y by 1 - a major release increases x by 1 Correct tagging is necessary for our automated versioning and release process. The description of your pull request will be used as the commit message for the merge, and also be included in the changelog. Please ensure that your title is sufficiently descriptive. ### Rerunning Checks If you need to rename your pull request, you can restart the checks by either: - Closing and reopening the pull request - pushing an empty commit ```bash git commit --allow-empty -m 'trigger build' git push ``` - Amend your last commit and force push to the branch ```bash git commit --amend --no-edit git push --force ``` Rerunning the checks from within the pull request will not use the updated title.
1 parent 4845c5c commit 09cd766

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

packages/slackBotFunction/app/utils/handler_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ def should_reply_to_message(event: Dict[str, Any], client: WebClient = None) ->
292292
Conditions:
293293
should not reply if:
294294
- Message is in a group chat (channel_type == 'group') but not in a thread
295-
- Message is in a channel thread where the bot was not initially mentioned
295+
- Message is in a channel or group thread where the bot was not initially mentioned
296296
"""
297297

298298
# we don't reply to non-threaded messages in group chats
299299
if event.get("channel_type") == "group" and event.get("type") == "message" and event.get("thread_ts") is None:
300300
return False
301301

302-
# for channel threads, check if bot was mentioned anywhere in the thread history
303-
if event.get("channel_type") == "channel" and event.get("thread_ts"):
302+
# for channel or group threads, check if bot was mentioned anywhere in the thread history
303+
if event.get("channel_type") in ["channel", "group"] and event.get("thread_ts"):
304304
if not client:
305305
logger.warning("No Slack client provided to check thread participation")
306306
return True

packages/slackBotFunction/tests/test_handler_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,44 @@ def test_was_bot_mentioned_later_in_thread(mock_env: Mock):
527527
assert result is True
528528

529529

530+
def test_should_reply_to_message_group_thread_with_bot_mention(mock_env: Mock):
531+
"""test should_reply_to_message returns True for group thread where bot was mentioned"""
532+
mock_client = Mock()
533+
mock_client.auth_test.return_value = {"ok": True, "user_id": "U123"}
534+
mock_client.conversations_replies.return_value = {
535+
"ok": True,
536+
"messages": [{"text": "<@U123> help me", "ts": "1234567890.123456"}],
537+
}
538+
539+
if "app.utils.handler_utils" in sys.modules:
540+
del sys.modules["app.utils.handler_utils"]
541+
from app.utils.handler_utils import should_reply_to_message
542+
543+
event = {"channel_type": "group", "type": "message", "channel": "G123", "thread_ts": "1234567890.123456"}
544+
result = should_reply_to_message(event, mock_client)
545+
546+
assert result is True
547+
548+
549+
def test_should_reply_to_message_group_thread_without_bot_mention(mock_env: Mock):
550+
"""test should_reply_to_message returns False for group thread where bot was not mentioned"""
551+
mock_client = Mock()
552+
mock_client.auth_test.return_value = {"ok": True, "user_id": "U123"}
553+
mock_client.conversations_replies.return_value = {
554+
"ok": True,
555+
"messages": [{"text": "some discussion", "ts": "1234567890.123456"}],
556+
}
557+
558+
if "app.utils.handler_utils" in sys.modules:
559+
del sys.modules["app.utils.handler_utils"]
560+
from app.utils.handler_utils import should_reply_to_message
561+
562+
event = {"channel_type": "group", "type": "message", "channel": "G123", "thread_ts": "1234567890.123456"}
563+
result = should_reply_to_message(event, mock_client)
564+
565+
assert result is False
566+
567+
530568
def test_get_bot_user_id_auth_test_fails(mock_env: Mock):
531569
"""test get_bot_user_id returns None when auth_test fails"""
532570
mock_client = Mock()

0 commit comments

Comments
 (0)