Skip to content

feat(gateway): add @-mention-only filter for Mattermost channels#2279

Closed
vernonstinebaker wants to merge 1 commit into
NousResearch:mainfrom
vernonstinebaker:feat/mattermost-mention-only-filter
Closed

feat(gateway): add @-mention-only filter for Mattermost channels#2279
vernonstinebaker wants to merge 1 commit into
NousResearch:mainfrom
vernonstinebaker:feat/mattermost-mention-only-filter

Conversation

@vernonstinebaker

Copy link
Copy Markdown

What does this PR do?

Adds @-mention-only filtering to the Mattermost gateway adapter. The bot now only responds to messages in channels and groups when it is explicitly @-mentioned. DMs are always processed without filtering.

Currently, the Mattermost adapter processes every message from other users in channels, creating noise and unnecessary API calls. This brings Mattermost in line with Discord and Slack adapters which already filter for mentions.

Related Issue

Fixes #2174

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

  • gateway/platforms/mattermost.py: Added mention detection in _handle_post() after the existing "For channels, check for @mention" comment (line 580). Non-DM messages without a matching @username or @user_id in the message text are skipped with a debug log.

How to Test

  1. Connect the bot to a Mattermost server with MATTERMOST_ALLOW_ALL_USERS=true
  2. Send a message in a channel without @-mentioning the bot — it should not respond
  3. Send a message in a channel with @hermes-agent — it should respond normally
  4. Send a DM to the bot — it should respond without requiring a mention
  5. Check logs for Mattermost: skipping non-DM message without @mention debug entries

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (feat(gateway): ...)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've tested on my platform: Docker (python:3.12-slim on macOS/OrbStack)

Documentation & Housekeeping

  • I've considered cross-platform impact (Windows, macOS) — or N/A (WebSocket filtering is platform-independent)
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

The Mattermost adapter now only responds to messages in channels and
groups when the bot is @-mentioned. DMs are always processed without
filtering.

Detection checks both the bot's @username and user ID in the message
text, providing a reliable fallback when the structured mentions field
is unavailable.

Fixes NousResearch#2174
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #2443. Cherry-picked with authorship preserved. Thanks for the clean contribution!

@teknium1 teknium1 closed this Mar 22, 2026
@vernonstinebaker vernonstinebaker deleted the feat/mattermost-mention-only-filter branch March 22, 2026 13:46
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.

Feature: @-mention-only mode for Mattermost gateway adapter

2 participants