@michengai/dsh-im-connect 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
  # Changelog
2
+
3
+ ## [1.0.29] - 2026-11-08
4
+
5
+ ### Telegram group mention policy & visual configuration
6
+
7
+ - Telegram group mention policy: support choosing group chat trigger policy in account settings — "Mention or reply only (default)", "Always reply to all group messages", and "Free chat in specific groups only" (#62).
8
+ - Visual configuration for group whitelist: when choosing specific groups, enter group IDs directly in the visual settings panel. Draft inputs are retained when toggling between policies to prevent accidental input loss.
9
+ - Smart group ID parsing and link tolerance: support pasting Telegram Web group URLs directly (e.g. `web.telegram.org` and private links `t.me/c/...`), automatically normalize Unicode full-width minus signs, dashes, and topic suffixes, and provide real-time validation warnings for unrecognized entries.
10
+ - Group ID discovery guide: add clear instructions in README for discovering Telegram group IDs via browser address bar or query bots.
11
+
2
12
  ## [1.0.28] - 2026-11-06
3
13
 
4
14
  ### Telegram delivery reliability
@@ -1,4 +1,14 @@
1
1
  # 更新日志
2
+
3
+ ## [1.0.29] - 2026-11-08
4
+
5
+ ### Telegram 群聊免 @ 触发策略与可视化设置
6
+
7
+ - Telegram 群聊支持选择触发策略:可在账号设置中选择「仅 @提及 或回复时响应(默认)」、「所有群消息均响应」或「仅指定群免 @ 响应」(#62)。
8
+ - 支持可视化配置免 @ 群白名单:选择指定群模式时,可直接在设置界面填写群号列表;切换模式时自动保留已填写的群号草稿,避免重复输入。
9
+ - 群 ID 智能识别与链接容错:群名单支持直接粘贴 Telegram 网页版群聊链接(如 `web.telegram.org` 或私有群链接 `t.me/c/...`),自动兼容手机端复制的全角负号、破折号及话题后缀,并在输入无法识别的内容时展示即时格式警告。
10
+ - 完善群 ID 获取指引:在文档中补充了通过 Telegram 网页端地址栏、官方查询机器人获取群 ID 的详细步骤。
11
+
2
12
  ## [1.0.28] - 2026-11-06
3
13
 
4
14
  ### Telegram 投递可靠性
package/README.en.md CHANGED
@@ -271,6 +271,41 @@ Native configuration options are provided here. Their values are persisted in `c
271
271
  - **Channels Tab Preserved**: Filtering applies only to the official workspace tree. All channel sessions remain fully available and accessible at any time under the sidebar's **Channels** tab;
272
272
  - **Lightweight Pipeline Collaboration**: Implemented via the `NativeTabRegistry.sessionFilters` inter-plugin protocol without invasive host hijacking. Toggling takes effect immediately and interoperates smoothly with Automation and Archive Manager. Non-supporting host shells degrade gracefully with a one-time warning.
273
273
 
274
+ ### 4. Telegram group trigger policy (`mentionPolicy` / `freeChatGroups`)
275
+ - **Default**: `addressed` — in groups the bot only reacts to an @mention, a reply to it, or a direct message.
276
+ - **What it does**: to let a group chat with the bot without @mentioning it, configure the trigger policy directly in **Settings → IM Assistant → Telegram Account Details**, or in `channels.json`:
277
+ - **Scenario A (specific groups only)**: configure `freeChatGroups` only; other groups keep default:
278
+ ```json
279
+ {
280
+ "channels": {
281
+ "<account id>": {
282
+ "config": {
283
+ "freeChatGroups": "-1001234567890, -5496760438"
284
+ }
285
+ }
286
+ }
287
+ }
288
+ ```
289
+ - **Scenario B (all groups)**: configure `mentionPolicy` as `always` (no need to configure `freeChatGroups` in this mode):
290
+ ```json
291
+ {
292
+ "channels": {
293
+ "<account id>": {
294
+ "config": {
295
+ "mentionPolicy": "always"
296
+ }
297
+ }
298
+ }
299
+ }
300
+ ```
301
+ - Both only decide whether a message reaches the agent — direct-message admission, tool approvals and command permissions are unchanged.
302
+ - **Platform prerequisite**: with Telegram privacy mode the bot only receives mentions, replies and commands. Make the bot a group administrator, or run `setprivacy` → `Disable` in @BotFather, so plain group messages reach the plugin.
303
+ - **UI**: configure visually by expanding Telegram account details in **Settings → IM Assistant** with policy select and group ID inputs.
304
+ - **How to find Group IDs**:
305
+ - **Option 1 (Recommended)**: Open Telegram Web in your browser, enter the group, and copy the address bar URL (e.g. `https://web.telegram.org/a/#-1001234567890` or private group link `https://t.me/c/1234567890`). You can paste it directly into the input field;
306
+ - **Option 2**: Send any message in the group, forward it to a query bot (such as `@userinfobot`), and copy the chat `Id` (starts with a minus sign);
307
+ - **Option 3**: Call `https://api.telegram.org/bot<TOKEN>/getUpdates` directly in your browser and check `"chat":{"id": -100xxxxxxxxxx}`.
308
+
274
309
  ## Usage
275
310
 
276
311
  Open **Settings → IM Assistant**, select **Add account** under the target channel, then choose that account's workspace, model, permission, private-access mode, and send mode. To register a new workspace, click **Add workspace…** in the dropdown footer to invoke the system folder picker (manual path inputs are disallowed); hosts lacking native folder pickers show "This Host cannot create workspaces" (upgrade to one of the supported host releases listed in Requirements, or add via the host sidebar).
package/README.md CHANGED
@@ -271,6 +271,41 @@ dsh --profile web --dump-config
271
271
  - **频道面板不受影响**:关闭仅作用于主任务树,在侧栏「频道」页签中依然完整保留并可随时点开、回复和复盘全部渠道会话;
272
272
  - **轻量管道协同**:基于 `NativeTabRegistry.sessionFilters` 标准协作协议实现,无需深度劫持宿主组件,切换即时生效,与定时插件及归档管理等第三方插件完全兼容。未支持该协议的外壳会自动安全降级并提示。
273
273
 
274
+ ### 4. Telegram 群聊触发策略 (`mentionPolicy` / `freeChatGroups`)
275
+ - **默认状态**:`addressed`(群里只有 @bot、回复 bot 或私聊才会处理)
276
+ - **功能说明**:群聊希望「不 @ 也能直接聊」时,可直接在「设置 → IM助理 → Telegram 账号详情」中配置群聊触发策略,亦可在 `channels.json` 中配置:
277
+ - **场景 A(仅特定群免 @)**:仅配置 `freeChatGroups`,未列出的群保持默认:
278
+ ```json
279
+ {
280
+ "channels": {
281
+ "<账号 id>": {
282
+ "config": {
283
+ "freeChatGroups": "-1001234567890, -5496760438"
284
+ }
285
+ }
286
+ }
287
+ }
288
+ ```
289
+ - **场景 B(所有群均免 @)**:配置 `mentionPolicy` 为 `always`(此模式下无需配置 `freeChatGroups`):
290
+ ```json
291
+ {
292
+ "channels": {
293
+ "<账号 id>": {
294
+ "config": {
295
+ "mentionPolicy": "always"
296
+ }
297
+ }
298
+ }
299
+ }
300
+ ```
301
+ - 这两项只影响「这条消息要不要送进 agent」,不改变私聊准入、工具审批与命令权限。
302
+ - **平台侧前提**:Telegram 隐私模式下 bot 只能收到提及、回复与命令。要让普通群消息到达插件,需把 bot 设为该群管理员,或在 @BotFather 里 `setprivacy` → `Disable`。
303
+ - **界面支持**:可在「设置 → IM助理」展开 Telegram 账号详情,直接通过下拉选择与群号输入框进行可视化配置。
304
+ - **如何获取群 ID**:
305
+ - **方法 1(推荐)**:在电脑浏览器打开 Telegram Web 网页版进入群聊,直接复制地址栏 URL(如 `https://web.telegram.org/a/#-1001234567890`,或私有群链接 `https://t.me/c/1234567890`),可直接粘贴至输入框自动解析;
306
+ - **方法 2**:在群里随便发一条消息,转发给官方查询机器人(如 `@userinfobot`),复制其回复中 `Forwarded from chat` 的 `Id` 数字(以负号开头);
307
+ - **方法 3**:通过 Bot 原生接口查询 `https://api.telegram.org/bot<TOKEN>/getUpdates`,找到 `"chat":{"id": -100xxxxxxxxxx}`。
308
+
274
309
  ## 使用
275
310
 
276
311
  打开「设置 → IM助理」,在目标渠道点击「添加账号」,并为该账号选择工作区、模型、权限、私聊准入和发送方式。若需要新工作区,可展开工作区下拉列表点击底部的「添加工作区…」直接调起系统文件选择器(禁止手输路径);不支持原生目录选择器的宿主会提示「当前 Host 无法新增工作区」,请升级到「环境要求」中列出的受支持宿主版本,或直接在宿主侧栏添加工作区。
package/README.zh-CN.md CHANGED
@@ -271,6 +271,41 @@ dsh --profile web --dump-config
271
271
  - **频道面板不受影响**:关闭仅作用于主任务树,在侧栏「频道」页签中依然完整保留并可随时点开、回复和复盘全部渠道会话;
272
272
  - **轻量管道协同**:基于 `NativeTabRegistry.sessionFilters` 标准协作协议实现,无需深度劫持宿主组件,切换即时生效,与定时插件及归档管理等第三方插件完全兼容。未支持该协议的外壳会自动安全降级并提示。
273
273
 
274
+ ### 4. Telegram 群聊触发策略 (`mentionPolicy` / `freeChatGroups`)
275
+ - **默认状态**:`addressed`(群里只有 @bot、回复 bot 或私聊才会处理)
276
+ - **功能说明**:群聊希望「不 @ 也能直接聊」时,可直接在「设置 → IM助理 → Telegram 账号详情」中配置群聊触发策略,亦可在 `channels.json` 中配置:
277
+ - **场景 A(仅特定群免 @)**:仅配置 `freeChatGroups`,未列出的群保持默认:
278
+ ```json
279
+ {
280
+ "channels": {
281
+ "<账号 id>": {
282
+ "config": {
283
+ "freeChatGroups": "-1001234567890, -5496760438"
284
+ }
285
+ }
286
+ }
287
+ }
288
+ ```
289
+ - **场景 B(所有群均免 @)**:配置 `mentionPolicy` 为 `always`(此模式下无需配置 `freeChatGroups`):
290
+ ```json
291
+ {
292
+ "channels": {
293
+ "<账号 id>": {
294
+ "config": {
295
+ "mentionPolicy": "always"
296
+ }
297
+ }
298
+ }
299
+ }
300
+ ```
301
+ - 这两项只影响「这条消息要不要送进 agent」,不改变私聊准入、工具审批与命令权限。
302
+ - **平台侧前提**:Telegram 隐私模式下 bot 只能收到提及、回复与命令。要让普通群消息到达插件,需把 bot 设为该群管理员,或在 @BotFather 里 `setprivacy` → `Disable`。
303
+ - **界面支持**:可在「设置 → IM助理」展开 Telegram 账号详情,直接通过下拉选择与群号输入框进行可视化配置。
304
+ - **如何获取群 ID**:
305
+ - **方法 1(推荐)**:在电脑浏览器打开 Telegram Web 网页版进入群聊,直接复制地址栏 URL(如 `https://web.telegram.org/a/#-1001234567890`,或私有群链接 `https://t.me/c/1234567890`),可直接粘贴至输入框自动解析;
306
+ - **方法 2**:在群里随便发一条消息,转发给官方查询机器人(如 `@userinfobot`),复制其回复中 `Forwarded from chat` 的 `Id` 数字(以负号开头);
307
+ - **方法 3**:通过 Bot 原生接口查询 `https://api.telegram.org/bot<TOKEN>/getUpdates`,找到 `"chat":{"id": -100xxxxxxxxxx}`。
308
+
274
309
  ## 使用
275
310
 
276
311
  打开「设置 → IM助理」,在目标渠道点击「添加账号」,并为该账号选择工作区、模型、权限、私聊准入和发送方式。若需要新工作区,可展开工作区下拉列表点击底部的「添加工作区…」直接调起系统文件选择器(禁止手输路径);不支持原生目录选择器的宿主会提示「当前 Host 无法新增工作区」,请升级到「环境要求」中列出的受支持宿主版本,或直接在宿主侧栏添加工作区。
package/client.js CHANGED
@@ -621,7 +621,7 @@ window.__ModuleLoader__.load({
621
621
  "taskTreeSessions.entry.title": "在任务树显示 IM 会话", "taskTreeSessions.entry.desc": "在官方工作区任务树中显示各渠道会话。关闭后仅在侧栏「频道」页签中显示", "taskTreeSessions.entry.toggle": "切换在任务树显示 IM 会话",
622
622
  "settings.aria": "IM助理", "settings.publicChatNotice": "未批准用户可以发起聊天,但不能批准工具调用。", "pending.notice": "有访问请求。批准后该用户才能驱动本机助手。", "action.approve": "批准", "action.deny": "拒绝", "loading": "加载中…",
623
623
  "account.presetUnavailable": "预设不可用", "action.settings": "设置", "command.dm": "私聊命令", "command.group": "群聊命令", "command.enabled": "可以执行命令", "command.disabled": "仅正常对话",
624
- "account.workspace": "工作区", "account.currentWorkspace": "当前工作区", "account.selectWorkspace": "请选择工作区", "account.selectModel": "请选择模型", "account.selectPermission": "请选择权限", "account.privateAccess": "私聊准入", "account.privateApproved": "仅已批准用户", "account.privateAll": "允许所有私聊用户", "account.sendMode": "发送方式", "account.sendQueue": "排队发送", "account.sendSteer": "插话发送", "account.sendSteerNote": "插话发送会把消息作为补充指令立即交给运行中的任务;任务空闲时与排队发送相同。", "account.sessionIdle": "空闲新开会话", "account.sessionIdleOff": "关闭(保持原会话)", "account.sessionIdleMin": "{n} 分钟", "account.sessionIdleHour": "{n} 小时", "account.sessionIdleHours": "{n} 小时", "account.sessionIdleNote": "距上一条消息超过该时间后再收到新消息,将开启新会话;旧会话仍可用 /sessions 找回。设为 0 表示关闭。", "account.segmentReply": "分段回复", "account.segmentFull": "完整发送", "account.segmentSplit": "分段发送", "account.segmentReplyNote": "选择分段发送时助手会把一次回复拆成多条短消息,在分隔标记处切开逐条发送;完整发送时仍是一条完整回复。", "account.segmentGap": "发送间隔", "account.segmentGapMin": "最小间隔", "account.segmentGapMax": "最大间隔", "account.segmentGapInvalid": "请填写 0 到 60 之间的秒数", "account.segmentGapOrder": "上限不能低于下限", "account.seconds": "秒", "account.autoNameNote": "绑定成功后会自动生成账号名,无需手动填写。需要区分使用者时,可在账号行填写备注。", "account.proxyMode": "网络代理", "account.proxyInherit": "跟随宿主", "account.proxyDirect": "直接连接", "account.proxyCustom": "手动配置", "account.proxyUrl": "代理地址", "account.proxyNote": "仅影响当前账号;保存后自动重连生效。", "account.proxySaved": "代理地址已保存;留空保存可保留当前地址。", "account.defaultName": "{channel}账号 {count}",
624
+ "account.workspace": "工作区", "account.currentWorkspace": "当前工作区", "account.selectWorkspace": "请选择工作区", "account.selectModel": "请选择模型", "account.selectPermission": "请选择权限", "account.privateAccess": "私聊准入", "account.privateApproved": "仅已批准用户", "account.privateAll": "允许所有私聊用户", "account.sendMode": "发送方式", "account.sendQueue": "排队发送", "account.sendSteer": "插话发送", "account.sendSteerNote": "插话发送会把消息作为补充指令立即交给运行中的任务;任务空闲时与排队发送相同。", "account.sessionIdle": "空闲新开会话", "account.sessionIdleOff": "关闭(保持原会话)", "account.sessionIdleMin": "{n} 分钟", "account.sessionIdleHour": "{n} 小时", "account.sessionIdleHours": "{n} 小时", "account.sessionIdleNote": "距上一条消息超过该时间后再收到新消息,将开启新会话;旧会话仍可用 /sessions 找回。设为 0 表示关闭。", "account.segmentReply": "分段回复", "account.segmentFull": "完整发送", "account.segmentSplit": "分段发送", "account.segmentReplyNote": "选择分段发送时助手会把一次回复拆成多条短消息,在分隔标记处切开逐条发送;完整发送时仍是一条完整回复。", "account.segmentGap": "发送间隔", "account.segmentGapMin": "最小间隔", "account.segmentGapMax": "最大间隔", "account.segmentGapInvalid": "请填写 0 到 60 之间的秒数", "account.segmentGapOrder": "上限不能低于下限", "account.seconds": "秒", "account.autoNameNote": "绑定成功后会自动生成账号名,无需手动填写。需要区分使用者时,可在账号行填写备注。", "account.proxyMode": "网络代理", "account.proxyInherit": "跟随宿主", "account.proxyDirect": "直接连接", "account.proxyCustom": "手动配置", "account.proxyUrl": "代理地址", "account.proxyNote": "仅影响当前账号;保存后自动重连生效。", "account.proxySaved": "代理地址已保存;留空保存可保留当前地址。", "account.telegramGroupPolicy": "群聊触发策略", "account.telegramGroupPolicyAddressed": "仅 @提及 或回复时响应(默认)", "account.telegramGroupPolicyAlways": "所有群消息均响应", "account.telegramGroupPolicyCustom": "仅指定群免 @ 响应", "account.telegramFreeChatGroups": "免 @ 群号白名单", "account.telegramFreeChatGroupsInvalid": "未检测到有效群 ID。群 ID 通常为负数纯数字(如 -1001234567890),亦可直接粘贴 Telegram 网页版群聊链接。", "account.telegramFreeChatGroupsPartial": "有 {count} 个群号无法识别,将被忽略;请填负数群号(如 -1001234567890)或 Telegram 网页版群聊链接。", "account.telegramGroupPolicyNote": "仅影响当前账号群聊;若需普通消息送达,请将 Bot 设为群管理员或在 @BotFather 中关闭隐私模式(/setprivacy → Disable)。", "account.defaultName": "{channel}账号 {count}",
625
625
  "account.remark": "名称备注", "account.remarkNote": "只在本机设置页区分账号,留空恢复自动名称。", "account.rename": "修改名称备注",
626
626
  "account.count": "{count} 个账号", "account.statusProcessing": "处理中…", "account.statusNotConnected": "未连接", "account.receive": "接收消息", "account.receiveDescription": "关闭后保留账号配置,但不接收新消息", "account.removeConfirm": "确定移除这个账号?本机保存的配置和凭据将一并删除。",
627
627
  "action.addAccount": "添加账号", "action.generateQr": "生成二维码", "action.checkConnection": "诊断连接", "action.reconnectAccount": "重新连接", "action.removeAccount": "移除接入", "status.saving": "保存中…", "status.saved": "已保存",
@@ -654,7 +654,7 @@ window.__ModuleLoader__.load({
654
654
  "taskTreeSessions.entry.title": "Show IM sessions in task tree", "taskTreeSessions.entry.desc": "Show messaging channel sessions in the official workspace task tree. When disabled, sessions are shown only under the 'Channels' tab.", "taskTreeSessions.entry.toggle": "Toggle show IM sessions in task tree",
655
655
  "settings.aria": "IM Assistant", "settings.publicChatNotice": "Unapproved users can start chats, but they cannot approve tool calls.", "pending.notice": "There are access requests. Approve a user before they can control the local assistant.", "action.approve": "Approve", "action.deny": "Deny", "loading": "Loading…",
656
656
  "account.presetUnavailable": "Preset unavailable", "action.settings": "Settings", "command.dm": "DM commands", "command.group": "Group commands", "command.enabled": "Commands enabled", "command.disabled": "Conversation only",
657
- "account.workspace": "Workspace", "account.currentWorkspace": "Current workspace", "account.selectWorkspace": "Select a workspace", "account.selectModel": "Select a model", "account.selectPermission": "Select a permission", "account.privateAccess": "Private chat access", "account.privateApproved": "Approved users only", "account.privateAll": "Allow all DM users", "account.sendMode": "Send mode", "account.sendQueue": "Queue", "account.sendSteer": "Steer", "account.sendSteerNote": "Steer hands the message to the running task as additional instructions at its next step; when the task is idle it behaves like Queue.", "account.sessionIdle": "Idle session rotation", "account.sessionIdleOff": "Disabled (keep session)", "account.sessionIdleMin": "{n} min", "account.sessionIdleHour": "{n} hr", "account.sessionIdleHours": "{n} hrs", "account.sessionIdleNote": "Start a new session when the next message arrives after this idle period; previous sessions remain accessible via /sessions. Set to 0 to disable.", "account.segmentReply": "Segmented replies", "account.segmentFull": "Send as whole", "account.segmentSplit": "Send in segments", "account.segmentReplyNote": "When set to Send in segments, the assistant splits one reply into several short messages at the separator and sends them one by one; Send as whole keeps the entire reply in a single message.", "account.segmentGap": "Send gap", "account.segmentGapMin": "Minimum gap", "account.segmentGapMax": "Maximum gap", "account.segmentGapInvalid": "Enter a number of seconds between 0 and 60.", "account.segmentGapOrder": "The maximum gap cannot be lower than the minimum.", "account.seconds": "s", "account.autoNameNote": "The account name is generated automatically after setup. Add a remark on the account row if you need to tell users apart.", "account.proxyMode": "Network proxy", "account.proxyInherit": "Follow Host", "account.proxyDirect": "Connect directly", "account.proxyCustom": "Configure manually", "account.proxyUrl": "Proxy address", "account.proxyNote": "Affects only this account. The channel reconnects automatically after saving.", "account.proxySaved": "A proxy address is saved. Leave the field blank to keep it.", "account.defaultName": "{channel} account {count}",
657
+ "account.workspace": "Workspace", "account.currentWorkspace": "Current workspace", "account.selectWorkspace": "Select a workspace", "account.selectModel": "Select a model", "account.selectPermission": "Select a permission", "account.privateAccess": "Private chat access", "account.privateApproved": "Approved users only", "account.privateAll": "Allow all DM users", "account.sendMode": "Send mode", "account.sendQueue": "Queue", "account.sendSteer": "Steer", "account.sendSteerNote": "Steer hands the message to the running task as additional instructions at its next step; when the task is idle it behaves like Queue.", "account.sessionIdle": "Idle session rotation", "account.sessionIdleOff": "Disabled (keep session)", "account.sessionIdleMin": "{n} min", "account.sessionIdleHour": "{n} hr", "account.sessionIdleHours": "{n} hrs", "account.sessionIdleNote": "Start a new session when the next message arrives after this idle period; previous sessions remain accessible via /sessions. Set to 0 to disable.", "account.segmentReply": "Segmented replies", "account.segmentFull": "Send as whole", "account.segmentSplit": "Send in segments", "account.segmentReplyNote": "When set to Send in segments, the assistant splits one reply into several short messages at the separator and sends them one by one; Send as whole keeps the entire reply in a single message.", "account.segmentGap": "Send gap", "account.segmentGapMin": "Minimum gap", "account.segmentGapMax": "Maximum gap", "account.segmentGapInvalid": "Enter a number of seconds between 0 and 60.", "account.segmentGapOrder": "The maximum gap cannot be lower than the minimum.", "account.seconds": "s", "account.autoNameNote": "The account name is generated automatically after setup. Add a remark on the account row if you need to tell users apart.", "account.proxyMode": "Network proxy", "account.proxyInherit": "Follow Host", "account.proxyDirect": "Connect directly", "account.proxyCustom": "Configure manually", "account.proxyUrl": "Proxy address", "account.proxyNote": "Affects only this account. The channel reconnects automatically after saving.", "account.proxySaved": "A proxy address is saved. Leave the field blank to keep it.", "account.telegramGroupPolicy": "Group trigger policy", "account.telegramGroupPolicyAddressed": "Only on @mention or reply (Default)", "account.telegramGroupPolicyAlways": "All group messages", "account.telegramGroupPolicyCustom": "Only specified groups without @", "account.telegramFreeChatGroups": "Free-chat group IDs", "account.telegramFreeChatGroupsInvalid": "No valid group IDs detected. Group IDs are typically negative integers (e.g. -1001234567890), or paste a Telegram Web chat link.", "account.telegramFreeChatGroupsPartial": "{count} group ID(s) could not be recognized and will be ignored. Use negative integers (e.g. -1001234567890) or a Telegram Web chat link.", "account.telegramGroupPolicyNote": "Applies only to this account. To receive plain group messages, make the bot a group admin or disable privacy mode in @BotFather (/setprivacy → Disable).", "account.defaultName": "{channel} account {count}",
658
658
  "account.remark": "Name remark", "account.remarkNote": "Shown only in settings to tell accounts apart. Leave blank to restore the automatic name.", "account.rename": "Edit name remark",
659
659
  "account.count": "{count} accounts", "account.statusProcessing": "Processing…", "account.statusNotConnected": "Not connected", "account.receive": "Receive messages", "account.receiveDescription": "Turn this off to keep the account settings without receiving new messages", "account.removeConfirm": "Remove this account? Its saved settings and credentials will also be deleted.",
660
660
  "action.addAccount": "Add account", "action.generateQr": "Generate QR code", "action.checkConnection": "Diagnose connection", "action.reconnectAccount": "Reconnect", "action.removeAccount": "Remove", "status.saving": "Saving…", "status.saved": "Saved",
@@ -831,8 +831,8 @@ window.__ModuleLoader__.load({
831
831
  .ima-segment-gap-input{flex:1 1 0;min-width:0}
832
832
  .ima-segment-gap-sep,.ima-segment-gap-unit{color:var(--ima-muted, #8a8a8a);white-space:nowrap}
833
833
  .ima-account-settings.compact{grid-template-columns:1fr}
834
- .ima-proxy-settings{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px 16px;width:100%;box-sizing:border-box}
835
- .ima-proxy-settings>.ima-picker-note{grid-column:1/-1}
834
+ .ima-proxy-settings,.ima-mention-policy-settings{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px 16px;width:100%;box-sizing:border-box}
835
+ .ima-proxy-settings>.ima-picker-note,.ima-mention-policy-settings>.ima-picker-note{grid-column:1/-1}
836
836
  .ima-picker-field{display:flex;min-width:0;width:100%;flex-direction:column;gap:6px;box-sizing:border-box}
837
837
  .ima-picker-field.wide,.ima-picker-note,.ima-model-effort{grid-column:1/-1}
838
838
  .ima-model-effort{display:grid;grid-template-columns:1fr 1fr;gap:14px 16px;min-width:0;width:100%;box-sizing:border-box}
@@ -2112,11 +2112,37 @@ window.__ModuleLoader__.load({
2112
2112
  );
2113
2113
  }
2114
2114
 
2115
+ /**
2116
+ * 单个群号条目能否被识别。
2117
+ * 规则必须与后端 src/channels/mention-policy.ts 的 normalizeChatId 保持一致:
2118
+ * 纯数字群号(可带负号、可带 :topicId 后缀)、t.me/c 私有群链接、web.telegram.org 链接。
2119
+ */
2120
+ function isValidFreeChatGroupToken(item) {
2121
+ const cleaned = String(item).trim().replace(/[\u2212\u2013\u2014\uFF0D]/g, "-");
2122
+ if (!cleaned) return false;
2123
+ return /^-?\d{1,20}$/.test(cleaned.split(":")[0])
2124
+ || /t\.me\/c\/\d{1,18}(?:[/?#]|$)/i.test(cleaned)
2125
+ || /web\.telegram\.org\/[^#]*#(?:-\d{1,18}|c?\d{1,18})(?![0-9])/i.test(cleaned);
2126
+ }
2127
+
2128
+ /** 统计群号列表里的条目总数与无法识别的条数;前端只用于提示,不改变保存内容。 */
2129
+ function freeChatGroupTokenIssues(raw) {
2130
+ const tokens = typeof raw === "string" && raw.trim() ? raw.split(/[\s,,]+/).filter(Boolean) : [];
2131
+ let invalid = 0;
2132
+ for (const token of tokens) if (!isValidFreeChatGroupToken(token)) invalid += 1;
2133
+ return { total: tokens.length, invalid };
2134
+ }
2135
+
2115
2136
  function AccountInspector({ account, catalog, permissions, agentPresets, workspaces, createWorkspace, pickDirectory, modelT, permissionT, presetT, t, onAction, onSave, busy }) {
2116
2137
  const [modal, modalHolder] = Modal.useModal();
2117
2138
  const [draft, setDraft] = useState(account);
2118
2139
  const [proxyModeDraft, setProxyModeDraft] = useState(account.proxyMode || "inherit");
2119
2140
  const [proxyUrlDraft, setProxyUrlDraft] = useState(account.proxyUrl || "");
2141
+ const [mentionPolicyDraft, setMentionPolicyDraft] = useState(
2142
+ account.mentionPolicy === "always" ? "always" : (account.freeChatGroups ? "custom" : "addressed")
2143
+ );
2144
+ const [freeChatGroupsDraft, setFreeChatGroupsDraft] = useState(account.freeChatGroups || "");
2145
+ const accountIdRef = useRef(account.id);
2120
2146
  const [note, setNote] = useState("");
2121
2147
  const [checkResult, setCheckResult] = useState(null);
2122
2148
  const [checkFailed, setCheckFailed] = useState(false);
@@ -2158,6 +2184,13 @@ window.__ModuleLoader__.load({
2158
2184
  setProxyModeDraft(account.proxyMode || "inherit");
2159
2185
  setNote("");
2160
2186
  }, [account.id, account.cwd, account.permission, account.agentPreset, account.privateAccess, account.sendMode, account.sessionIdleMinutes, account.segmentReply, account.segmentDelayMinSecs, account.segmentDelayMaxSecs, account.proxyMode, account.proxyConfigured, JSON.stringify(account.commandPermissions), account.receiveEnabled, account.assistant && account.assistant.provider, account.assistant && account.assistant.model, account.assistant && account.assistant.reasoningEffort]);
2187
+ useEffect(() => {
2188
+ if (accountIdRef.current !== account.id) {
2189
+ accountIdRef.current = account.id;
2190
+ setFreeChatGroupsDraft(account.freeChatGroups || "");
2191
+ setMentionPolicyDraft(account.mentionPolicy === "always" ? "always" : (account.freeChatGroups ? "custom" : "addressed"));
2192
+ }
2193
+ }, [account.id, account.freeChatGroups, account.mentionPolicy]);
2161
2194
  useEffect(() => {
2162
2195
  setProxyUrlDraft(account.proxyUrl || "");
2163
2196
  }, [account.id, account.proxyUrl]);
@@ -2190,6 +2223,13 @@ window.__ModuleLoader__.load({
2190
2223
  payload.proxyUrl = Object.prototype.hasOwnProperty.call(patch, "proxyUrl") ? patch.proxyUrl : proxyUrlDraft;
2191
2224
  }
2192
2225
  }
2226
+ if (account.platform === "telegram") {
2227
+ const hasMentionPatch = Object.prototype.hasOwnProperty.call(patch, "mentionPolicy") || Object.prototype.hasOwnProperty.call(patch, "freeChatGroups");
2228
+ if (hasMentionPatch) {
2229
+ payload.mentionPolicy = Object.prototype.hasOwnProperty.call(patch, "mentionPolicy") ? patch.mentionPolicy : (mentionPolicyDraft === "always" ? "always" : "addressed");
2230
+ payload.freeChatGroups = Object.prototype.hasOwnProperty.call(patch, "freeChatGroups") ? patch.freeChatGroups : freeChatGroupsDraft;
2231
+ }
2232
+ }
2193
2233
  return onSave(account.id, payload).then((ok) => {
2194
2234
  if (seq === saveSeq.current) setNote(ok ? "status.saved" : "error.save");
2195
2235
  return ok;
@@ -2280,6 +2320,54 @@ window.__ModuleLoader__.load({
2280
2320
  ),
2281
2321
  h("div", { className: "ima-picker-note" }, t("account.proxyNote")),
2282
2322
  ),
2323
+ account.platform === "telegram" && h("div", { className: "ima-mention-policy-settings" },
2324
+ h("label", { className: mentionPolicyDraft === "custom" ? "ima-picker-field" : "ima-picker-field wide" },
2325
+ h("span", { className: "ima-picker-label" }, t("account.telegramGroupPolicy")),
2326
+ h(Select, {
2327
+ className: "ima-account-picker",
2328
+ value: mentionPolicyDraft,
2329
+ "aria-label": t("account.telegramGroupPolicy"),
2330
+ options: [
2331
+ { value: "addressed", label: t("account.telegramGroupPolicyAddressed") },
2332
+ { value: "custom", label: t("account.telegramGroupPolicyCustom") },
2333
+ { value: "always", label: t("account.telegramGroupPolicyAlways") },
2334
+ ],
2335
+ onChange: (next) => {
2336
+ setMentionPolicyDraft(next);
2337
+ if (next === "addressed") {
2338
+ save({ mentionPolicy: "addressed", freeChatGroups: "" });
2339
+ } else if (next === "always") {
2340
+ save({ mentionPolicy: "always", freeChatGroups: "" });
2341
+ } else {
2342
+ save({ mentionPolicy: "addressed", freeChatGroups: freeChatGroupsDraft.trim() });
2343
+ }
2344
+ },
2345
+ }),
2346
+ ),
2347
+ mentionPolicyDraft === "custom" && h("label", { className: "ima-picker-field" },
2348
+ h("span", { className: "ima-picker-label" }, t("account.telegramFreeChatGroups")),
2349
+ h(Input, {
2350
+ type: "text",
2351
+ value: freeChatGroupsDraft,
2352
+ placeholder: "-1001234567890, -5496760438",
2353
+ "aria-label": t("account.telegramFreeChatGroups"),
2354
+ onChange: (event) => {
2355
+ setFreeChatGroupsDraft(event.target.value);
2356
+ },
2357
+ onBlur: (event) => {
2358
+ const value = event.target.value.trim();
2359
+ save({ mentionPolicy: "addressed", freeChatGroups: value });
2360
+ },
2361
+ }),
2362
+ ),
2363
+ mentionPolicyDraft === "custom" && (() => {
2364
+ const issues = freeChatGroupTokenIssues(freeChatGroupsDraft);
2365
+ if (issues.invalid === 0) return null;
2366
+ const key = issues.invalid === issues.total ? "account.telegramFreeChatGroupsInvalid" : "account.telegramFreeChatGroupsPartial";
2367
+ return h("div", { className: "ima-picker-note warning" }, t(key, { count: issues.invalid }));
2368
+ })(),
2369
+ h("div", { className: "ima-picker-note" }, t("account.telegramGroupPolicyNote")),
2370
+ ),
2283
2371
  h(CommandPermissionSettings, { value: draft.commandPermissions, onSave: commandPermissions => save({ commandPermissions }), t }),
2284
2372
  note && h("div", { className: note === "status.saved" ? "ima-save-note ok" : "ima-save-note" }, t(note)),
2285
2373
  h("div", { className: "ima-inspector-actions" },
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/channels/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAWxD,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACrK,cAAc,GAAG,SAAS,CAsC5B"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/channels/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAYxD,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACrK,cAAc,GAAG,SAAS,CAiD5B"}
@@ -7,14 +7,25 @@ import { createWeixinChannel } from './weixin.js';
7
7
  import { createQqChannel } from './qq.js';
8
8
  import { createSlackChannel } from './slack.js';
9
9
  import { parseAdditionalImageHosts } from './image-host-policy.js';
10
+ import { parseChatIdList } from './mention-policy.js';
10
11
  export function createChannelAdapter(id, config, log, stateDir, options) {
11
12
  let adapter;
12
13
  const imageOptions = ['qq', 'wecom', 'dingtalk'].includes(id)
13
14
  ? { additionalImageHosts: parseAdditionalImageHosts(config.additionalImageHosts) } : {};
14
15
  switch (id) {
15
- case 'telegram':
16
- adapter = createTelegramChannel({ token: config.token, stateDir, host: options?.host, proxyMode: config.proxyMode, proxyUrl: config.proxyUrl }, log);
16
+ case 'telegram': {
17
+ const freeChatGroups = parseChatIdList(config.freeChatGroups);
18
+ adapter = createTelegramChannel({
19
+ token: config.token,
20
+ stateDir,
21
+ host: options?.host,
22
+ proxyMode: config.proxyMode,
23
+ proxyUrl: config.proxyUrl,
24
+ mentionPolicy: config.mentionPolicy === 'always' ? 'always' : undefined,
25
+ ...(freeChatGroups.length > 0 ? { freeChatGroups } : {}),
26
+ }, log);
17
27
  break;
28
+ }
18
29
  case 'discord':
19
30
  adapter = createDiscordChannel({
20
31
  token: config.token,
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/channels/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAElE,MAAM,UAAU,oBAAoB,CAClC,EAAa,EACb,MAA8B,EAC9B,GAA2B,EAC3B,QAAgB,EAChB,OAAsK;IAEtK,IAAI,OAAmC,CAAA;IACvC,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,CAAC,CAAC,EAAE,oBAAoB,EAAE,yBAAyB,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACzF,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,UAAU;YACb,OAAO,GAAG,qBAAqB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,SAAwD,EAAE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EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YAAC,MAAK;QACrJ,KAAK,IAAI;YACP,OAAO,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YAAC,MAAK;QACnI,KAAK,OAAO;YACV,OAAO,GAAG,kBAAkB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YAAC,MAAK;QAC7H;YACE,OAAO,SAAS,CAAA;IACpB,CAAC;IACD,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAC9B,OAAO;QACL,GAAG,OAAO;QACV,EAAE,EAAE,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,EAAE;QACpC,KAAK,EAAE,OAAO,EAAE,YAAY,IAAI,OAAO,CAAC,KAAK;KAC9C,CAAA;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 群聊触发策略:判断一条入站消息是否算「在对 bot 说话」。
3
+ *
4
+ * 默认(`addressed`)只有三种情况会触发:私聊、回复 bot 自己的消息、文本里 @ 了 bot。
5
+ * 群组常常希望「不 @ 也能直接聊」,于是提供两种放宽方式:
6
+ *
7
+ * - `mentionPolicy: 'always'`:该账号下所有群的普通消息都触发。
8
+ * - `freeChatGroups: [...chatId]`:只放宽指定群,其余群保持默认。
9
+ *
10
+ * 两者都只影响「这条消息要不要送进 agent」,不改变消息授权(谁能用 bot)
11
+ * 与工具审批边界。
12
+ */
13
+ export type MentionPolicy = 'addressed' | 'always';
14
+ export interface InboundAddressInput {
15
+ readonly direct: boolean;
16
+ readonly chatId: string | number;
17
+ readonly replyToBot: boolean;
18
+ readonly mentioned: boolean;
19
+ readonly policy?: MentionPolicy | undefined;
20
+ readonly freeChatGroups?: readonly string[] | undefined;
21
+ }
22
+ /** 一条入站消息是否算在对 bot 说话。 */
23
+ export declare function isInboundAddressed(input: InboundAddressInput): boolean;
24
+ /**
25
+ * 解析渠道配置里的群号列表:支持逗号、中文逗号、空白分隔,非法项直接丢弃。
26
+ * 渠道配置是字符串键值对,支持 Unicode 负号、话题后缀剥离与 Telegram Web 链接提取。
27
+ */
28
+ export declare function parseChatIdList(raw: unknown): string[];
29
+ //# sourceMappingURL=mention-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mention-policy.d.ts","sourceRoot":"","sources":["../../src/channels/mention-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IAChC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IAC3C,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;CACxD;AAED,0BAA0B;AAC1B,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAOtE;AAgDD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAUtD"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * 群聊触发策略:判断一条入站消息是否算「在对 bot 说话」。
3
+ *
4
+ * 默认(`addressed`)只有三种情况会触发:私聊、回复 bot 自己的消息、文本里 @ 了 bot。
5
+ * 群组常常希望「不 @ 也能直接聊」,于是提供两种放宽方式:
6
+ *
7
+ * - `mentionPolicy: 'always'`:该账号下所有群的普通消息都触发。
8
+ * - `freeChatGroups: [...chatId]`:只放宽指定群,其余群保持默认。
9
+ *
10
+ * 两者都只影响「这条消息要不要送进 agent」,不改变消息授权(谁能用 bot)
11
+ * 与工具审批边界。
12
+ */
13
+ /** 一条入站消息是否算在对 bot 说话。 */
14
+ export function isInboundAddressed(input) {
15
+ if (input.direct)
16
+ return true;
17
+ if (input.policy === 'always')
18
+ return true;
19
+ if (input.replyToBot || input.mentioned)
20
+ return true;
21
+ if (input.freeChatGroups === undefined || input.freeChatGroups.length === 0)
22
+ return false;
23
+ const chatId = String(input.chatId);
24
+ return input.freeChatGroups.some(item => item.trim() === chatId);
25
+ }
26
+ /**
27
+ * 归一化单个群号条目:
28
+ * - 归一化各种 Unicode 负号(全角负号、破折号)为 ASCII 减号;
29
+ * - 支持直接解析 Telegram 网页端私有群链接(如 https://t.me/c/1234567890/xxx -> -1001234567890);
30
+ * - 支持剥离论坛话题后缀(如 -1001234567890:42 -> -1001234567890);
31
+ * - 最终仅保留 1 到 20 位的有效数字 ID(可带负号)。
32
+ */
33
+ function normalizeChatId(item) {
34
+ let cleaned = item.trim();
35
+ if (!cleaned)
36
+ return undefined;
37
+ // 1. 先统一 Unicode 负号为 ASCII '-':否则带全角负号的链接会在链接分支里失配。
38
+ cleaned = cleaned.replace(/[\u2212\u2013\u2014\uFF0D]/g, '-');
39
+ // 2. Telegram 链接提取:
40
+ // 2.1 t.me/c/(\d+) 内部 ID 一律拼 -100 前缀(如 t.me/c/1005555 -> -1001005555),
41
+ // 数字后必须是分隔符或结尾,避免把 "…7890abc" 这类残链接认成群号。
42
+ const tmeMatch = cleaned.match(/t\.me\/c\/(\d{1,18})(?:[/?#]|$)/i);
43
+ if (tmeMatch && tmeMatch[1]) {
44
+ return `-100${tmeMatch[1]}`;
45
+ }
46
+ // 2.2 web.telegram.org 链接:
47
+ // - 若自带负号完整群 ID(如 web.telegram.org/a/#-1001234567890 或 #-123456),直接提取该负数 ID;
48
+ // - 若为私有群内部数字(如 #c123456 或纯正整数),拼 -100 前缀;
49
+ // - 数字后同样要求非数字,避免超长数字被截断成另一个群号。
50
+ const webFullMatch = cleaned.match(/web\.telegram\.org\/[^#]*#(-\d{1,18})(?![0-9])/i);
51
+ if (webFullMatch && webFullMatch[1]) {
52
+ return webFullMatch[1];
53
+ }
54
+ const webInternalMatch = cleaned.match(/web\.telegram\.org\/[^#]*#(?:c)?(\d{1,18})(?![0-9])/i);
55
+ if (webInternalMatch && webInternalMatch[1]) {
56
+ return `-100${webInternalMatch[1]}`;
57
+ }
58
+ // 3. 截断话题后缀(如 :42)
59
+ const topicIdx = cleaned.indexOf(':');
60
+ if (topicIdx > 0)
61
+ cleaned = cleaned.slice(0, topicIdx).trim();
62
+ // 4. 正则严格校验纯数字群 ID
63
+ if (/^-?\d{1,20}$/.test(cleaned)) {
64
+ return cleaned;
65
+ }
66
+ return undefined;
67
+ }
68
+ /**
69
+ * 解析渠道配置里的群号列表:支持逗号、中文逗号、空白分隔,非法项直接丢弃。
70
+ * 渠道配置是字符串键值对,支持 Unicode 负号、话题后缀剥离与 Telegram Web 链接提取。
71
+ */
72
+ export function parseChatIdList(raw) {
73
+ if (typeof raw !== 'string')
74
+ return [];
75
+ const result = [];
76
+ for (const item of raw.split(/[\s,,]+/)) {
77
+ const normalized = normalizeChatId(item);
78
+ if (normalized && !result.includes(normalized)) {
79
+ result.push(normalized);
80
+ }
81
+ }
82
+ return result;
83
+ }
84
+ //# sourceMappingURL=mention-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mention-policy.js","sourceRoot":"","sources":["../../src/channels/mention-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA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EAAE,CAAC;QACpC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC;IACD,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAA;IAC9F,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,OAAO,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC,CAAC;IAED,mBAAmB;IACnB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACrC,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAA;IAE7D,mBAAmB;IACnB,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAA;IACtC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;QACxC,IAAI,UAAU,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/C,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { ChannelAdapter } from '../engine/types.js';
2
+ import { type MentionPolicy } from './mention-policy.js';
2
3
  export interface TelegramConfig {
3
4
  token?: string;
4
5
  stateDir?: string;
@@ -7,6 +8,10 @@ export interface TelegramConfig {
7
8
  };
8
9
  proxyMode?: 'inherit' | 'direct' | 'custom';
9
10
  proxyUrl?: string;
11
+ /** 群聊触发策略:默认 `addressed`(私聊 / 回复 bot / @bot),`always` 表示普通群消息也触发。 */
12
+ mentionPolicy?: MentionPolicy;
13
+ /** 只对这些群放宽触发(群 id 字符串);未列出的群保持默认策略。 */
14
+ freeChatGroups?: readonly string[];
10
15
  }
11
16
  /**
12
17
  * 编码 Telegram 会话键:
@@ -1 +1 @@
1
- {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/channels/telegram.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAmC,MAAM,oBAAoB,CAAA;AAOzF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;IACrC,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAkCD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAalG;AAgBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkB1D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMxE;AAeD,wBAAgB,qBAAqB,CAAC,MAAM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AI,EAAE,MAAM,KAAK,IAAI,GAAG,cAAc,GAAG,SAAS,CAwkBrH"}
@@ -8,6 +8,7 @@ import { JsonStateFile } from '../engine/json-state.js';
8
8
  import { sleepWithSignal, timeoutSignal } from '../engine/abort.js';
9
9
  import { fileMedia, imageMedia, MAX_CHANNEL_IMAGE_BYTES } from './channel-image-download.js';
10
10
  import { retryTelegram } from './telegram-retry.js';
11
+ import { isInboundAddressed } from './mention-policy.js';
11
12
  const API = 'https://api.telegram.org';
12
13
  /**
13
14
  * 编码 Telegram 会话键:
@@ -329,9 +330,14 @@ export function createTelegramChannel(config, log) {
329
330
  continue;
330
331
  }
331
332
  const direct = message.chat.type === 'private';
332
- let addressed = direct
333
- || String(message.reply_to_message?.from?.id ?? '') === botId
334
- || mentioned(message);
333
+ let addressed = isInboundAddressed({
334
+ direct,
335
+ chatId: message.chat.id,
336
+ replyToBot: String(message.reply_to_message?.from?.id ?? '') === botId,
337
+ mentioned: mentioned(message),
338
+ policy: config.mentionPolicy,
339
+ freeChatGroups: config.freeChatGroups,
340
+ });
335
341
  let deliveries = [update];
336
342
  if (!direct && message.media_group_id && message.from?.id) {
337
343
  const now = Date.now();