@zhin.js/adapter-telegram 5.0.2 → 6.0.0

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +63 -145
  3. package/adapters/telegram.ts +27 -0
  4. package/agent/tools/create_invite.ts +2 -2
  5. package/agent/tools/list_admins.ts +2 -2
  6. package/agent/tools/member_count.ts +2 -2
  7. package/agent/tools/pin_message.ts +2 -2
  8. package/agent/tools/react.ts +2 -2
  9. package/agent/tools/send_poll.ts +2 -2
  10. package/agent/tools/send_sticker.ts +2 -2
  11. package/agent/tools/set_description.ts +2 -2
  12. package/agent/tools/set_permissions.ts +2 -2
  13. package/agent/tools/unpin_message.ts +2 -2
  14. package/lib/endpoint.d.ts +65 -0
  15. package/lib/endpoint.js +332 -0
  16. package/lib/index.d.ts +4 -0
  17. package/lib/index.js +4 -0
  18. package/lib/platform-permit.d.ts +18 -0
  19. package/lib/{src/platform-permit.js → platform-permit.js} +1 -2
  20. package/lib/polling.d.ts +9 -0
  21. package/lib/polling.js +52 -0
  22. package/lib/protocol.d.ts +250 -0
  23. package/lib/protocol.js +324 -0
  24. package/lib/telegram-agent-deps.d.ts +28 -0
  25. package/lib/telegram-agent-deps.js +30 -0
  26. package/lib/webhook.d.ts +13 -0
  27. package/lib/webhook.js +45 -0
  28. package/package.json +43 -40
  29. package/plugin.ts +13 -0
  30. package/schema.json +74 -0
  31. package/src/endpoint.ts +339 -1103
  32. package/src/index.ts +40 -186
  33. package/src/platform-permit.ts +1 -1
  34. package/src/polling.ts +71 -0
  35. package/src/protocol.ts +573 -0
  36. package/src/telegram-agent-deps.ts +52 -11
  37. package/src/webhook.ts +67 -0
  38. package/client/Dashboard.tsx +0 -295
  39. package/client/index.tsx +0 -11
  40. package/client/tsconfig.json +0 -7
  41. package/client/utils/api.ts +0 -30
  42. package/dist/index.js +0 -32
  43. package/lib/agent/tools/create_invite.js +0 -20
  44. package/lib/agent/tools/create_invite.js.map +0 -1
  45. package/lib/agent/tools/list_admins.js +0 -26
  46. package/lib/agent/tools/list_admins.js.map +0 -1
  47. package/lib/agent/tools/member_count.js +0 -18
  48. package/lib/agent/tools/member_count.js.map +0 -1
  49. package/lib/agent/tools/pin_message.js +0 -21
  50. package/lib/agent/tools/pin_message.js.map +0 -1
  51. package/lib/agent/tools/react.js +0 -20
  52. package/lib/agent/tools/react.js.map +0 -1
  53. package/lib/agent/tools/send_poll.js +0 -32
  54. package/lib/agent/tools/send_poll.js.map +0 -1
  55. package/lib/agent/tools/send_sticker.js +0 -19
  56. package/lib/agent/tools/send_sticker.js.map +0 -1
  57. package/lib/agent/tools/set_description.js +0 -19
  58. package/lib/agent/tools/set_description.js.map +0 -1
  59. package/lib/agent/tools/set_permissions.js +0 -34
  60. package/lib/agent/tools/set_permissions.js.map +0 -1
  61. package/lib/agent/tools/unpin_message.js +0 -21
  62. package/lib/agent/tools/unpin_message.js.map +0 -1
  63. package/lib/src/adapter.js +0 -58
  64. package/lib/src/adapter.js.map +0 -1
  65. package/lib/src/endpoint.js +0 -1046
  66. package/lib/src/endpoint.js.map +0 -1
  67. package/lib/src/index.js +0 -215
  68. package/lib/src/index.js.map +0 -1
  69. package/lib/src/platform-permit.js.map +0 -1
  70. package/lib/src/segment-mapper.js +0 -2
  71. package/lib/src/segment-mapper.js.map +0 -1
  72. package/lib/src/telegram-agent-deps.js +0 -10
  73. package/lib/src/telegram-agent-deps.js.map +0 -1
  74. package/lib/src/types.js +0 -2
  75. package/lib/src/types.js.map +0 -1
  76. package/plugin.yml +0 -3
  77. package/src/adapter.ts +0 -66
  78. package/src/segment-mapper.ts +0 -1
  79. package/src/types.ts +0 -32
package/CHANGELOG.md CHANGED
@@ -1,5 +1,67 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7db69c1: 命令前缀改为适配器配置项:`MessageDispatcher` 不再硬编码 `/`,默认按消息所属适配器实例 config 的 `commandPrefix` 解析(默认 `''` 无前缀,任意文本按命令匹配),`endpoints[i].commandPrefix` 逐项覆盖;`ImRuntime({ commandPrefix })` 仍可设全局静态前缀。全部 20 个平台适配器 schema 新增 `commandPrefix` 属性。
8
+
9
+ BREAKING(行为变化):未配置时命令不再需要 `/` 前缀——原 `/zt` 写法不再命中,直接发 `zt` 即可;需要斜杠风格的适配器请在配置里显式设 `commandPrefix: '/'`。
10
+
11
+ - 713445c: 适配器配置格式定稿(不兼容旧格式):`plugins.<adapter>` 顶层仅共享字段 + `commandPrefix`,`endpoints[i]` 携带 endpoint 级字段(`name` + 凭据,各 schema 已类型化),`endpoints` 为必填(icqq 另需顶层 `master`);icqq 新增 `trusted` 列表(顶层/逐项均可)。scaffold-wizard 全部字段式与自定义 configure() 产出改为新格式,examples(full-bot / qq-games-bot)与 20 个适配器 README 同步迁移。
12
+ - Updated dependencies [7db69c1]
13
+ - Updated dependencies [e5c84ed]
14
+ - Updated dependencies [3ea84a0]
15
+ - Updated dependencies [1ddcd70]
16
+ - Updated dependencies [ac9da66]
17
+ - @zhin.js/core@1.4.0
18
+ - @zhin.js/adapter@1.1.0
19
+ - @zhin.js/plugin-runtime@1.1.0
20
+ - @zhin.js/agent@1.0.5
21
+ - @zhin.js/host-http@1.0.2
22
+ - zhin.js@5.0.0
23
+
24
+ ## 5.0.3
25
+
26
+ ### Patch Changes
27
+
28
+ - cc5c94d: 约定式插件运行时迁移(breaking):插件与适配器由 `usePlugin()` / `extends Adapter` 迁移为 `definePlugin` / `defineAdapter` + `plugin.ts` + 约定目录(`adapters/`、`commands/`、`components/`、`tools/` 等)。
29
+
30
+ - 新增约定式运行时包:`@zhin.js/plugin-runtime`、`@zhin.js/adapter`、`@zhin.js/runtime`、`@zhin.js/host-http`(首版 1.0.0 走 init-publish,不在本 changeset 内 bump)。
31
+ - 全部 20 个平台适配器改为约定式 `defineAdapter`,旧 `usePlugin` / `extends Adapter` / `segment-mapper` 生产入口已删除;onebot11 反向 WSS、onebot12 webhook/wss、milky sse/webhook/wss、satori webhook、kook webhook、qq webhook/middleware 等 slice 1 推迟的连接模式已补齐。
32
+ - 游戏 / 工具 / 服务插件同步迁移到约定目录结构。
33
+ - CLI 增加 plugin-runtime host installer(http/database/outbound/schedule/console 等)。
34
+
35
+ 后续加固(同批):
36
+
37
+ - CLI:`zhin runtime start --daemon`(pidfile/崩溃拉起/风暴保护),orphan watchdog 防僵尸进程;legacy `zhin dev` / `zhin start` 已移除(含 `zhin restart`),`zhin stop` 兼容新 daemon。
38
+ - 安全:builtin 工具统一走 `security/policy-facade.ts` 的 `runToolPolicies`(声明式策略表,deny 优先);审计日志 close flush + 背压队列;`splitCompoundCommand` 引号感知、`extractCommandName` 去引号堵绕过。
39
+ - 日志:Logger 双堆栈修复、本地时区、`getLogger` 挂树(`setLevel` 递归生效)、第三方库(log4js/discord)桥接、启动人读总结。
40
+ - 结构:`plugins/games/shared` 迁为 `packages/game-kit`(`@zhin.js/game-kit`);死目录 `plugins/adapters/common` 删除。
41
+ - 脚手架:`create-zhin-app` / `zhin new` / scaffold-wizard 生成物改为 Plugin Runtime 形态(minimal-bot 同构,新配置格式)。
42
+ - Console:endpoint.list 真实名称与 phase、schema:get-all 按 instanceKey 映射、db:\* 接 DatabaseHost。
43
+
44
+ 注:按仓库发布惯例(见 1bb345dd2),本次 breaking 迁移统一使用 patch,避免 zhin.js 5.0 级联。
45
+
46
+ - 447f3e2: 迁移缺口修复(legacy 功能对齐):
47
+
48
+ - html 段出站规范化:经 `@zhin.js/html-renderer` 渲染为 image 段(sandbox 豁免、无渲染器时降级文本),修复真实平台 `[object Object]`。
49
+ - 群聊 @ 触发 AI:适配器入站标注 `metadata.mentioned`(icqq/qq/slack/onebot11/onebot12/napcat/milky/discord/telegram/kook/dingtalk/satori),`matchAiTrigger` 补齐 ignorePrefixes/respondToAt/respondToPrivate/keywords(默认值与 legacy 对齐)。
50
+ - im_transcripts 全量流水恢复写入(chat_history 工具可用);群聊旁听上下文回迁。
51
+ - `ai.trigger.timeout/thinkingMessage/errorTemplate` 生效;masters/trusted 角色解析对齐 legacy。
52
+ - `Message.sender` 统一为用户 ID(onebot11/12、napcat、milky 原误传显示名);quote_id 经 metadata 接入 AI 引用上下文。
53
+
54
+ - Updated dependencies [16ec4e8]
55
+ - Updated dependencies [cc5c94d]
56
+ - Updated dependencies [447f3e2]
57
+ - @zhin.js/core@1.3.5
58
+ - @zhin.js/agent@1.0.4
59
+ - @zhin.js/host-http@1.0.1
60
+ - zhin.js@4.1.3
61
+ - @zhin.js/logger@1.0.75
62
+ - @zhin.js/plugin-runtime@1.0.1
63
+ - @zhin.js/adapter@1.0.1
64
+
3
65
  ## 5.0.2
4
66
 
5
67
  ### Patch Changes
package/README.md CHANGED
@@ -1,188 +1,106 @@
1
1
  # @zhin.js/adapter-telegram
2
2
 
3
- Telegram adapter for zhin.js framework.
3
+ Zhin.js Telegram Bot API 适配器(Plugin Runtime),默认通过 **长轮询 `getUpdates`** 收发消息(无需 host)。
4
4
 
5
- ## Installation
5
+ ## 功能
6
+
7
+ - 长轮询 `getUpdates` 入站(默认;无需公网 IP / host-http)
8
+ - 解析 text / image / video / audio / voice / document / sticker / location / callback_query
9
+ - 支持私聊与群组
10
+ - 出站 `send({ target, payload })` → Bot API(text / media / keyboard)
11
+ - 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
12
+ - Webhook 模式延期(需 `httpHostToken`);配置 `polling: false` 会明确报错
13
+
14
+ ## 安装
6
15
 
7
16
  ```bash
8
17
  pnpm add @zhin.js/adapter-telegram
9
18
  ```
10
19
 
11
- ## Prerequisites
20
+ ## Plugin Runtime
12
21
 
13
- | 要求 | 说明 |
14
- |------|------|
15
- | **Bot Token** | 通过 [@BotFather](https://t.me/botfather) 创建 Endpoint 并获取 Token |
16
- | **Polling(默认)** | 本地开发无需公网 IP;`polling: true`(默认) |
17
- | **Webhook(可选)** | 生产环境:`polling: false` + 公网 **HTTPS** 域名与有效 TLS;Telegraf 在 `webhook.port` 监听 |
18
- | **host-router** | 不需要;本适配器自行处理 polling / webhook |
22
+ - `@zhin.js/adapter` — 约定式 `adapters/telegram.ts`(`defineAdapter`)
23
+ - `@zhin.js/core` — `messageGatewayToken` 入站/出站
24
+ - `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
25
+ - 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
26
+ - **无需** `@zhin.js/host-http`(polling 路径)
19
27
 
20
- 必填字段见 `TelegramEndpointConfig`:`context`、`name`、`token`;`polling` 默认为 `true`。
28
+ 入站:`gateway.receive({ adapter, target: chatId, content: text, sender, metadata })`
29
+ 出站:`send({ target, payload })` → Telegram Bot API
21
30
 
22
- ## Minimal configuration
31
+ ### 平台权限(platform permit)
23
32
 
24
- ```yaml
25
- plugins:
26
- - "@zhin.js/adapter-telegram"
33
+ - sender role 已恢复:群消息入站时经 `getChatMember`(60s 缓存)解析,写入 `metadata.senderRole` / `metadata.senderPermissions`。
34
+ - `plugin.ts` 在 generation setup 注册 checker,并在 dispose 注销;Plugin Runtime CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费 `permissions`。
27
35
 
28
- endpoints:
29
- - context: telegram
30
- name: my-telegram-bot
31
- token: "${TELEGRAM_TOKEN}"
32
- polling: true
33
- ```
36
+ ## 前置条件
34
37
 
35
- ## Configuration
38
+ | 要求 | 说明 |
39
+ |------|------|
40
+ | **Bot Token** | 通过 [@BotFather](https://t.me/botfather) 创建并获取 Token |
41
+ | **Polling(默认)** | 本地/生产均可;主动拉取更新,无需公网 HTTPS |
42
+ | **网络** | 出站可访问 `api.telegram.org` |
43
+ | **host-http** | Polling **不需要**;Webhook 延期至下一棒 |
36
44
 
37
- ### 长轮询 Polling(默认,本地开发)
45
+ 必填字段(`endpoints[i]`):`name`、`token`。
38
46
 
39
- 无需公网 IP 或 HTTPS,Bot 主动向 Telegram 拉取更新:
47
+ ## 最小配置
40
48
 
41
49
  ```yaml
50
+ # zhin.config.yml(Plugin Runtime)
42
51
  plugins:
43
- - "@zhin.js/adapter-telegram"
44
-
45
- endpoints:
46
- - context: telegram
47
- name: my-telegram-bot
48
- token: "${TELEGRAM_TOKEN}"
49
- polling: true
52
+ telegram:
53
+ # polling: true # 默认
54
+ endpoints:
55
+ - name: my-telegram-bot
56
+ token: ${TELEGRAM_TOKEN}
50
57
  ```
51
58
 
52
- ### Webhook(生产环境)
53
-
54
- 设置 `polling: false` 并配置 `webhook` 对象;Telegraf 在 `webhook.port` 上启动 HTTPS 服务:
55
-
56
- ```yaml
57
- endpoints:
58
- - context: telegram
59
- name: my-telegram-bot
60
- token: "${TELEGRAM_TOKEN}"
61
- polling: false
62
- webhook:
63
- domain: https://bot.example.com
64
- path: /telegram-webhook
65
- port: 8443
66
- ```
59
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-telegram`(`instanceKey: telegram`)。
67
60
 
68
- #### Webhook 前置条件
61
+ ## 环境变量
69
62
 
70
- | 要求 | 说明 |
63
+ | 变量 | 说明 |
71
64
  |------|------|
72
- | **HTTPS 公网域名** | `webhook.domain` 须为 Telegram 可访问的 `https://` 地址(有效 TLS 证书) |
73
- | **端口可达** | `webhook.port`(如 8443)须从公网可连,或通过反向代理转发 |
74
- | **Bot Token** | 通过 [@BotFather](https://t.me/botfather) 获取 |
75
- | **无需 host-router** | 本适配器由 Telegraf 自行监听 webhook,不依赖 `@zhin.js/host-router` |
76
-
77
- > 本地开发建议先用 **polling**;上线后再切 webhook 并在 BotFather 或 launch 时注册 webhook URL。
78
-
79
- TypeScript 等价配置:
80
-
81
- ```typescript
82
- import { defineConfig } from 'zhin.js'
83
-
84
- export default defineConfig({
85
- endpoints: [
86
- {
87
- name: 'my-telegram-bot',
88
- context: 'telegram',
89
- token: 'YOUR_BOT_TOKEN',
90
- polling: true,
91
- // polling: false,
92
- // webhook: { domain: 'https://yourdomain.com', path: '/telegram-webhook', port: 8443 },
93
- }
94
- ]
95
- })
96
- ```
65
+ | `TELEGRAM_TOKEN` / `TELEGRAM_BOT_TOKEN` | Bot Token |
66
+ | `TELEGRAM_BOT_NAME` | 可选,默认 endpoint 名 |
97
67
 
98
- ## Features
68
+ ## Webhook(延期)
99
69
 
100
- - ✅ Send and receive text messages
101
- - ✅ Support for rich media (images, videos, audio, documents)
102
- - ✅ Message formatting (bold, italic, code, links)
103
- - ✅ Reply to messages
104
- - ✅ Mentions (@username)
105
- - ✅ Stickers and locations
106
- - ✅ Callback queries (inline buttons)
107
- - ✅ Long polling and webhook modes
108
- - ✅ Private and group chats
70
+ `polling: false` + `webhook` 目前会抛出明确错误:
109
71
 
110
- ## Getting Your Endpoint Token
72
+ > Telegram webhook mode is deferred until httpHostToken wiring; use polling: true (default) for now
111
73
 
112
- 1. Talk to [@BotFather](https://t.me/botfather) on Telegram
113
- 2. Send `/newbot` and follow the instructions
114
- 3. Copy the bot token provided
115
- 4. Add the token to your configuration
74
+ 下一棒将用 `httpHostToken` 注册 POST 路由,不再使用 Telegraf 自建监听或 legacy host-router。
116
75
 
117
- ## Usage Examples
76
+ ## 消息类型映射
118
77
 
119
- ### Basic Message Handling
120
-
121
- ```typescript
122
- import { usePlugin, MessageCommand } from 'zhin.js'
123
-
124
- const { addCommand } = usePlugin()
125
-
126
- addCommand(new MessageCommand('hello')
127
- .action(async (message) => {
128
- return 'Hello from Telegram!'
129
- })
130
- )
131
- ```
132
-
133
- ### Send Rich Media
134
-
135
- ```typescript
136
- addCommand(new MessageCommand('photo')
137
- .action(async (message) => {
138
- return [
139
- { type: 'image', data: { url: 'https://example.com/photo.jpg' } },
140
- { type: 'text', data: { text: 'Check out this photo!' } }
141
- ]
142
- })
143
- )
144
- ```
145
-
146
- ### Reply to Messages
147
-
148
- ```typescript
149
- addCommand(new MessageCommand('quote <text:text>')
150
- .action(async (message, result) => {
151
- await message.$reply(`You said: ${result.params.text}`, true) // true = quote original message
152
- })
153
- )
154
- ```
155
-
156
- ## Telegram-Specific Features
157
-
158
- ### Callback Queries
159
-
160
- The adapter automatically handles callback queries (from inline keyboards) as special messages.
161
-
162
- ### File Handling
163
-
164
- You can send files using:
165
- - `file_id` (from received messages)
166
- - URL
167
- - Local file path
78
+ | Telegram | 入站 content(文本摘要) | 出站 wire |
79
+ |----------|--------------------------|-----------|
80
+ | text | 原文 | sendMessage |
81
+ | photo | `[image]` / caption | sendPhoto(`file_id` / `url`) |
82
+ | video | `[video]` | sendVideo |
83
+ | audio / voice | `[audio]` / `[voice]` | sendAudio / sendVoice |
84
+ | document | `[file: name]` | sendDocument |
85
+ | sticker | `[sticker: …]` | sendSticker |
86
+ | location | `[location: lat,lon]` | sendLocation |
87
+ | callback_query | `[action: data]` | — |
168
88
 
169
89
  ## AI tools
170
90
 
171
91
  | Kind | Path |
172
92
  |------|------|
173
- | Platform tools (10) | `agent/tools/` (`telegram_*`: invites, pins, admins, stickers, etc.) |
93
+ | Platform tools (10) | `agent/tools/`(invite / pin / admins / sticker / poll 等) |
174
94
  | Skill doc | `agent/skills/telegram.md` |
175
- | Scene management | `createSceneManagementTools()` |
176
-
177
95
 
178
- ## Troubleshooting
96
+ ## 故障排查
179
97
 
180
98
  | 现象 | 排查 |
181
99
  |------|------|
182
- | Endpoint 无响应 / 收不到消息 | 确认 Token 正确;进程已启动;私聊 Endpoint 或将其加入群组 |
183
- | Polling 报错 | 检查网络能否访问 `api.telegram.org`;同一 Token 勿多进程同时 polling |
184
- | Webhook 不工作 | `webhook.domain` 须为 Telegram 可访问的 `https://`;放行 `webhook.port`;BotFather 或 launch 时注册 URL |
185
- | 发送失败 | Token revoked 或 Endpoint 被限制;查看日志中的 Telegraf 错误 |
100
+ | 收不到消息 | Token 是否正确;进程已 `open()`;同一 Token 勿多进程同时 polling |
101
+ | Polling 报错 | 检查能否访问 `api.telegram.org`;查看日志 `op: poll` |
102
+ | Webhook 配置报错 | 当前仅支持 polling;去掉 `polling: false` |
103
+ | 发送失败 | Token 是否被撤销;查看 Bot API 错误描述 |
186
104
 
187
105
  ## Documentation
188
106
 
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Convention entry: discover `adapters/telegram.ts` → defineAdapter.
3
+ */
4
+ import { defineAdapter } from '@zhin.js/adapter';
5
+ import { messageGatewayToken } from '@zhin.js/core/runtime';
6
+ import { httpHostToken } from '@zhin.js/host-http';
7
+ import { TelegramEndpoint } from '../src/endpoint.js';
8
+ import {
9
+ resolveTelegramConfig,
10
+ type TelegramAdapterConfig,
11
+ } from '../src/protocol.js';
12
+
13
+ export { TelegramEndpoint } from '../src/endpoint.js';
14
+ export type { TelegramEndpointOptions, TelegramFetch } from '../src/endpoint.js';
15
+
16
+ export default defineAdapter<TelegramAdapterConfig>({
17
+ capabilities: ['inbound', 'outbound'],
18
+ create(context) {
19
+ const config = resolveTelegramConfig(context.config);
20
+ return new TelegramEndpoint({
21
+ id: context.id,
22
+ gateway: context.use(messageGatewayToken),
23
+ config,
24
+ http: config.mode === 'webhook' ? context.use(httpHostToken) : undefined,
25
+ });
26
+ },
27
+ });
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; chat_id: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string }>({
7
7
  description: '创建 Telegram 群组邀请链接',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string }>({
6
6
  description: '获取 Telegram 群组管理员列表',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string }>({
6
6
  description: '获取 Telegram 群组成员数量',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; chat_id: string; message_id: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; message_id: string }>({
7
7
  description: '置顶 Telegram 群组消息',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string; message_id: string; reaction: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; message_id: string; reaction: string }>({
6
6
  description: '对 Telegram 消息添加表情反应',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string; question: string; options: string; is_anonymous?: boolean; allows_multiple?: boolean }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; question: string; options: string; is_anonymous?: boolean; allows_multiple?: boolean }>({
6
6
  description: '在 Telegram 群组中发起投票',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string; sticker: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; sticker: string }>({
6
6
  description: '发送 Telegram 贴纸',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; chat_id: string; description: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; description: string }>({
6
6
  description: '设置 Telegram 群组描述',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; chat_id: string; can_send_messages?: boolean; can_send_photos?: boolean; can_send_videos?: boolean; can_send_polls?: boolean; can_send_other_messages?: boolean; can_add_web_page_previews?: boolean; can_change_info?: boolean; can_invite_users?: boolean; can_pin_messages?: boolean }>({
6
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; can_send_messages?: boolean; can_send_photos?: boolean; can_send_videos?: boolean; can_send_polls?: boolean; can_send_other_messages?: boolean; can_add_web_page_previews?: boolean; can_change_info?: boolean; can_invite_users?: boolean; can_pin_messages?: boolean }>({
7
7
  description: '设置 Telegram 群组的默认成员权限',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getTelegramAgentDeps } from '../../src/telegram-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; chat_id: string; message_id?: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; chat_id: string; message_id?: string }>({
7
7
  description: '取消置顶 Telegram 群组消息',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -0,0 +1,65 @@
1
+ /**
2
+ * TelegramEndpoint — lifecycle, outbound, admit, Bot API helpers for agent tools.
3
+ */
4
+ import type { EndpointInstance } from '@zhin.js/adapter';
5
+ import type { MessageGateway } from '@zhin.js/core/runtime';
6
+ import type { HttpHost } from '@zhin.js/host-http';
7
+ import type { CapabilityId } from '@zhin.js/plugin-runtime';
8
+ import { type ResolvedTelegramConfig, type TelegramCallbackQuery, type TelegramChatMember, type TelegramMessage, type TelegramUpdate } from './protocol.js';
9
+ export type TelegramFetch = (url: string, init?: {
10
+ readonly method?: string;
11
+ readonly headers?: Record<string, string>;
12
+ readonly body?: string;
13
+ readonly signal?: AbortSignal;
14
+ }) => Promise<{
15
+ readonly ok: boolean;
16
+ readonly status: number;
17
+ text(): Promise<string>;
18
+ json(): Promise<unknown>;
19
+ }>;
20
+ export interface TelegramEndpointOptions {
21
+ readonly id: CapabilityId;
22
+ readonly gateway: MessageGateway;
23
+ readonly config: ResolvedTelegramConfig;
24
+ readonly http?: HttpHost;
25
+ readonly fetch?: TelegramFetch;
26
+ }
27
+ export declare class TelegramEndpoint implements EndpointInstance {
28
+ #private;
29
+ constructor(options: TelegramEndpointOptions);
30
+ /** Used by webhook handler. */
31
+ get isOpen(): boolean;
32
+ get config(): ResolvedTelegramConfig;
33
+ get allowedUpdates(): readonly string[];
34
+ getUpdateOffset(): number;
35
+ setUpdateOffset(offset: number): void;
36
+ start(): Promise<void>;
37
+ open(): void;
38
+ close(): void;
39
+ stop(): Promise<void>;
40
+ send({ target, payload }: {
41
+ readonly target: string;
42
+ readonly payload: unknown;
43
+ }): Promise<string>;
44
+ /** Test / internal: admit a message when open. */
45
+ admit(msg: TelegramMessage): void;
46
+ /** Test / internal: admit a callback query when open. */
47
+ admitCallback(query: TelegramCallbackQuery): void;
48
+ /** Used by webhook / polling handlers. */
49
+ handleUpdate(update: TelegramUpdate): void;
50
+ callApi<T = unknown>(method: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<T>;
51
+ pinMessage(chatId: number, messageId: number): Promise<boolean>;
52
+ unpinMessage(chatId: number, messageId?: number): Promise<boolean>;
53
+ setChatDescription(chatId: number, description: string): Promise<boolean>;
54
+ setMessageReaction(chatId: number, messageId: number, reaction: string): Promise<boolean>;
55
+ getChatMemberCount(chatId: number): Promise<number>;
56
+ getChatAdmins(chatId: number): Promise<TelegramChatMember[]>;
57
+ sendStickerMessage(chatId: number, sticker: string): Promise<{
58
+ message_id: number;
59
+ }>;
60
+ setChatPermissionsAll(chatId: number, permissions: Record<string, boolean | undefined>): Promise<boolean>;
61
+ createInviteLink(chatId: number): Promise<string>;
62
+ sendPoll(chatId: number, question: string, options: string[], isAnonymous?: boolean, allowsMultipleAnswers?: boolean): Promise<{
63
+ message_id: number;
64
+ }>;
65
+ }