The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(slack): slash payload decoding lives in adapter_slash_payload
Tekniuma7010c4913d9
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.pyindex 95cb97c839a..27fa637e09b 100644--- a/plugins/platforms/slack/adapter.py+++ b/plugins/platforms/slack/adapter.py@@ -52,10 +52,12 @@ from gateway.platforms.base import ()from gateway.platforms.event import MessageEvent, MessageType, ProcessingOutcome-try: # sibling module; support both package and flat plugin-dir import+try: # sibling modules; support both package and flat plugin-dir importfrom .block_kit import render_blocks, sanitize_blocks+ from .adapter_slash_payload import slash_command_text, slash_thread_idexcept ImportError: # pragma: no cover - plugin loaded outside package contextfrom block_kit import render_blocks, sanitize_blocks # type: ignore+ from adapter_slash_payload import slash_command_text, slash_thread_id # type: ignorelogger = logging.getLogger(__name__)@@ -6062,8 +6064,8 @@ class SlackAdapter(BasePlatformAdapter):team_id = command.get("team_id", "")if team_id and channel_id:self._remember_channel_team(channel_id, team_id)- text = self._slash_command_text(command)- thread_id = self._slash_thread_id(command)+ text = slash_command_text(command)+ thread_id = slash_thread_id(command)if self._slash_channel_gated(channel_id):logger.debug("[Slack] Ignoring slash command in ignored/non-allowed channel: %s", channel_id)return@@ -6114,40 +6116,6 @@ class SlackAdapter(BasePlatformAdapter):finally:_slash_user_id.reset(_slash_user_id_token)- @staticmethod- def _slash_command_text(command: dict) -> str:- """Gateway message text for a slash payload. Native slashes keep Slack's raw argument- payload verbatim (internal/trailing spacing). ``/hermes`` (or a missing ``command``) maps- ``<subcommand> [args]`` via the registry, else free-form text is a regular question."""- slash_name = (command.get("command") or "").lstrip("/").strip()- raw_text = str(command.get("text") or "")- if slash_name not in {"hermes", ""}:- return f"/{slash_name}" if not raw_text else f"/{slash_name} {raw_text}"- legacy_text = raw_text.strip()- from hermes_cli.commands_platforms import slack_subcommand_map- subcommand_map = slack_subcommand_map()- subcommand_map["compact"] = "/compress"- first_word = legacy_text.split()[0] if legacy_text.split() else ""- if first_word in subcommand_map:- rest = legacy_text[len(first_word) :].strip()- mapped = subcommand_map[first_word]- return f"{mapped} {rest}".strip() if rest else mapped- return legacy_text or "/help"-- @staticmethod- def _slash_thread_id(command: dict) -> Optional[str]:- """Thread anchor for a slash payload so session-scoped commands (``/model``)- hit the same thread session. Shape varies by surface: top-level or nested- ``message``/``container``; ``thread_ts`` preferred over ``message_ts``."""- nested = (command.get(k) for k in ("message", "container"))- candidates = [command] + [n for n in nested if isinstance(n, dict)]- for ts_key in ("thread_ts", "message_ts"):- for payload in candidates:- value = payload.get(ts_key)- if value:- return str(value)- return None-def _stash_slash_context(self, team_id: str, channel_id: str, user_id: str, response_url: str) -> None:"""Remember a slash ``response_url`` (+ user for the postEphemeral fallback),diff --git a/plugins/platforms/slack/adapter_slash_payload.py b/plugins/platforms/slack/adapter_slash_payload.pynew file mode 100644index 00000000000..f6c72523796--- /dev/null+++ b/plugins/platforms/slack/adapter_slash_payload.py@@ -0,0 +1,39 @@+"""Slack slash-command payload decoding: the gateway text and the thread anchor of a slash."""++from __future__ import annotations++from typing import Optional+++def slash_command_text(command: dict) -> str:+ """Gateway message text for a slash payload. Native slashes keep Slack's raw argument+ payload verbatim (internal/trailing spacing). ``/hermes`` (or a missing ``command``) maps+ ``<subcommand> [args]`` via the registry, else free-form text is a regular question."""+ slash_name = (command.get("command") or "").lstrip("/").strip()+ raw_text = str(command.get("text") or "")+ if slash_name not in {"hermes", ""}:+ return f"/{slash_name}" if not raw_text else f"/{slash_name} {raw_text}"+ legacy_text = raw_text.strip()+ from hermes_cli.commands_platforms import slack_subcommand_map+ subcommand_map = slack_subcommand_map()+ subcommand_map["compact"] = "/compress"+ first_word = legacy_text.split()[0] if legacy_text.split() else ""+ if first_word in subcommand_map:+ rest = legacy_text[len(first_word) :].strip()+ mapped = subcommand_map[first_word]+ return f"{mapped} {rest}".strip() if rest else mapped+ return legacy_text or "/help"+++def slash_thread_id(command: dict) -> Optional[str]:+ """Thread anchor for a slash payload so session-scoped commands (``/model``)+ hit the same thread session. Shape varies by surface: top-level or nested+ ``message``/``container``; ``thread_ts`` preferred over ``message_ts``."""+ nested = (command.get(k) for k in ("message", "container"))+ candidates = [command] + [n for n in nested if isinstance(n, dict)]+ for ts_key in ("thread_ts", "message_ts"):+ for payload in candidates:+ value = payload.get(ts_key)+ if value:+ return str(value)+ return None