feat(slack): support !cmd as alternate prefix for slash commands in threads (#25355)
Slack platform-blocks native slash commands inside thread replies ("/queue
is not supported in threads. Sorry!") and there is no app-side setting to
re-enable them. As a workaround, rewrite a leading '!' to '/' for any known
gateway command before downstream processing — so '!queue', '!stop',
'!model gpt-5.4' etc. work inside Slack threads (and anywhere else).
Only the first token is checked against is_gateway_known_command(), so
casual messages like '!nice work' pass through to the agent unchanged.
Downstream pipeline (MessageType.COMMAND tagging, gateway dispatcher,
thread reply routing) is unchanged.
Adds 6 tests covering rewrite, args preservation, thread routing,
casual-message passthrough, '@bot' suffix, and plain '/' still-works.
This commit is contained in:
@@ -1799,6 +1799,26 @@ class SlackAdapter(BasePlatformAdapter):
|
||||
return
|
||||
|
||||
original_text = event.get("text", "")
|
||||
|
||||
# Slack blocks native slash commands inside threads ("/queue is not
|
||||
# supported in threads. Sorry!"). As a workaround, recognise a
|
||||
# leading ``!`` as an alternate command prefix and rewrite it to
|
||||
# ``/`` so the rest of the pipeline (MessageType.COMMAND tagging,
|
||||
# gateway dispatcher) handles it like a normal slash command. Only
|
||||
# rewrite when the first token resolves to a known gateway command
|
||||
# so casual messages like "!nice work" pass through unchanged.
|
||||
if original_text.startswith("!"):
|
||||
try:
|
||||
from hermes_cli.commands import is_gateway_known_command
|
||||
first_token = original_text[1:].split(maxsplit=1)[0]
|
||||
# Strip "@suffix" the same way get_command() does, so
|
||||
# forms like ``!stop@hermes`` still resolve.
|
||||
cmd_name = first_token.split("@", 1)[0].lower()
|
||||
if cmd_name and "/" not in cmd_name and is_gateway_known_command(cmd_name):
|
||||
original_text = "/" + original_text[1:]
|
||||
except Exception: # pragma: no cover - defensive
|
||||
pass
|
||||
|
||||
text = original_text
|
||||
|
||||
# Extract quoted/forwarded content from Slack blocks.
|
||||
|
||||
Reference in New Issue
Block a user