Merge pull request #2443 from NousResearch/hermes/hermes-31d7db3b

feat(gateway): add @-mention-only filter for Mattermost channels
This commit is contained in:
Teknium 2026-03-22 03:50:35 -07:00 committed by GitHub
commit cd6d24f111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -580,6 +580,24 @@ class MattermostAdapter(BasePlatformAdapter):
# For DMs, user_id is sufficient. For channels, check for @mention.
message_text = post.get("message", "")
# Mention-only mode: skip channel messages that don't @mention the bot.
# DMs (type "D") are always processed.
if channel_type_raw != "D":
mention_patterns = [
f"@{self._bot_username}",
f"@{self._bot_user_id}",
]
has_mention = any(
pattern.lower() in message_text.lower()
for pattern in mention_patterns
)
if not has_mention:
logger.debug(
"Mattermost: skipping non-DM message without @mention (channel=%s)",
channel_id,
)
return
# Resolve sender info.
sender_id = post.get("user_id", "")
sender_name = data.get("sender_name", "").lstrip("@") or sender_id