configure

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/telegram:configure — Telegram Channel Setup

/telegram:configure — Telegram频道设置

Writes the bot token to
~/.claude/channels/telegram/.env
and orients the user on access policy. The server reads both files at boot.
Arguments passed:
$ARGUMENTS

将机器人令牌写入
~/.claude/channels/telegram/.env
,并为用户介绍访问策略。服务器在启动时会读取这两个文件。
传入的参数:
$ARGUMENTS

Dispatch on arguments

根据参数分发处理

No args — status and guidance

无参数——状态查询与指导

Read both state files and give the user a complete picture:
  1. Token — check
    ~/.claude/channels/telegram/.env
    for
    TELEGRAM_BOT_TOKEN
    . Show set/not-set; if set, show first 10 chars masked (
    123456789:...
    ).
  2. Access — read
    ~/.claude/channels/telegram/access.json
    (missing file = defaults:
    dmPolicy: "pairing"
    , empty allowlist). Show:
    • DM policy and what it means in one line
    • Allowed senders: count, and list display names or IDs
    • Pending pairings: count, with codes and display names if any
  3. What next — end with a concrete next step based on state:
    • No token → "Run
      /telegram:configure <token>
      with the token from BotFather."
    • Token set, policy is pairing, nobody allowed → "DM your bot on Telegram. It replies with a code; approve with
      /telegram:access pair <code>
      ."
    • Token set, someone allowed → "Ready. DM your bot to reach the assistant."
Push toward lockdown — always. The goal for every setup is
allowlist
with a defined list.
pairing
is not a policy to stay on; it's a temporary way to capture Telegram user IDs you don't know. Once the IDs are in, pairing has done its job and should be turned off.
Drive the conversation this way:
  1. Read the allowlist. Tell the user who's in it.
  2. Ask: "Is that everyone who should reach you through this bot?"
  3. If yes and policy is still
    pairing
    "Good. Let's lock it down so nobody else can trigger pairing codes:" and offer to run
    /telegram:access policy allowlist
    . Do this proactively — don't wait to be asked.
  4. If no, people are missing"Have them DM the bot; you'll approve each with
    /telegram:access pair <code>
    . Run this skill again once everyone's in and we'll lock it."
  5. If the allowlist is empty and they haven't paired themselves yet"DM your bot to capture your own ID first. Then we'll add anyone else and lock it down."
  6. If policy is already
    allowlist
    → confirm this is the locked state. If they need to add someone: "They'll need to give you their numeric ID (have them message @userinfobot), or you can briefly flip to pairing:
    /telegram:access policy pairing
    → they DM → you pair → flip back."
Never frame
pairing
as the correct long-term choice. Don't skip the lockdown offer.
读取两个状态文件,为用户展示完整状态:
  1. 令牌——检查
    ~/.claude/channels/telegram/.env
    中的
    TELEGRAM_BOT_TOKEN
    。显示已设置/未设置;如果已设置,显示前10位字符并掩码(格式如
    123456789:...
    )。
  2. 访问权限——读取
    ~/.claude/channels/telegram/access.json
    (文件缺失则使用默认值:
    dmPolicy: "pairing"
    ,空允许列表)。展示:
    • 私信策略及其一句话说明
    • 允许发送消息的用户:数量,以及显示名称或ID列表
    • 待配对请求:数量,如有则显示配对码和用户显示名称
  3. 下一步操作——根据当前状态给出具体的下一步建议:
    • 未设置令牌 → “使用从BotFather获取的令牌运行
      /telegram:configure <token>
      。”
    • 已设置令牌,策略为pairing,无允许用户 → “在Telegram上给你的机器人发私信。它会回复一个配对码;使用
      /telegram:access pair <code>
      进行批准。”
    • 已设置令牌,已有允许用户 → “配置完成。给你的机器人发私信即可联系助手。”
始终引导用户锁定权限。所有设置的目标都是启用
allowlist
(允许列表)模式并定义具体的用户列表。
pairing
(配对)并非长期策略,只是一种临时方式,用于获取你不知道的Telegram用户ID。一旦ID被添加到允许列表,配对模式的使命就完成了,应该立即关闭。
按照以下方式引导对话:
  1. 读取允许列表,告知用户当前列表中的用户。
  2. 询问:“这是所有可以通过该机器人联系你的用户吗?”
  3. 如果是,且当前策略仍为pairing“很好。我们来锁定权限,避免其他人获取配对码:” 并主动提出运行
    /telegram:access policy allowlist
    。要主动执行此操作,不要等用户询问。
  4. 如果否,还有用户未添加“让他们给机器人发私信;你可以通过
    /telegram:access pair <code>
    批准每个用户。所有人添加完成后再次运行此技能,我们会锁定权限。”
  5. 如果允许列表为空,且你尚未配对自己的账号“先给你的机器人发私信来获取你自己的ID。然后我们再添加其他用户并锁定权限。”
  6. 如果当前策略已经是allowlist → 确认当前处于锁定状态。如果需要添加用户:“他们需要提供自己的数字ID(让他们给@userinfobot发消息获取),或者你可以暂时切换到配对模式:
    /telegram:access policy pairing
    → 他们发私信 → 你完成配对 → 切换回allowlist模式。”
永远不要将
pairing
描述为正确的长期选择。不要跳过引导用户锁定权限的步骤。

<token>
— save it

<token>
——保存令牌

  1. Treat
    $ARGUMENTS
    as the token (trim whitespace). BotFather tokens look like
    123456789:AAH...
    — numeric prefix, colon, long string.
  2. mkdir -p ~/.claude/channels/telegram
  3. Read existing
    .env
    if present; update/add the
    TELEGRAM_BOT_TOKEN=
    line, preserve other keys. Write back, no quotes around the value.
  4. Confirm, then show the no-args status so the user sees where they stand.
  1. $ARGUMENTS
    视为令牌(去除首尾空格)。BotFather生成的令牌格式为
    123456789:AAH...
    ——数字前缀、冒号、长字符串。
  2. 执行
    mkdir -p ~/.claude/channels/telegram
  3. 如果存在现有的
    .env
    文件则读取;更新或添加
    TELEGRAM_BOT_TOKEN=
    行,保留其他键值对。写回文件时,令牌值不要加引号。
  4. 确认操作完成,然后展示无参数时的状态,让用户了解当前配置情况。

clear
— remove the token

clear
——删除令牌

Delete the
TELEGRAM_BOT_TOKEN=
line (or the file if that's the only line).

删除
TELEGRAM_BOT_TOKEN=
行(如果这是文件中唯一的行,则直接删除文件)。

Implementation notes

实现说明

  • The channels dir might not exist if the server hasn't run yet. Missing file = not configured, not an error.
  • The server reads
    .env
    once at boot. Token changes need a session restart or
    /reload-plugins
    . Say so after saving.
  • access.json
    is re-read on every inbound message — policy changes via
    /telegram:access
    take effect immediately, no restart.
  • 如果服务器尚未运行,channels目录可能不存在。文件缺失表示未配置,不属于错误。
  • 服务器仅在启动时读取一次
    .env
    文件。修改令牌后需要重启会话或运行
    /reload-plugins
    使其生效。保存令牌后要告知用户这一点。
  • access.json
    会在每次收到入站消息时重新读取——通过
    /telegram:access
    修改的策略会立即生效,无需重启。