feat(gateway): add @-mention-only filter for Mattermost channels
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 #2174
This commit is contained in:
parent
4bded44b6a
commit
fbbe9e6030
1 changed files with 18 additions and 0 deletions
|
|
@ -580,6 +580,24 @@ class MattermostAdapter(BasePlatformAdapter):
|
||||||
# For DMs, user_id is sufficient. For channels, check for @mention.
|
# For DMs, user_id is sufficient. For channels, check for @mention.
|
||||||
message_text = post.get("message", "")
|
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.
|
# Resolve sender info.
|
||||||
sender_id = post.get("user_id", "")
|
sender_id = post.get("user_id", "")
|
||||||
sender_name = data.get("sender_name", "").lstrip("@") or sender_id
|
sender_name = data.get("sender_name", "").lstrip("@") or sender_id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue