@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.
- package/CHANGELOG.md +62 -0
- package/README.md +63 -145
- package/adapters/telegram.ts +27 -0
- package/agent/tools/create_invite.ts +2 -2
- package/agent/tools/list_admins.ts +2 -2
- package/agent/tools/member_count.ts +2 -2
- package/agent/tools/pin_message.ts +2 -2
- package/agent/tools/react.ts +2 -2
- package/agent/tools/send_poll.ts +2 -2
- package/agent/tools/send_sticker.ts +2 -2
- package/agent/tools/set_description.ts +2 -2
- package/agent/tools/set_permissions.ts +2 -2
- package/agent/tools/unpin_message.ts +2 -2
- package/lib/endpoint.d.ts +65 -0
- package/lib/endpoint.js +332 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/platform-permit.d.ts +18 -0
- package/lib/{src/platform-permit.js → platform-permit.js} +1 -2
- package/lib/polling.d.ts +9 -0
- package/lib/polling.js +52 -0
- package/lib/protocol.d.ts +250 -0
- package/lib/protocol.js +324 -0
- package/lib/telegram-agent-deps.d.ts +28 -0
- package/lib/telegram-agent-deps.js +30 -0
- package/lib/webhook.d.ts +13 -0
- package/lib/webhook.js +45 -0
- package/package.json +43 -40
- package/plugin.ts +13 -0
- package/schema.json +74 -0
- package/src/endpoint.ts +339 -1103
- package/src/index.ts +40 -186
- package/src/platform-permit.ts +1 -1
- package/src/polling.ts +71 -0
- package/src/protocol.ts +573 -0
- package/src/telegram-agent-deps.ts +52 -11
- package/src/webhook.ts +67 -0
- package/client/Dashboard.tsx +0 -295
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -30
- package/dist/index.js +0 -32
- package/lib/agent/tools/create_invite.js +0 -20
- package/lib/agent/tools/create_invite.js.map +0 -1
- package/lib/agent/tools/list_admins.js +0 -26
- package/lib/agent/tools/list_admins.js.map +0 -1
- package/lib/agent/tools/member_count.js +0 -18
- package/lib/agent/tools/member_count.js.map +0 -1
- package/lib/agent/tools/pin_message.js +0 -21
- package/lib/agent/tools/pin_message.js.map +0 -1
- package/lib/agent/tools/react.js +0 -20
- package/lib/agent/tools/react.js.map +0 -1
- package/lib/agent/tools/send_poll.js +0 -32
- package/lib/agent/tools/send_poll.js.map +0 -1
- package/lib/agent/tools/send_sticker.js +0 -19
- package/lib/agent/tools/send_sticker.js.map +0 -1
- package/lib/agent/tools/set_description.js +0 -19
- package/lib/agent/tools/set_description.js.map +0 -1
- package/lib/agent/tools/set_permissions.js +0 -34
- package/lib/agent/tools/set_permissions.js.map +0 -1
- package/lib/agent/tools/unpin_message.js +0 -21
- package/lib/agent/tools/unpin_message.js.map +0 -1
- package/lib/src/adapter.js +0 -58
- package/lib/src/adapter.js.map +0 -1
- package/lib/src/endpoint.js +0 -1046
- package/lib/src/endpoint.js.map +0 -1
- package/lib/src/index.js +0 -215
- package/lib/src/index.js.map +0 -1
- package/lib/src/platform-permit.js.map +0 -1
- package/lib/src/segment-mapper.js +0 -2
- package/lib/src/segment-mapper.js.map +0 -1
- package/lib/src/telegram-agent-deps.js +0 -10
- package/lib/src/telegram-agent-deps.js.map +0 -1
- package/lib/src/types.js +0 -2
- package/lib/src/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -66
- package/src/segment-mapper.ts +0 -1
- 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
|
|
3
|
+
Zhin.js Telegram Bot API 适配器(Plugin Runtime),默认通过 **长轮询 `getUpdates`** 收发消息(无需 host)。
|
|
4
4
|
|
|
5
|
-
##
|
|
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
|
-
##
|
|
20
|
+
## Plugin Runtime
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
28
|
+
入站:`gateway.receive({ adapter, target: chatId, content: text, sender, metadata })`
|
|
29
|
+
出站:`send({ target, payload })` → Telegram Bot API
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
### 平台权限(platform permit)
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
- context: telegram
|
|
30
|
-
name: my-telegram-bot
|
|
31
|
-
token: "${TELEGRAM_TOKEN}"
|
|
32
|
-
polling: true
|
|
33
|
-
```
|
|
36
|
+
## 前置条件
|
|
34
37
|
|
|
35
|
-
|
|
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
|
-
|
|
45
|
+
必填字段(`endpoints[i]`):`name`、`token`。
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
## 最小配置
|
|
40
48
|
|
|
41
49
|
```yaml
|
|
50
|
+
# zhin.config.yml(Plugin Runtime)
|
|
42
51
|
plugins:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
endpoints:
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
+
## 环境变量
|
|
69
62
|
|
|
70
|
-
|
|
|
63
|
+
| 变量 | 说明 |
|
|
71
64
|
|------|------|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
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
|
-
##
|
|
68
|
+
## Webhook(延期)
|
|
99
69
|
|
|
100
|
-
|
|
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
|
-
|
|
72
|
+
> Telegram webhook mode is deferred until httpHostToken wiring; use polling: true (default) for now
|
|
111
73
|
|
|
112
|
-
|
|
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
|
-
##
|
|
76
|
+
## 消息类型映射
|
|
118
77
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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
|
-
##
|
|
96
|
+
## 故障排查
|
|
179
97
|
|
|
180
98
|
| 现象 | 排查 |
|
|
181
99
|
|------|------|
|
|
182
|
-
|
|
|
183
|
-
| Polling 报错 |
|
|
184
|
-
| Webhook
|
|
185
|
-
| 发送失败 | Token
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 名称'),
|
package/agent/tools/react.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 名称'),
|
package/agent/tools/send_poll.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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
|
+
}
|