Skip to content

The agent that grows with you

fix(mattermost): tidy the user-ID setup hint and move the plugin test

kshitijk4poor94bd0837121a
diff --git a/hermes_cli/gateway_setup_wizard.py b/hermes_cli/gateway_setup_wizard.py
index 8214df6fb1a..08b1eea30da 100644
--- a/hermes_cli/gateway_setup_wizard.py
+++ b/hermes_cli/gateway_setup_wizard.py
@@ -26,11 +26,11 @@ _PLATFORMS = [
" (System Console → Integrations → Bot Accounts must be enabled)",
"2. Give it a username (e.g. hermes) and copy the bot token",
"3. Works with any self-hosted Mattermost instance — enter your server URL",
- "4. The profile dialog does not show your user ID.",
- " System Console → User Management → Users → open your user.",
- " The ID is on that User Configuration page.",
- " Or GET /api/v4/users/username/<your-username> and copy id.",
- " /api/v4/users/me with the bot token is the bot's id, not yours.",
+ "4. Find your user ID (the profile dialog does not show it):",
+ " Admins: System Console → User Management → Users → open your user.",
+ " Anyone: while logged in, open <server>/api/v4/users/me in a browser tab.",
+ " With the bot token: GET <server>/api/v4/users/username/<your-username>.",
+ " Copy the \"id\" field. /users/me with the bot token returns the bot's ID.",
" ⚠ This is NOT your username — it's a 26-character alphanumeric ID.",
"5. To get a channel ID: click the channel name → View Info → copy the ID",
],
@@ -41,7 +41,7 @@ _PLATFORMS = [
"help": "Paste the bot token from step 2 above."},
{"name": "MATTERMOST_ALLOWED_USERS", "prompt": "Allowed user IDs (comma-separated)",
"password": False, "is_allowlist": True,
- "help": "Your user ID from the System Console user page, or from GET /api/v4/users/username/<you>."},
+ "help": "Your user ID from step 4 above (26 characters, not your @username)."},
{"name": "MATTERMOST_HOME_CHANNEL",
"prompt": "Home channel ID (for cron/notification delivery, or empty to set later with /set-home)",
"password": False, "help": "Channel ID where Hermes delivers cron results and notifications."},
diff --git a/plugins/platforms/mattermost/adapter.py b/plugins/platforms/mattermost/adapter.py
index 50459ae29de..2ade013fa1b 100644
--- a/plugins/platforms/mattermost/adapter.py
+++ b/plugins/platforms/mattermost/adapter.py
@@ -677,10 +677,11 @@ def interactive_setup() -> None:
print_success("Mattermost token saved")
print()
info("🔒 Security: Restrict who can use your bot",
- " The profile dialog does not show your user ID.",
- " System Console → User Management → Users → open your user,",
- " or GET /api/v4/users/username/<your-username>.",
- " /api/v4/users/me with the bot token is the bot's id, not yours.")
+ " Find your user ID (the profile dialog does not show it):",
+ " Admins: System Console → User Management → Users → open your user.",
+ " Anyone: while logged in, open <server>/api/v4/users/me in a browser tab.",
+ " With the bot token: GET <server>/api/v4/users/username/<your-username>.",
+ " Copy the \"id\" field. /users/me with the bot token returns the bot's ID.")
print()
allowed_users = prompt("Allowed user IDs (comma-separated, leave empty for open access)")
if allowed_users:
diff --git a/tests/gateway/test_mattermost_plugin_setup.py b/tests/gateway/test_mattermost_plugin_setup.py
index 7430b6cfde4..ec2b3369112 100644
--- a/tests/gateway/test_mattermost_plugin_setup.py
+++ b/tests/gateway/test_mattermost_plugin_setup.py
@@ -51,3 +51,14 @@ class TestMattermostHomeChannelClear:
assert "MATTERMOST_HOME_CHANNEL" not in saved
+def test_security_hint_names_a_documented_user_id_lookup(monkeypatch):
+ """The profile dialog has no user ID; the hint must not send people there."""
+ saved, removed, shown = {}, [], []
+ _patch_setup_io(monkeypatch, _PROMPTS_BLANK, saved, removed, existing={})
+ monkeypatch.setattr(cli_output_mod, "print_info", lambda line, *_a, **_kw: shown.append(line))
+ interactive_setup()
+
+ out = "\n".join(shown)
+ assert "User Management" in out
+ assert "/api/v4/users/username/" in out
+ assert "click your avatar" not in out
diff --git a/tests/hermes_cli/test_mattermost_user_id_setup.py b/tests/hermes_cli/test_mattermost_user_id_setup.py
index a5460c5e217..77320b4ab16 100644
--- a/tests/hermes_cli/test_mattermost_user_id_setup.py
+++ b/tests/hermes_cli/test_mattermost_user_id_setup.py
@@ -1,8 +1,8 @@
-"""Mattermost setup must name a user-id lookup Mattermost actually documents.
+"""`hermes gateway setup` → Mattermost must name a user-ID lookup that exists.
-The profile dialog does not show the id. System Console → User Management →
-Users, and GET /api/v4/users/username/<username>, do. /users/me with the bot
-token is the bot.
+The profile dialog does not show the ID. System Console → User Management →
+Users and GET /api/v4/users/username/<username> do; /users/me with the bot
+token returns the bot's own user.
"""
import io
@@ -21,23 +21,5 @@ def test_gateway_setup_points_at_a_documented_user_id(tmp_path, monkeypatch, cap
out = capsys.readouterr().out
assert "User Management" in out
assert "/api/v4/users/username/" in out
- assert "displayed there" not in out
assert "click your avatar" not in out
- assert "bot's id" in out
-
-
-def test_plugin_setup_points_at_a_documented_user_id(tmp_path, monkeypatch, capsys):
- monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- from plugins.platforms.mattermost.adapter import interactive_setup
-
- monkeypatch.setattr(
- "sys.stdin",
- io.StringIO("https://mm.example.com\ntok-abc\nuserid26\n\n"),
- )
- interactive_setup()
-
- out = capsys.readouterr().out
- assert "User Management" in out
- assert "/api/v4/users/username/" in out
- assert "click your avatar" not in out
- assert "bot's id" in out
+ assert "displayed there" not in out
diff --git a/website/docs/user-guide/messaging/mattermost.md b/website/docs/user-guide/messaging/mattermost.md
index e64e53a8ef6..3f40d86dfe6 100644
--- a/website/docs/user-guide/messaging/mattermost.md
+++ b/website/docs/user-guide/messaging/mattermost.md
@@ -102,19 +102,19 @@ For DMs, simply open a direct message with the bot — it will be able to respon
Hermes Agent uses your Mattermost User ID to control who can interact with the bot. The profile dialog (avatar → Profile) does not show it.
-Mattermost documents the ID in three places. See [Identify a user's ID](https://docs.mattermost.com/administration-guide/configure/user-management-configuration-settings.html#identify-a-users-id):
+Use one of these (see Mattermost's [Identify a user's ID](https://docs.mattermost.com/administration-guide/configure/user-management-configuration-settings#identify-a-users-id)):
-1. **System Console** → **User Management** → **Users** → open your user. The ID is on the User Configuration page. This needs a system admin.
-2. **API**, with the bot token, looking up your username. The `id` field is yours, not the bot's:
+1. **System Console** (system admins): **User Management** → **Users** → open your user. The ID is on the User Configuration page.
+2. **Browser** (any user): while logged in to Mattermost, open `https://your-mattermost-server/api/v4/users/me` in a new tab. The `id` field is your User ID.
+3. **API with the bot token**: look up your username. The `id` field in the response is yours:
-```bash
-curl -s -H "Authorization: Bearer YOUR_BOT_TOKEN" \
- https://your-mattermost-server/api/v4/users/username/YOUR_USERNAME
-```
-
-`GET /api/v4/users/me` with that same bot token returns the **bot's** id. `/users/me` is your id only when the token is a personal access token for your own account.
+ ```bash
+ curl -s -H "Authorization: Bearer YOUR_BOT_TOKEN" \
+ https://your-mattermost-server/api/v4/users/username/YOUR_USERNAME
+ ```
-3. **mmctl**: `mmctl user list` prints each user id.
+ Don't call `/api/v4/users/me` with the bot token: that returns the **bot's** ID, not yours.
+4. **mmctl** (system admins): `mmctl user list --all` prints one line per user: `<id>: <username> (<email>)`.
Your User ID is a 26-character alphanumeric string like `3uo8dkh1p7g1mfk49ear5fzs5c`.
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/mattermost.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/mattermost.md
index 3eb1d1ad317..a27f6e1165d 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/mattermost.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/messaging/mattermost.md
@@ -102,19 +102,19 @@ group_sessions_per_user: false
Hermes Agent 使用你的 Mattermost 用户 ID 来控制谁可以与机器人交互。个人资料对话框(头像 → 个人资料)里没有这个 ID。
-Mattermost 把 ID 记在三处。见 [Identify a user's ID](https://docs.mattermost.com/administration-guide/configure/user-management-configuration-settings.html#identify-a-users-id):
+可以用以下任一方式查找(见 Mattermost 文档 [Identify a user's ID](https://docs.mattermost.com/administration-guide/configure/user-management-configuration-settings#identify-a-users-id)):
-1. **System Console** → **User Management** → **Users** → 打开你自己的用户。ID 在 User Configuration 页面上。这需要系统管理员。
-2. **API**:用 bot token 按用户名查询。返回里的 `id` 是你的,不是 bot 的:
+1. **System Console**(系统管理员):**User Management** → **Users** → 打开你自己的用户。ID 在 User Configuration 页面上。
+2. **浏览器**(任何用户):在已登录 Mattermost 的浏览器中新开标签页,打开 `https://your-mattermost-server/api/v4/users/me`。返回里的 `id` 就是你的用户 ID。
+3. **用 bot token 调用 API**:按你的用户名查询。返回里的 `id` 是你的:
-```bash
-curl -s -H "Authorization: Bearer YOUR_BOT_TOKEN" \
- https://your-mattermost-server/api/v4/users/username/YOUR_USERNAME
-```
-
-用同一个 bot token 调用 `GET /api/v4/users/me` 得到的是 **bot** 的 id。只有当你用的是自己账号的 personal access token 时,`/users/me` 才是你的 id。
+ ```bash
+ curl -s -H "Authorization: Bearer YOUR_BOT_TOKEN" \
+ https://your-mattermost-server/api/v4/users/username/YOUR_USERNAME
+ ```
-3. **mmctl**:`mmctl user list` 会列出每个用户的 id。
+ 不要用 bot token 调用 `/api/v4/users/me`:那返回的是 **bot** 的 ID,不是你的。
+4. **mmctl**(系统管理员):`mmctl user list --all` 会为每个用户输出一行 `<id>: <username> (<email>)`。
你的用户 ID 是一个 26 位字母数字字符串,例如 `3uo8dkh1p7g1mfk49ear5fzs5c`。