Skip to content

Fix Mattermost @mention detection in group channels#793

Open
anathn wants to merge 1 commit intoRightNow-AI:mainfrom
anathn:fix/mattermost-mention-detection
Open

Fix Mattermost @mention detection in group channels#793
anathn wants to merge 1 commit intoRightNow-AI:mainfrom
anathn:fix/mattermost-mention-detection

Conversation

@anathn
Copy link
Copy Markdown

@anathn anathn commented Mar 22, 2026

Fix Mattermost @mention detection in group channels

Background

The Mattermost channel adapter was parsing incoming WebSocket events but always returned an empty metadata map — meaning there was no way to know if the bot had been directly @mentioned in a group channel.

Mattermost includes a mentions JSON array in the event payload listing the user IDs of anyone mentioned in that message. The fix reads that array and sets was_mentioned: true in the message metadata when the bot's own user ID appears in it. This only applies to group channels since DMs are always directed at the bot.

Summary

  • Parse the mentions JSON array from Mattermost WebSocket event data
  • Set was_mentioned: true in message metadata when the bot's user ID appears in the mentions list
  • Enables agents to distinguish direct @mentions from background group channel traffic

Changes

  • Parse the mentions JSON array from Mattermost WebSocket event data
  • Set was_mentioned: true in message metadata when the bot's user ID appears in the mentions list
  • Enables agents to distinguish direct @mentions from background group channel traffic

Test plan

  • test_parse_mattermost_event_mention_detected — verifies was_mentioned is set when bot ID is in mentions array
  • test_parse_mattermost_event_no_mention — verifies metadata is absent when bot is not mentioned
  • cargo test --workspace passes (1,744+ tests; one pre-existing flaky cron timing test unrelated to this change)
  • cargo clippy --workspace --all-targets -- -D warnings zero warnings
  • cargo fmt --all --check no diff

Testing

  • cargo clippy --workspace --all-targets -- -D warnings passes
  • cargo test --workspace passes
  • Live integration tested (if applicable)

Security

  • No new unsafe code
  • No secrets or API keys in diff
  • User input validated at boundaries — serde_json::from_str(...).unwrap_or_default() handles malformed or missing mentions data by defaulting to an empty vec

Parse the mentions JSON array from Mattermost event data and set
was_mentioned metadata when the bot user ID is present, enabling
agents to distinguish direct mentions from background group traffic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jaberjaber23
Copy link
Copy Markdown
Member

Reviewed and approved. Has merge conflicts with recent changes on main. Please rebase and we will merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants