@zhin.js/adapter-telegram 1.0.69 → 1.1.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 +816 -17
- package/README.md +106 -77
- package/adapters/telegram.js +34 -0
- package/adapters/telegram.ts +39 -0
- package/agent/PERMITS.md +24 -0
- package/agent/tools/create_invite.ts +18 -0
- package/agent/tools/list_admins.ts +24 -0
- package/agent/tools/member_count.ts +16 -0
- package/agent/tools/pin_message.ts +19 -0
- package/agent/tools/react.ts +18 -0
- package/agent/tools/send_poll.ts +32 -0
- package/agent/tools/send_sticker.ts +17 -0
- package/agent/tools/set_description.ts +17 -0
- package/agent/tools/set_permissions.ts +31 -0
- package/agent/tools/unpin_message.ts +19 -0
- package/commands/endpoint/add/[id].js +3 -0
- package/commands/endpoint/add/[id].ts +3 -0
- package/commands/endpoint/list.js +3 -0
- package/commands/endpoint/list.ts +3 -0
- package/commands/endpoint/remove/[id].js +3 -0
- package/commands/endpoint/remove/[id].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 +299 -0
- package/lib/protocol.js +474 -0
- package/lib/telegram-endpoint-commands.d.ts +1 -0
- package/lib/telegram-endpoint-commands.js +16 -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 +59 -28
- package/plugin.js +19 -0
- package/schema.json +110 -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 +767 -0
- package/src/telegram-endpoint-commands.ts +17 -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/src/adapter.ts +0 -64
- package/src/bot.ts +0 -983
- package/src/types.ts +0 -32
- /package/{skills/telegram/SKILL.md → agent/skills/telegram.md} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-telegram",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Zhin.js adapter for
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Zhin.js Telegram Bot API adapter for Plugin Runtime (long-poll getUpdates)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -32,43 +32,53 @@
|
|
|
32
32
|
"directory": "plugins/adapters/telegram"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"lucide-react": "^1.16.0",
|
|
42
|
-
"typescript": "^6.0.3",
|
|
43
|
-
"@zhin.js/cli": "1.0.77",
|
|
44
|
-
"@zhin.js/console": "2.0.24",
|
|
45
|
-
"zhin.js": "1.0.81"
|
|
35
|
+
"@zhin.js/adapter": "1.1.12",
|
|
36
|
+
"@zhin.js/core": "1.1.35",
|
|
37
|
+
"@zhin.js/feature-kit": "1.1.0",
|
|
38
|
+
"@zhin.js/host-http": "1.1.0",
|
|
39
|
+
"@zhin.js/im-contract": "1.1.0",
|
|
40
|
+
"@zhin.js/logger": "1.1.0"
|
|
46
41
|
},
|
|
47
42
|
"peerDependencies": {
|
|
48
|
-
"
|
|
49
|
-
"@zhin.js/
|
|
50
|
-
"@zhin.js/
|
|
51
|
-
"@zhin.js/
|
|
52
|
-
"zhin.js": "1.
|
|
43
|
+
"zod": "^4.0.0",
|
|
44
|
+
"@zhin.js/adapter": "^1.1.12",
|
|
45
|
+
"@zhin.js/agent": "^1.1.23",
|
|
46
|
+
"@zhin.js/command": "^1.1.0",
|
|
47
|
+
"@zhin.js/core": "^1.1.35",
|
|
48
|
+
"@zhin.js/permission": "^1.1.0",
|
|
49
|
+
"zhin.js": "^1.1.0"
|
|
53
50
|
},
|
|
54
51
|
"peerDependenciesMeta": {
|
|
55
|
-
"@zhin.js/
|
|
52
|
+
"@zhin.js/agent": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@zhin.js/command": {
|
|
56
56
|
"optional": true
|
|
57
57
|
},
|
|
58
|
-
"
|
|
58
|
+
"zhin.js": {
|
|
59
59
|
"optional": true
|
|
60
60
|
},
|
|
61
|
-
"
|
|
61
|
+
"zod": {
|
|
62
62
|
"optional": true
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^26.1.2",
|
|
67
|
+
"typescript": "^6.0.3",
|
|
68
|
+
"vitest": "^4.1.10",
|
|
69
|
+
"zod": "^4.4.3",
|
|
70
|
+
"@zhin.js/agent": "1.1.23",
|
|
71
|
+
"@zhin.js/host-http": "1.1.0",
|
|
72
|
+
"zhin.js": "1.1.0"
|
|
73
|
+
},
|
|
65
74
|
"files": [
|
|
75
|
+
"adapters",
|
|
76
|
+
"commands",
|
|
77
|
+
"plugin.js",
|
|
78
|
+
"schema.json",
|
|
66
79
|
"src",
|
|
67
80
|
"lib",
|
|
68
|
-
"
|
|
69
|
-
"dist",
|
|
70
|
-
"skills",
|
|
71
|
-
"plugin.yml",
|
|
81
|
+
"agent",
|
|
72
82
|
"README.md",
|
|
73
83
|
"CHANGELOG.md"
|
|
74
84
|
],
|
|
@@ -76,9 +86,30 @@
|
|
|
76
86
|
"access": "public",
|
|
77
87
|
"registry": "https://registry.npmjs.org"
|
|
78
88
|
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
91
|
+
},
|
|
92
|
+
"zhin": {
|
|
93
|
+
"protocol": 1,
|
|
94
|
+
"type": "plugin",
|
|
95
|
+
"entry": "./plugin.js",
|
|
96
|
+
"engine": "^1.0.0",
|
|
97
|
+
"runtime": "trusted",
|
|
98
|
+
"features": [
|
|
99
|
+
{
|
|
100
|
+
"package": "@zhin.js/adapter",
|
|
101
|
+
"api": "^1.0.0"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"package": "@zhin.js/command",
|
|
105
|
+
"api": "^1.0.0"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"plugins": []
|
|
109
|
+
},
|
|
79
110
|
"scripts": {
|
|
80
|
-
"build": "
|
|
81
|
-
"clean": "rimraf lib
|
|
82
|
-
"
|
|
111
|
+
"build": "tsc",
|
|
112
|
+
"clean": "rimraf lib",
|
|
113
|
+
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/telegram/tests"
|
|
83
114
|
}
|
|
84
115
|
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { createEndpointRuntimeState } from 'zhin.js/adapter';
|
|
3
|
+
import { definePlugin } from 'zhin.js';
|
|
4
|
+
import { permissionHostToken } from '@zhin.js/permission';
|
|
5
|
+
import { checkTelegramPlatformPermit } from "./lib/platform-permit.js";
|
|
6
|
+
import { telegramRuntimeStateToken } from "./lib/telegram-runtime-state.js";
|
|
7
|
+
export default definePlugin({
|
|
8
|
+
name: 'telegram',
|
|
9
|
+
metadata: {
|
|
10
|
+
displayName: 'Telegram Bot API Adapter',
|
|
11
|
+
},
|
|
12
|
+
setup(context) {
|
|
13
|
+
context.resources.provide(telegramRuntimeStateToken, createEndpointRuntimeState());
|
|
14
|
+
if (context.resources.has(permissionHostToken)) {
|
|
15
|
+
const host = context.resources.use(permissionHostToken);
|
|
16
|
+
return host.registerPlatform('telegram', checkTelegramPlatformPermit);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
package/schema.json
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"polling": {
|
|
7
|
+
"type": "boolean",
|
|
8
|
+
"default": true,
|
|
9
|
+
"description": "Long-poll getUpdates (default). Set false for webhook via httpHostToken."
|
|
10
|
+
},
|
|
11
|
+
"webhook": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"additionalProperties": false,
|
|
14
|
+
"description": "Webhook settings when polling is false.",
|
|
15
|
+
"properties": {
|
|
16
|
+
"domain": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"path": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"default": "/telegram/webhook"
|
|
22
|
+
},
|
|
23
|
+
"secretToken": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Verified via X-Telegram-Bot-Api-Secret-Token."
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"allowedUpdates": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"items": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
},
|
|
34
|
+
"default": [
|
|
35
|
+
"message",
|
|
36
|
+
"callback_query"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"apiBaseUrl": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"default": "https://api.telegram.org"
|
|
42
|
+
},
|
|
43
|
+
"master": {
|
|
44
|
+
"type": [
|
|
45
|
+
"string",
|
|
46
|
+
"number"
|
|
47
|
+
],
|
|
48
|
+
"description": "框架 master(Telegram user id;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
49
|
+
},
|
|
50
|
+
"trusted": {
|
|
51
|
+
"type": "array",
|
|
52
|
+
"items": {
|
|
53
|
+
"type": [
|
|
54
|
+
"string",
|
|
55
|
+
"number"
|
|
56
|
+
],
|
|
57
|
+
"description": "Trusted Telegram user id"
|
|
58
|
+
},
|
|
59
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
60
|
+
},
|
|
61
|
+
"endpoints": {
|
|
62
|
+
"type": "array",
|
|
63
|
+
"description": "多账号:一个插件实例挂多个 endpoint。每项与顶层字段同构(id 必填,其余覆盖顶层)",
|
|
64
|
+
"items": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"additionalProperties": true,
|
|
67
|
+
"properties": {
|
|
68
|
+
"master": {
|
|
69
|
+
"type": [
|
|
70
|
+
"string",
|
|
71
|
+
"number"
|
|
72
|
+
],
|
|
73
|
+
"description": "本 endpoint 的框架 master(Telegram user id);覆盖顶层 master"
|
|
74
|
+
},
|
|
75
|
+
"trusted": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"items": {
|
|
78
|
+
"type": [
|
|
79
|
+
"string",
|
|
80
|
+
"number"
|
|
81
|
+
],
|
|
82
|
+
"description": "Trusted Telegram user id"
|
|
83
|
+
},
|
|
84
|
+
"description": "本 endpoint 的 trusted 列表"
|
|
85
|
+
},
|
|
86
|
+
"token": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"description": "Telegram bot token"
|
|
89
|
+
},
|
|
90
|
+
"id": {
|
|
91
|
+
"type": "string",
|
|
92
|
+
"description": "Telegram bot name"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"required": [
|
|
96
|
+
"id",
|
|
97
|
+
"token"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"commandPrefix": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"default": "",
|
|
104
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"required": [
|
|
108
|
+
"endpoints"
|
|
109
|
+
]
|
|
110
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
|
+
import type { TelegramClient } from './endpoint.js';
|
|
3
|
+
import type { TelegramUpdate } from './protocol.js';
|
|
4
|
+
|
|
5
|
+
export type TelegramClientEventMap = Record<string, TelegramUpdate>;
|
|
6
|
+
|
|
7
|
+
declare module '@zhin.js/feature-kit' {
|
|
8
|
+
interface AdapterClientRegistry {
|
|
9
|
+
readonly telegram: {
|
|
10
|
+
readonly client: TelegramClient;
|
|
11
|
+
readonly events: TelegramClientEventMap;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const telegramClient = defineEndpointClient<TelegramClient, TelegramClientEventMap>('telegram');
|