Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions plugins/platforms/slack/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3936,10 +3936,13 @@ def _build_identity_prompt(self, team_id: str = "") -> str:
return ""
return (
f"You are connected to this Slack workspace as the bot "
f'"@{name}". In messages, each line is prefixed with the sender\'s '
f"name, and mentions are shown as @DisplayName. Only treat a "
f'message as directed at you when it mentions "@{name}" '
f"specifically; a mention of any other participant is not a "
f'"@{name}". The adapter already applied mention and channel '
f"routing; treat every delivered turn as intentionally routed to "
f'you. Your routing mention "@{name}" may have been stripped from '
f'the visible text — do not reject or ignore a message solely '
f'because "@{name}" is absent. In messages, each line is prefixed '
f"with the sender's name, and visible mentions are shown as "
f"@DisplayName; a mention of any other participant is not a "
f"mention of you, even if their name is similar."
)

Expand Down
32 changes: 32 additions & 0 deletions tests/gateway/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,38 @@ async def test_channel_mention_strips_bot_id(self, adapter):
assert msg_event.text == "what's the weather?"
assert "<@U_BOT>" not in msg_event.text

@pytest.mark.asyncio
async def test_accepted_mention_prompt_trusts_adapter_routing(self, adapter):
"""Cleaned text must not make the model revalidate an accepted mention."""
adapter.config.extra.update({"require_mention": True, "strict_mention": True})
adapter._bot_display_name = "TestBot"
adapter._team_bot_names = {"T123": "WorkspaceBot"}
event = {
"text": "<@U_BOT> Hi",
"user": "U_USER",
"channel": "C123",
"channel_type": "channel",
"team": "T123",
"ts": "1234567890.000001",
}

await adapter._handle_slack_message(event)

adapter.handle_message.assert_awaited_once()
msg_event = adapter.handle_message.await_args.args[0]
prompt = msg_event.channel_prompt
assert msg_event.text == "Hi"
assert "@WorkspaceBot" in prompt
assert "already applied" in prompt
assert "may have been stripped" in prompt
assert "do not reject or ignore" in prompt
assert "intentionally routed" in prompt
assert "not a mention of you" in prompt
assert "Only treat a message as directed" not in prompt

@pytest.mark.asyncio



@pytest.mark.asyncio
async def test_allow_bots_mentions_ignores_bot_user_without_current_mention(
Expand Down
Loading