-
Notifications
You must be signed in to change notification settings - Fork 46.4k
feat(slack): make bot mention stripping configurable #47536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
replygirl
wants to merge
1
commit into
NousResearch:main
from
replygirl:fix/slack-strip-bot-mentions
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2522,9 +2522,10 @@ async def _handle_slack_message(self, event: dict) -> None: | |
| ): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current main migrated the active Slack adapter to |
||
| return | ||
|
|
||
| if is_mentioned: | ||
| if is_mentioned and self._slack_strip_bot_mentions(): | ||
| # Strip the bot mention from the text | ||
| text = text.replace(f"<@{bot_uid}>", "").strip() | ||
| if is_mentioned: | ||
| # Register this thread so all future messages auto-trigger the bot. | ||
| # Skipped in strict mode: strict_mention=true bots must be | ||
| # re-mentioned every turn, so remembering the thread would | ||
|
|
@@ -3410,7 +3411,7 @@ async def _fetch_thread_context( | |
| continue | ||
|
|
||
| # Strip bot mentions from context messages | ||
| if bot_uid: | ||
| if bot_uid and self._slack_strip_bot_mentions(): | ||
| msg_text = msg_text.replace(f"<@{bot_uid}>", "").strip() | ||
|
|
||
| prefix = "[thread parent] " if is_parent else "" | ||
|
|
@@ -3480,7 +3481,7 @@ async def _fetch_thread_parent_text( | |
| return "" | ||
| bot_uid = self._team_bot_user_ids.get(team_id, self._bot_user_id) | ||
| text = (parent.get("text") or "").strip() | ||
| if bot_uid: | ||
| if bot_uid and self._slack_strip_bot_mentions(): | ||
| text = text.replace(f"<@{bot_uid}>", "").strip() | ||
| return text | ||
| except Exception as exc: # pragma: no cover - defensive | ||
|
|
@@ -3780,6 +3781,24 @@ def _slack_strict_mention(self) -> bool: | |
| "on", | ||
| } | ||
|
|
||
| def _slack_strip_bot_mentions(self) -> bool: | ||
| """Return whether Slack bot mention tokens are removed from prompt text. | ||
|
|
||
| Defaults to True to preserve existing behavior. Explicit false values | ||
| keep the raw ``<@U...>`` tokens in current and fetched thread text. | ||
| """ | ||
| configured = self.config.extra.get("strip_bot_mentions") | ||
| if configured is not None: | ||
| if isinstance(configured, str): | ||
| return configured.lower() not in {"false", "0", "no", "off"} | ||
| return bool(configured) | ||
| return os.getenv("SLACK_STRIP_BOT_MENTIONS", "true").lower() not in { | ||
| "false", | ||
| "0", | ||
| "no", | ||
| "off", | ||
| } | ||
|
|
||
| def _slack_free_response_channels(self) -> set: | ||
| """Return channel IDs where no @mention is required.""" | ||
| raw = self.config.extra.get("free_response_channels") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current main delegates Slack YAML-to-environment translation to
plugins/platforms/slack/adapter.py::_apply_yaml_config(gateway/config.py:1269-1309). Add this bridge to that plugin hook rather than the removed core Slack configuration block.