@zhin.js/adapter-telegram 1.0.69 → 1.1.2
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 +909 -17
- package/PERMITS.md +24 -0
- package/README.md +106 -77
- package/adapters/telegram/index.js +34 -0
- package/adapters/telegram/index.ts +39 -0
- package/agents/telegram/agent.json +20 -0
- package/agents/telegram/boundaries.md +3 -0
- package/agents/telegram/conventions.md +3 -0
- package/agents/telegram/skills/telegram-chat-admin/SKILL.md +24 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/create_invite/index.js +18 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/create_invite/index.ts +18 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/list_admins/index.js +24 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/list_admins/index.ts +24 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/member_count/index.js +16 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/member_count/index.ts +16 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/pin_message/index.js +19 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/pin_message/index.ts +19 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/set_description/index.js +17 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/set_description/index.ts +17 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/set_permissions/index.js +32 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/set_permissions/index.ts +31 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/unpin_message/index.js +19 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/unpin_message/index.ts +19 -0
- package/agents/telegram/skills/telegram-messages/SKILL.md +19 -0
- package/agents/telegram/skills/telegram-messages/tools/react/index.js +18 -0
- package/agents/telegram/skills/telegram-messages/tools/react/index.ts +18 -0
- package/agents/telegram/skills/telegram-messages/tools/send_poll/index.js +30 -0
- package/agents/telegram/skills/telegram-messages/tools/send_poll/index.ts +32 -0
- package/agents/telegram/skills/telegram-messages/tools/send_sticker/index.js +17 -0
- package/agents/telegram/skills/telegram-messages/tools/send_sticker/index.ts +17 -0
- package/agents/telegram/system.md +3 -0
- package/commands/telegram/endpoint/add/[id]/index.js +3 -0
- package/commands/telegram/endpoint/add/[id]/index.ts +3 -0
- package/commands/telegram/endpoint/definition.js +17 -0
- package/commands/telegram/endpoint/definition.ts +17 -0
- package/commands/telegram/endpoint/list/index.js +3 -0
- package/commands/telegram/endpoint/list/index.ts +3 -0
- package/commands/telegram/endpoint/remove/[id]/index.js +3 -0
- package/commands/telegram/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +12 -0
- package/lib/client.js +2 -0
- package/lib/endpoint.d.ts +112 -0
- package/lib/endpoint.js +535 -0
- package/lib/index.d.ts +4 -18
- package/lib/index.js +4 -455
- package/lib/markdown-to-html.d.ts +9 -0
- package/lib/markdown-to-html.js +75 -0
- package/lib/platform-permit.d.ts +17 -0
- package/lib/platform-permit.js +51 -0
- package/lib/polling.d.ts +9 -0
- package/lib/polling.js +57 -0
- package/lib/protocol.d.ts +291 -0
- package/lib/protocol.js +463 -0
- package/lib/telegram-runtime-state.d.ts +1 -0
- package/lib/telegram-runtime-state.js +6 -0
- package/lib/webhook.d.ts +12 -0
- package/lib/webhook.js +55 -0
- package/package.json +72 -29
- package/plugin.js +19 -0
- package/schema.json +141 -0
- package/src/client.ts +16 -0
- package/src/endpoint.ts +679 -0
- package/src/index.ts +39 -426
- package/src/markdown-to-html.ts +86 -0
- package/src/platform-permit.ts +65 -0
- package/src/polling.ts +76 -0
- package/src/protocol.ts +744 -0
- package/src/telegram-runtime-state.ts +7 -0
- package/src/webhook.ts +75 -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 -17
- package/dist/index.js +0 -32
- package/lib/adapter.d.ts +0 -18
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -55
- package/lib/adapter.js.map +0 -1
- package/lib/bot.d.ts +0 -140
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -866
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -29
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/skills/telegram/SKILL.md +0 -103
- package/src/adapter.ts +0 -64
- package/src/bot.ts +0 -983
- package/src/types.ts +0 -32
package/PERMITS.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Telegram Platform Permits
|
|
2
|
+
|
|
3
|
+
## 入站字段
|
|
4
|
+
|
|
5
|
+
群/超级群消息经 `getChatMember`(TTL 60s)写入:
|
|
6
|
+
|
|
7
|
+
| 字段 | 取值 |
|
|
8
|
+
|------|------|
|
|
9
|
+
| `$sender.role` | `creator` · `administrator` · `member` |
|
|
10
|
+
| `$sender.permissions` | `chat_creator` · `chat_administrator` · `restrict_members` · `pin_messages` · `manage_chat` · … |
|
|
11
|
+
|
|
12
|
+
## Permit 词汇表
|
|
13
|
+
|
|
14
|
+
| `platform(telegram,…)` | 含义 |
|
|
15
|
+
|------------------------|------|
|
|
16
|
+
| `chat_creator` | 群主 |
|
|
17
|
+
| `chat_administrator` | 管理员 |
|
|
18
|
+
| `restrict_members` | 可禁言成员 |
|
|
19
|
+
| `pin_messages` | 可置顶 |
|
|
20
|
+
| `manage_chat` | 可改群默认权限 |
|
|
21
|
+
|
|
22
|
+
## 工厂映射
|
|
23
|
+
|
|
24
|
+
`scene_admin` → `chat_administrator` · `scene_owner` → `chat_creator`
|
package/README.md
CHANGED
|
@@ -1,107 +1,136 @@
|
|
|
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({ conversation, payload })` → Bot API(Markdown→安全 HTML / media / keyboard)
|
|
11
|
+
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
12
|
+
- Webhook 模式通过 `httpHostToken` 注册回调路由,支持 secretToken 校验
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
6
15
|
|
|
7
16
|
```bash
|
|
8
17
|
pnpm add @zhin.js/adapter-telegram
|
|
9
18
|
```
|
|
10
19
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { defineConfig } from 'zhin.js'
|
|
15
|
-
|
|
16
|
-
export default defineConfig({
|
|
17
|
-
bots: [
|
|
18
|
-
{
|
|
19
|
-
name: 'my-telegram-bot',
|
|
20
|
-
context: 'telegram',
|
|
21
|
-
token: 'YOUR_BOT_TOKEN', // Get from @BotFather
|
|
22
|
-
polling: true, // Use long polling (default)
|
|
23
|
-
// OR use webhooks:
|
|
24
|
-
// polling: false,
|
|
25
|
-
// webhook: {
|
|
26
|
-
// domain: 'https://yourdomain.com',
|
|
27
|
-
// path: '/telegram-webhook',
|
|
28
|
-
// port: 8443
|
|
29
|
-
// }
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
})
|
|
33
|
-
```
|
|
20
|
+
## Plugin Runtime
|
|
34
21
|
|
|
35
|
-
|
|
22
|
+
- `@zhin.js/adapter` — 约定式 `adapters/telegram/index.ts`(`defineAdapter`)
|
|
23
|
+
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
24
|
+
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
25
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
26
|
+
- **无需** `@zhin.js/host-http`(polling 路径)
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- ✅ Message formatting (bold, italic, code, links)
|
|
40
|
-
- ✅ Reply to messages
|
|
41
|
-
- ✅ Mentions (@username)
|
|
42
|
-
- ✅ Stickers and locations
|
|
43
|
-
- ✅ Callback queries (inline buttons)
|
|
44
|
-
- ✅ Long polling and webhook modes
|
|
45
|
-
- ✅ Private and group chats
|
|
28
|
+
入站:`gateway.receive({ conversation, message, content, sender, metadata })`(`conversation` 为 ConversationRef,由 `telegramInboundConversation` 归一化)
|
|
29
|
+
出站:`send({ conversation, payload })` → Telegram Bot API
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
### 平台权限(platform permit)
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
3. Copy the bot token provided
|
|
52
|
-
4. Add the token to your configuration
|
|
33
|
+
- sender role 已恢复:群消息入站时经 `getChatMember`(60s 缓存)解析,写入 `metadata.senderRole` / `metadata.senderPermissions`。
|
|
34
|
+
- `plugin.ts` 在 generation setup 注册 checker,并在 dispose 注销;Plugin Runtime CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费 `permissions`。
|
|
53
35
|
|
|
54
|
-
##
|
|
36
|
+
## 前置条件
|
|
55
37
|
|
|
56
|
-
|
|
38
|
+
| 要求 | 说明 |
|
|
39
|
+
|------|------|
|
|
40
|
+
| **Bot Token** | 通过 [@BotFather](https://t.me/botfather) 创建并获取 Token |
|
|
41
|
+
| **Polling(默认)** | 本地/生产均可;主动拉取更新,无需公网 HTTPS |
|
|
42
|
+
| **网络** | 出站可访问 `api.telegram.org` |
|
|
43
|
+
| **host-http** | Polling **不需要**;Webhook **需要** CLI HTTP Host |
|
|
57
44
|
|
|
58
|
-
|
|
59
|
-
import { usePlugin, MessageCommand } from 'zhin.js'
|
|
45
|
+
必填字段(`endpoints[i]`):`id`、`token`。
|
|
60
46
|
|
|
61
|
-
|
|
47
|
+
## 最小配置
|
|
62
48
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
```yaml
|
|
50
|
+
# zhin.config.yml(Plugin Runtime)
|
|
51
|
+
plugins:
|
|
52
|
+
telegram:
|
|
53
|
+
# polling: true # 默认
|
|
54
|
+
endpoints:
|
|
55
|
+
- id: my-telegram-bot
|
|
56
|
+
token: ${TELEGRAM_TOKEN}
|
|
68
57
|
```
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-telegram`(`instanceKey: telegram`)。
|
|
60
|
+
|
|
61
|
+
## 环境变量
|
|
62
|
+
|
|
63
|
+
| 变量 | 说明 |
|
|
64
|
+
|------|------|
|
|
65
|
+
| `TELEGRAM_TOKEN` | 示例中由 YAML `${TELEGRAM_TOKEN}` 引用的 Bot Token;变量名可自行定义 |
|
|
66
|
+
| `TELEGRAM_WEBHOOK_SECRET` | 示例中由 YAML `${TELEGRAM_WEBHOOK_SECRET}` 引用的 webhook secret;变量名可自行定义 |
|
|
67
|
+
|
|
68
|
+
## Webhook
|
|
69
|
+
|
|
70
|
+
配置 `polling: false`,启用 CLI HTTP Host,并提供公网 HTTPS 回调地址。
|
|
71
|
+
`webhook.path` 必须与反向代理转发路径一致,多账号使用不同路径。
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
http:
|
|
75
|
+
host: 127.0.0.1
|
|
76
|
+
port: 8086
|
|
77
|
+
plugins:
|
|
78
|
+
telegram:
|
|
79
|
+
polling: false
|
|
80
|
+
endpoints:
|
|
81
|
+
- id: my-telegram-bot
|
|
82
|
+
token: ${TELEGRAM_TOKEN}
|
|
83
|
+
webhook:
|
|
84
|
+
domain: https://bot.example.com
|
|
85
|
+
path: /telegram/webhook
|
|
86
|
+
secretToken: ${TELEGRAM_WEBHOOK_SECRET}
|
|
81
87
|
```
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
启动时注册 Host 路由并调用 `setWebhook`;停止时释放路由。
|
|
90
|
+
配置 `secretToken` 后,回调须携带匹配的 `X-Telegram-Bot-Api-Secret-Token`,否则返回 403。
|
|
84
91
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
## 稳定化范围
|
|
93
|
+
|
|
94
|
+
当前为 **Advanced / 首批升档候选**,完整适配器测试已纳入 `pnpm check:stable`。
|
|
95
|
+
长轮询停止会中止请求与退避;即使传输层在中止后返回更新,也不会派发或推进 offset。
|
|
96
|
+
轮询 offset 仅保存在当前 Endpoint 内存中,不承诺跨重启去重或业务处理恰好一次。
|
|
97
|
+
Webhook 接收确认不等于业务处理完成;需要幂等性的业务应自行持久化去重。
|
|
98
|
+
详见[平台稳定验收](https://github.com/zhinjs/zhin/blob/main/docs/contributing/platform-acceptance.md)。
|
|
99
|
+
|
|
100
|
+
## 消息类型映射
|
|
101
|
+
|
|
102
|
+
| Telegram | 入站 content(文本摘要) | 出站 wire |
|
|
103
|
+
|----------|--------------------------|-----------|
|
|
104
|
+
| text | 原文 | sendMessage |
|
|
105
|
+
| markdown | 原文 | sendMessage(`parse_mode: HTML`) |
|
|
106
|
+
| photo | `[image]` / caption | sendPhoto(`file_id` / `url`) |
|
|
107
|
+
| video | `[video]` | sendVideo |
|
|
108
|
+
| audio / voice | `[audio]` / `[voice]` | sendAudio / sendVoice |
|
|
109
|
+
| document | `[file: name]` | sendDocument |
|
|
110
|
+
| sticker | `[sticker: …]` | sendSticker |
|
|
111
|
+
| location | `[location: lat,lon]` | sendLocation |
|
|
112
|
+
| callback_query | `[action: data]` | — |
|
|
113
|
+
|
|
114
|
+
## AI tools
|
|
92
115
|
|
|
93
|
-
|
|
116
|
+
| Kind | Path |
|
|
117
|
+
|------|------|
|
|
118
|
+
| Platform tools (10) | `tools/`(invite / pin / admins / sticker / poll 等) |
|
|
119
|
+
| Skill doc | `agents/telegram/skills/telegram-chat-admin/SKILL.md`, `agents/telegram/skills/telegram-messages/SKILL.md` |
|
|
94
120
|
|
|
95
|
-
|
|
121
|
+
## 故障排查
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
| 现象 | 排查 |
|
|
124
|
+
|------|------|
|
|
125
|
+
| 收不到消息 | Token 是否正确;进程已 `open()`;同一 Token 勿多进程同时 polling |
|
|
126
|
+
| Polling 报错 | 检查能否访问 `api.telegram.org`;查看日志 `op: poll` |
|
|
127
|
+
| Webhook 配置报错 | 检查 HTTP Host、公网 HTTPS、反向代理路径与 secretToken |
|
|
128
|
+
| 发送失败 | Token 是否被撤销;查看 Bot API 错误描述 |
|
|
98
129
|
|
|
99
|
-
|
|
130
|
+
## Documentation
|
|
100
131
|
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
- URL
|
|
104
|
-
- Local file path
|
|
132
|
+
- [Telegram adapter on zhin.js.org](https://zhin.js.org/adapters/telegram)
|
|
133
|
+
- [Adapters overview](https://zhin.js.org/essentials/adapters)
|
|
105
134
|
|
|
106
135
|
## License
|
|
107
136
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Convention entry: discover `adapters/telegram/index.ts` → defineAdapter.
|
|
4
|
+
*/
|
|
5
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
+
import { TelegramEndpoint } from "../../lib/endpoint.js";
|
|
8
|
+
import { resolveTelegramConfig, } from "../../lib/protocol.js";
|
|
9
|
+
import { telegramRuntimeStateToken } from "../../lib/telegram-runtime-state.js";
|
|
10
|
+
export { TelegramEndpoint } from "../../lib/endpoint.js";
|
|
11
|
+
export default defineAdapter({
|
|
12
|
+
capabilities: ['inbound', 'outbound'],
|
|
13
|
+
operations: ['recall'],
|
|
14
|
+
// 媒体 url / file_id 直发,base64 / 本地路径经 multipart attach:// 上传物化;
|
|
15
|
+
// inline keyboard 原生按钮承载交互段。
|
|
16
|
+
segments: {
|
|
17
|
+
outboundMedia: ['url', 'upload'],
|
|
18
|
+
interactive: 'native',
|
|
19
|
+
markdown: 'native',
|
|
20
|
+
},
|
|
21
|
+
create(context) {
|
|
22
|
+
const config = resolveTelegramConfig(context.config);
|
|
23
|
+
// 注册到插件运行时状态(telegram endpoint list 的"运行中"数据源)
|
|
24
|
+
context.use(telegramRuntimeStateToken).endpoints.set(config.id, {
|
|
25
|
+
id: config.id,
|
|
26
|
+
mode: config.mode,
|
|
27
|
+
});
|
|
28
|
+
return new TelegramEndpoint({
|
|
29
|
+
id: context.id,
|
|
30
|
+
config,
|
|
31
|
+
http: config.mode === 'webhook' ? context.use(httpHostToken) : undefined,
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/telegram/index.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
6
|
+
import { TelegramEndpoint } from '../../src/endpoint.js';
|
|
7
|
+
import {
|
|
8
|
+
resolveTelegramConfig,
|
|
9
|
+
type TelegramEndpointConfig,
|
|
10
|
+
} from '../../src/protocol.js';
|
|
11
|
+
import { telegramRuntimeStateToken } from '../../src/telegram-runtime-state.js';
|
|
12
|
+
|
|
13
|
+
export { TelegramEndpoint } from '../../src/endpoint.js';
|
|
14
|
+
export type { TelegramEndpointOptions, TelegramFetch } from '../../src/endpoint.js';
|
|
15
|
+
|
|
16
|
+
export default defineAdapter<TelegramEndpointConfig>({
|
|
17
|
+
capabilities: ['inbound', 'outbound'],
|
|
18
|
+
operations: ['recall'],
|
|
19
|
+
// 媒体 url / file_id 直发,base64 / 本地路径经 multipart attach:// 上传物化;
|
|
20
|
+
// inline keyboard 原生按钮承载交互段。
|
|
21
|
+
segments: {
|
|
22
|
+
outboundMedia: ['url', 'upload'],
|
|
23
|
+
interactive: 'native',
|
|
24
|
+
markdown: 'native',
|
|
25
|
+
},
|
|
26
|
+
create(context) {
|
|
27
|
+
const config = resolveTelegramConfig(context.config);
|
|
28
|
+
// 注册到插件运行时状态(telegram endpoint list 的"运行中"数据源)
|
|
29
|
+
context.use(telegramRuntimeStateToken).endpoints.set(config.id, {
|
|
30
|
+
id: config.id,
|
|
31
|
+
mode: config.mode,
|
|
32
|
+
});
|
|
33
|
+
return new TelegramEndpoint({
|
|
34
|
+
id: context.id,
|
|
35
|
+
config,
|
|
36
|
+
http: config.mode === 'webhook' ? context.use(httpHostToken) : undefined,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "TELEGRAM Platform Agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Handles telegram platform-specific operations and progressively loads only the required platform Skill.",
|
|
5
|
+
"trigger_rules": {
|
|
6
|
+
"file_patterns": [],
|
|
7
|
+
"keywords": [
|
|
8
|
+
"telegram",
|
|
9
|
+
"adapter:telegram"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"entry_points": [
|
|
13
|
+
"system.md",
|
|
14
|
+
"boundaries.md",
|
|
15
|
+
"conventions.md"
|
|
16
|
+
],
|
|
17
|
+
"platforms": [
|
|
18
|
+
"telegram"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: telegram-chat-admin
|
|
3
|
+
platforms:
|
|
4
|
+
- telegram
|
|
5
|
+
description: Telegram 管理员查询、成员数、邀请、置顶和群权限设置能力。
|
|
6
|
+
keywords:
|
|
7
|
+
- "telegram"
|
|
8
|
+
- "admin"
|
|
9
|
+
- "invite"
|
|
10
|
+
- "pin"
|
|
11
|
+
- "permissions"
|
|
12
|
+
tools:
|
|
13
|
+
- "pin_message"
|
|
14
|
+
- "unpin_message"
|
|
15
|
+
- "list_admins"
|
|
16
|
+
- "member_count"
|
|
17
|
+
- "create_invite"
|
|
18
|
+
- "set_permissions"
|
|
19
|
+
- "set_description"
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# telegram-chat-admin
|
|
23
|
+
|
|
24
|
+
先读取管理员与成员状态,再执行邀请、置顶或权限变更。群设置写操作遵守审批策略。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '创建 Telegram 群组邀请链接',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'telegram',
|
|
11
|
+
tags: ['telegram'],
|
|
12
|
+
permissions: [platformPermission('telegram', 'chat_administrator')],
|
|
13
|
+
async execute({ chat_id }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
const link = await endpoint.createInviteLink(Number(chat_id));
|
|
16
|
+
return { invite_link: link, message: `邀请链接: ${link}` };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string }>({
|
|
6
|
+
description: '创建 Telegram 群组邀请链接',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'telegram',
|
|
11
|
+
tags: ['telegram'],
|
|
12
|
+
permissions: [platformPermission('telegram', 'chat_administrator')],
|
|
13
|
+
async execute({ chat_id }: { chat_id: string }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
const link = await endpoint.createInviteLink(Number(chat_id));
|
|
16
|
+
return { invite_link: link, message: `邀请链接: ${link}` };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '获取 Telegram 群组管理员列表',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'telegram',
|
|
10
|
+
tags: ['telegram'],
|
|
11
|
+
async execute({ chat_id }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
const admins = await endpoint.getChatAdmins(Number(chat_id));
|
|
14
|
+
return {
|
|
15
|
+
admins: admins.map((a) => ({
|
|
16
|
+
user_id: a.user.id,
|
|
17
|
+
username: a.user.username,
|
|
18
|
+
first_name: a.user.first_name,
|
|
19
|
+
status: a.status,
|
|
20
|
+
})),
|
|
21
|
+
count: admins.length,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ chat_id: string }>({
|
|
5
|
+
description: '获取 Telegram 群组管理员列表',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'telegram',
|
|
10
|
+
tags: ['telegram'],
|
|
11
|
+
async execute({ chat_id }: { chat_id: string }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
const admins = await endpoint.getChatAdmins(Number(chat_id));
|
|
14
|
+
return {
|
|
15
|
+
admins: admins.map((a: { user: { id: number; username?: string; first_name?: string }; status: string }) => ({
|
|
16
|
+
user_id: a.user.id,
|
|
17
|
+
username: a.user.username,
|
|
18
|
+
first_name: a.user.first_name,
|
|
19
|
+
status: a.status,
|
|
20
|
+
})),
|
|
21
|
+
count: admins.length,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '获取 Telegram 群组成员数量',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'telegram',
|
|
10
|
+
tags: ['telegram'],
|
|
11
|
+
async execute({ chat_id }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
const count = await endpoint.getChatMemberCount(Number(chat_id));
|
|
14
|
+
return { count, message: `群组共有 ${count} 名成员` };
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ chat_id: string }>({
|
|
5
|
+
description: '获取 Telegram 群组成员数量',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'telegram',
|
|
10
|
+
tags: ['telegram'],
|
|
11
|
+
async execute({ chat_id }: { chat_id: string }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
const count = await endpoint.getChatMemberCount(Number(chat_id));
|
|
14
|
+
return { count, message: `群组共有 ${count} 名成员` };
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '置顶 Telegram 群组消息',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
message_id: z.string().describe('消息 ID'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'telegram',
|
|
12
|
+
tags: ['telegram'],
|
|
13
|
+
permissions: [platformPermission('telegram', 'pin_messages')],
|
|
14
|
+
async execute({ chat_id, message_id }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.pinMessage(Number(chat_id), Number(message_id));
|
|
17
|
+
return { success, message: success ? '消息已置顶' : '操作失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string; message_id: string }>({
|
|
6
|
+
description: '置顶 Telegram 群组消息',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
message_id: z.string().describe('消息 ID'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'telegram',
|
|
12
|
+
tags: ['telegram'],
|
|
13
|
+
permissions: [platformPermission('telegram', 'pin_messages')],
|
|
14
|
+
async execute({ chat_id, message_id }: { chat_id: string; message_id: string }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.pinMessage(Number(chat_id), Number(message_id));
|
|
17
|
+
return { success, message: success ? '消息已置顶' : '操作失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '设置 Telegram 群组描述',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
description: z.string().describe('群描述文字'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'telegram',
|
|
11
|
+
tags: ['telegram'],
|
|
12
|
+
async execute({ chat_id, description }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
const success = await endpoint.setChatDescription(Number(chat_id), description);
|
|
15
|
+
return { success, message: success ? '群描述已更新' : '操作失败' };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ chat_id: string; description: string }>({
|
|
5
|
+
description: '设置 Telegram 群组描述',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
8
|
+
description: z.string().describe('群描述文字'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'telegram',
|
|
11
|
+
tags: ['telegram'],
|
|
12
|
+
async execute({ chat_id, description }: { chat_id: string; description: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
const success = await endpoint.setChatDescription(Number(chat_id), description);
|
|
15
|
+
return { success, message: success ? '群描述已更新' : '操作失败' };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '设置 Telegram 群组的默认成员权限',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
can_send_messages: z.boolean().optional().describe('是否可以发消息'),
|
|
10
|
+
can_send_photos: z.boolean().optional().describe('是否可以发图片'),
|
|
11
|
+
can_send_videos: z.boolean().optional().describe('是否可以发视频'),
|
|
12
|
+
can_send_polls: z.boolean().optional().describe('是否可以发投票'),
|
|
13
|
+
can_send_other_messages: z.boolean().optional().describe('是否可以发贴纸/GIF等'),
|
|
14
|
+
can_add_web_page_previews: z.boolean().optional().describe('是否可以添加网页预览'),
|
|
15
|
+
can_change_info: z.boolean().optional().describe('是否可以改群信息'),
|
|
16
|
+
can_invite_users: z.boolean().optional().describe('是否可以邀请用户'),
|
|
17
|
+
can_pin_messages: z.boolean().optional().describe('是否可以置顶消息'),
|
|
18
|
+
}),
|
|
19
|
+
adapter: 'telegram',
|
|
20
|
+
tags: ['telegram'],
|
|
21
|
+
permissions: [platformPermission('telegram', 'manage_chat')],
|
|
22
|
+
async execute({ chat_id, ...perms }, context) {
|
|
23
|
+
const endpoint = context.$client;
|
|
24
|
+
const permissions = {};
|
|
25
|
+
for (const [k, v] of Object.entries(perms)) {
|
|
26
|
+
if (typeof v === 'boolean')
|
|
27
|
+
permissions[k] = v;
|
|
28
|
+
}
|
|
29
|
+
const success = await endpoint.setChatPermissionsAll(Number(chat_id), permissions);
|
|
30
|
+
return { success, message: success ? '群权限已更新' : '操作失败' };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ 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
|
+
description: '设置 Telegram 群组的默认成员权限',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('聊天 ID'),
|
|
9
|
+
can_send_messages: z.boolean().optional().describe('是否可以发消息'),
|
|
10
|
+
can_send_photos: z.boolean().optional().describe('是否可以发图片'),
|
|
11
|
+
can_send_videos: z.boolean().optional().describe('是否可以发视频'),
|
|
12
|
+
can_send_polls: z.boolean().optional().describe('是否可以发投票'),
|
|
13
|
+
can_send_other_messages: z.boolean().optional().describe('是否可以发贴纸/GIF等'),
|
|
14
|
+
can_add_web_page_previews: z.boolean().optional().describe('是否可以添加网页预览'),
|
|
15
|
+
can_change_info: z.boolean().optional().describe('是否可以改群信息'),
|
|
16
|
+
can_invite_users: z.boolean().optional().describe('是否可以邀请用户'),
|
|
17
|
+
can_pin_messages: z.boolean().optional().describe('是否可以置顶消息'),
|
|
18
|
+
}),
|
|
19
|
+
adapter: 'telegram',
|
|
20
|
+
tags: ['telegram'],
|
|
21
|
+
permissions: [platformPermission('telegram', 'manage_chat')],
|
|
22
|
+
async execute({ chat_id, ...perms }: { 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 }, context) {
|
|
23
|
+
const endpoint = context.$client;
|
|
24
|
+
const permissions: Record<string, boolean> = {};
|
|
25
|
+
for (const [k, v] of Object.entries(perms)) {
|
|
26
|
+
if (typeof v === 'boolean') permissions[k] = v;
|
|
27
|
+
}
|
|
28
|
+
const success = await endpoint.setChatPermissionsAll(Number(chat_id), permissions);
|
|
29
|
+
return { success, message: success ? '群权限已更新' : '操作失败' };
|
|
30
|
+
},
|
|
31
|
+
});
|