@zhin.js/adapter-telegram 1.1.25 → 1.1.27
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 +185 -0
- package/LICENSE +21 -0
- package/PERMITS.md +17 -13
- package/README.md +9 -5
- package/adapters/telegram/index.js +3 -0
- package/adapters/telegram/index.ts +3 -0
- package/agents/telegram/conversation.js +35 -0
- package/agents/telegram/conversation.ts +38 -0
- package/agents/telegram/messages.js +8 -0
- package/agents/telegram/messages.ts +8 -0
- package/agents/telegram/skills/telegram-chat-admin/tools/create_invite/index.js +6 -8
- package/agents/telegram/skills/telegram-chat-admin/tools/create_invite/index.ts +7 -9
- package/agents/telegram/skills/telegram-chat-admin/tools/list_admins/index.js +5 -7
- package/agents/telegram/skills/telegram-chat-admin/tools/list_admins/index.ts +6 -8
- package/agents/telegram/skills/telegram-chat-admin/tools/member_count/index.js +5 -7
- package/agents/telegram/skills/telegram-chat-admin/tools/member_count/index.ts +6 -8
- package/agents/telegram/skills/telegram-chat-admin/tools/pin_message/index.js +5 -6
- package/agents/telegram/skills/telegram-chat-admin/tools/pin_message/index.ts +6 -7
- package/agents/telegram/skills/telegram-chat-admin/tools/set_description/index.js +5 -4
- package/agents/telegram/skills/telegram-chat-admin/tools/set_description/index.ts +6 -5
- package/agents/telegram/skills/telegram-chat-admin/tools/unpin_message/index.js +5 -6
- package/agents/telegram/skills/telegram-chat-admin/tools/unpin_message/index.ts +6 -7
- package/agents/telegram/skills/telegram-group-permissions/tools/set_permissions/index.js +5 -6
- package/agents/telegram/skills/telegram-group-permissions/tools/set_permissions/index.ts +6 -7
- package/agents/telegram/skills/telegram-messages/tools/react/index.js +5 -6
- package/agents/telegram/skills/telegram-messages/tools/react/index.ts +6 -7
- package/agents/telegram/skills/telegram-messages/tools/send_poll/index.js +8 -7
- package/agents/telegram/skills/telegram-messages/tools/send_poll/index.ts +9 -8
- package/agents/telegram/skills/telegram-messages/tools/send_sticker/index.js +7 -7
- package/agents/telegram/skills/telegram-messages/tools/send_sticker/index.ts +8 -8
- package/lib/console-spec.js +85 -8
- package/lib/endpoint.d.ts +2 -1
- package/lib/endpoint.js +75 -21
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/platform-permit.d.ts +16 -16
- package/lib/platform-permit.js +26 -45
- package/lib/protocol.d.ts +25 -4
- package/lib/protocol.js +31 -16
- package/lib/webhook.d.ts +1 -2
- package/lib/webhook.js +9 -20
- package/package.json +23 -27
- package/plugin.js +0 -6
- package/schema.json +0 -56
- package/src/console-spec.ts +85 -8
- package/src/endpoint.ts +73 -25
- package/src/index.ts +1 -3
- package/src/platform-permit.ts +27 -56
- package/src/protocol.ts +52 -20
- package/src/webhook.ts +11 -23
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { currentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
6
6
|
export default defineAgentTool({
|
|
7
|
-
description: '
|
|
7
|
+
description: '置顶当前 Telegram 群组中的消息',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
message_id: z.string().describe('消息 ID'),
|
|
11
10
|
}),
|
|
12
11
|
adapter: 'telegram',
|
|
13
12
|
scopes: ["group", "channel"],
|
|
14
13
|
tags: ['telegram'],
|
|
15
|
-
permissions: [
|
|
16
|
-
async execute({
|
|
14
|
+
permissions: ['platform-permission:pin_messages', 'bot-permission:pin_messages'],
|
|
15
|
+
async execute({ message_id }, context) {
|
|
17
16
|
const endpoint = context.$client;
|
|
18
|
-
const success = await endpoint.pinMessage(
|
|
17
|
+
const success = await endpoint.pinMessage(currentChat(context), Number(message_id));
|
|
19
18
|
return { success, message: success ? t(context.locale, 'pinDone') : t(context.locale, 'operationFailed') };
|
|
20
19
|
},
|
|
21
20
|
});
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { currentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
|
-
export default defineAgentTool<{
|
|
7
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ message_id: string }>({
|
|
7
|
+
description: '置顶当前 Telegram 群组中的消息',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
message_id: z.string().describe('消息 ID'),
|
|
11
10
|
}),
|
|
12
11
|
adapter: 'telegram',
|
|
13
12
|
scopes: ["group","channel"],
|
|
14
13
|
tags: ['telegram'],
|
|
15
|
-
permissions: [
|
|
16
|
-
async execute({
|
|
14
|
+
permissions: ['platform-permission:pin_messages', 'bot-permission:pin_messages'],
|
|
15
|
+
async execute({ message_id }, context) {
|
|
17
16
|
const endpoint = context.$client;
|
|
18
|
-
const success = await endpoint.pinMessage(
|
|
17
|
+
const success = await endpoint.pinMessage(currentChat(context), Number(message_id));
|
|
19
18
|
return { success, message: success ? t(context.locale, 'pinDone') : t(context.locale, 'operationFailed') };
|
|
20
19
|
},
|
|
21
20
|
});
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { currentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
export default defineAgentTool({
|
|
6
|
-
description: '
|
|
7
|
+
description: '设置当前 Telegram 群组描述',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
9
9
|
description: z.string().describe('群描述文字'),
|
|
10
10
|
}),
|
|
11
11
|
adapter: 'telegram',
|
|
12
12
|
scopes: ["group", "channel"],
|
|
13
|
+
permissions: ['platform-permission:change_info', 'bot-permission:change_info'],
|
|
13
14
|
tags: ['telegram'],
|
|
14
|
-
async execute({
|
|
15
|
+
async execute({ description }, context) {
|
|
15
16
|
const endpoint = context.$client;
|
|
16
|
-
const success = await endpoint.setChatDescription(
|
|
17
|
+
const success = await endpoint.setChatDescription(currentChat(context), description);
|
|
17
18
|
return { success, message: success ? t(context.locale, 'descriptionUpdated') : t(context.locale, 'operationFailed') };
|
|
18
19
|
},
|
|
19
20
|
});
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { currentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
|
-
export default defineAgentTool<{
|
|
6
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ description: string }>({
|
|
7
|
+
description: '设置当前 Telegram 群组描述',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
9
9
|
description: z.string().describe('群描述文字'),
|
|
10
10
|
}),
|
|
11
11
|
adapter: 'telegram',
|
|
12
12
|
scopes: ["group","channel"],
|
|
13
|
+
permissions: ['platform-permission:change_info', 'bot-permission:change_info'],
|
|
13
14
|
tags: ['telegram'],
|
|
14
|
-
async execute({
|
|
15
|
+
async execute({ description }, context) {
|
|
15
16
|
const endpoint = context.$client;
|
|
16
|
-
const success = await endpoint.setChatDescription(
|
|
17
|
+
const success = await endpoint.setChatDescription(currentChat(context), description);
|
|
17
18
|
return { success, message: success ? t(context.locale, 'descriptionUpdated') : t(context.locale, 'operationFailed') };
|
|
18
19
|
},
|
|
19
20
|
});
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { currentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
6
6
|
export default defineAgentTool({
|
|
7
|
-
description: '
|
|
7
|
+
description: '取消置顶当前 Telegram 群组中的消息',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
message_id: z.string().optional().describe('消息 ID(可选,不提供则取消所有置顶)'),
|
|
11
10
|
}),
|
|
12
11
|
adapter: 'telegram',
|
|
13
12
|
scopes: ["group", "channel"],
|
|
14
13
|
tags: ['telegram'],
|
|
15
|
-
permissions: [
|
|
16
|
-
async execute({
|
|
14
|
+
permissions: ['platform-permission:pin_messages', 'bot-permission:pin_messages'],
|
|
15
|
+
async execute({ message_id }, context) {
|
|
17
16
|
const endpoint = context.$client;
|
|
18
|
-
const success = await endpoint.unpinMessage(
|
|
17
|
+
const success = await endpoint.unpinMessage(currentChat(context), message_id ? Number(message_id) : undefined);
|
|
19
18
|
return { success, message: success ? t(context.locale, 'messageUnpinned') : t(context.locale, 'operationFailed') };
|
|
20
19
|
},
|
|
21
20
|
});
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { currentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
|
-
export default defineAgentTool<{
|
|
7
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ message_id?: string }>({
|
|
7
|
+
description: '取消置顶当前 Telegram 群组中的消息',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
message_id: z.string().optional().describe('消息 ID(可选,不提供则取消所有置顶)'),
|
|
11
10
|
}),
|
|
12
11
|
adapter: 'telegram',
|
|
13
12
|
scopes: ["group","channel"],
|
|
14
13
|
tags: ['telegram'],
|
|
15
|
-
permissions: [
|
|
16
|
-
async execute({
|
|
14
|
+
permissions: ['platform-permission:pin_messages', 'bot-permission:pin_messages'],
|
|
15
|
+
async execute({ message_id }, context) {
|
|
17
16
|
const endpoint = context.$client;
|
|
18
|
-
const success = await endpoint.unpinMessage(
|
|
17
|
+
const success = await endpoint.unpinMessage(currentChat(context), message_id ? Number(message_id) : undefined);
|
|
19
18
|
return { success, message: success ? t(context.locale, 'messageUnpinned') : t(context.locale, 'operationFailed') };
|
|
20
19
|
},
|
|
21
20
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { currentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
6
6
|
export default defineAgentTool({
|
|
7
|
-
description: '
|
|
7
|
+
description: '设置当前 Telegram 群组的默认成员权限',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
can_send_messages: z.boolean().optional().describe('是否可以发消息'),
|
|
11
10
|
can_send_photos: z.boolean().optional().describe('是否可以发图片'),
|
|
12
11
|
can_send_videos: z.boolean().optional().describe('是否可以发视频'),
|
|
@@ -20,15 +19,15 @@ export default defineAgentTool({
|
|
|
20
19
|
adapter: 'telegram',
|
|
21
20
|
scopes: ["group"],
|
|
22
21
|
tags: ['telegram'],
|
|
23
|
-
permissions: [
|
|
24
|
-
async execute(
|
|
22
|
+
permissions: ['platform-permission:restrict_members', 'bot-permission:restrict_members'],
|
|
23
|
+
async execute(perms, context) {
|
|
25
24
|
const endpoint = context.$client;
|
|
26
25
|
const permissions = {};
|
|
27
26
|
for (const [k, v] of Object.entries(perms)) {
|
|
28
27
|
if (typeof v === 'boolean')
|
|
29
28
|
permissions[k] = v;
|
|
30
29
|
}
|
|
31
|
-
const success = await endpoint.setChatPermissionsAll(
|
|
30
|
+
const success = await endpoint.setChatPermissionsAll(currentChat(context), permissions);
|
|
32
31
|
return { success, message: success ? t(context.locale, 'permissionsUpdated') : t(context.locale, 'operationFailed') };
|
|
33
32
|
},
|
|
34
33
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { currentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
|
-
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
|
-
export default defineAgentTool<{
|
|
7
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ 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
|
+
description: '设置当前 Telegram 群组的默认成员权限',
|
|
8
8
|
inputSchema: z.object({
|
|
9
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
10
9
|
can_send_messages: z.boolean().optional().describe('是否可以发消息'),
|
|
11
10
|
can_send_photos: z.boolean().optional().describe('是否可以发图片'),
|
|
12
11
|
can_send_videos: z.boolean().optional().describe('是否可以发视频'),
|
|
@@ -20,14 +19,14 @@ export default defineAgentTool<{ chat_id: string; can_send_messages?: boolean; c
|
|
|
20
19
|
adapter: 'telegram',
|
|
21
20
|
scopes: ["group"],
|
|
22
21
|
tags: ['telegram'],
|
|
23
|
-
permissions: [
|
|
24
|
-
async execute(
|
|
22
|
+
permissions: ['platform-permission:restrict_members', 'bot-permission:restrict_members'],
|
|
23
|
+
async execute(perms: { 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) {
|
|
25
24
|
const endpoint = context.$client;
|
|
26
25
|
const permissions: Record<string, boolean> = {};
|
|
27
26
|
for (const [k, v] of Object.entries(perms)) {
|
|
28
27
|
if (typeof v === 'boolean') permissions[k] = v;
|
|
29
28
|
}
|
|
30
|
-
const success = await endpoint.setChatPermissionsAll(
|
|
29
|
+
const success = await endpoint.setChatPermissionsAll(currentChat(context), permissions);
|
|
31
30
|
return { success, message: success ? t(context.locale, 'permissionsUpdated') : t(context.locale, 'operationFailed') };
|
|
32
31
|
},
|
|
33
32
|
});
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { currentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
export default defineAgentTool({
|
|
6
|
-
description: '
|
|
7
|
+
description: '对当前 Telegram 会话中的消息添加表情反应',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
|
|
9
|
-
message_id: z.string().describe('消息 ID'),
|
|
9
|
+
message_id: z.string().describe('当前会话中的消息 ID'),
|
|
10
10
|
reaction: z.string().describe('反应表情(如 👍、❤️、🔥)'),
|
|
11
11
|
}),
|
|
12
12
|
adapter: 'telegram',
|
|
13
13
|
tags: ['telegram'],
|
|
14
|
-
async execute({
|
|
15
|
-
const
|
|
16
|
-
const success = await endpoint.setMessageReaction(Number(chat_id), Number(message_id), reaction);
|
|
14
|
+
async execute({ message_id, reaction }, context) {
|
|
15
|
+
const success = await context.$client.setMessageReaction(currentChat(context, { allowPrivate: true }), Number(message_id), reaction);
|
|
17
16
|
return { success, message: success ? t(context.locale, 'reactionAdded', { p0: reaction }) : t(context.locale, 'operationFailed') };
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { currentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
|
-
export default defineAgentTool<{
|
|
6
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ message_id: string; reaction: string }>({
|
|
7
|
+
description: '对当前 Telegram 会话中的消息添加表情反应',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
|
|
9
|
-
message_id: z.string().describe('消息 ID'),
|
|
9
|
+
message_id: z.string().describe('当前会话中的消息 ID'),
|
|
10
10
|
reaction: z.string().describe('反应表情(如 👍、❤️、🔥)'),
|
|
11
11
|
}),
|
|
12
12
|
adapter: 'telegram',
|
|
13
13
|
tags: ['telegram'],
|
|
14
|
-
async execute({
|
|
15
|
-
const
|
|
16
|
-
const success = await endpoint.setMessageReaction(Number(chat_id), Number(message_id), reaction);
|
|
14
|
+
async execute({ message_id, reaction }, context) {
|
|
15
|
+
const success = await context.$client.setMessageReaction(currentChat(context, { allowPrivate: true }), Number(message_id), reaction);
|
|
17
16
|
return { success, message: success ? t(context.locale, 'reactionAdded', { p0: reaction }) : t(context.locale, 'operationFailed') };
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { sendToCurrentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
export default defineAgentTool({
|
|
6
|
-
description: '
|
|
7
|
+
description: '在当前 Telegram 会话中发起投票',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
9
9
|
question: z.string().describe('投票问题'),
|
|
10
10
|
options: z.string().describe('选项 JSON 数组,如 ["A","B","C"]'),
|
|
11
11
|
is_anonymous: z.boolean().optional().describe('是否匿名投票,默认 true'),
|
|
@@ -13,8 +13,7 @@ export default defineAgentTool({
|
|
|
13
13
|
}),
|
|
14
14
|
adapter: 'telegram',
|
|
15
15
|
tags: ['telegram'],
|
|
16
|
-
async execute({
|
|
17
|
-
const endpoint = context.$client;
|
|
16
|
+
async execute({ question, options, is_anonymous, allows_multiple }, context) {
|
|
18
17
|
let optList;
|
|
19
18
|
try {
|
|
20
19
|
optList = JSON.parse(options);
|
|
@@ -25,8 +24,10 @@ export default defineAgentTool({
|
|
|
25
24
|
if (!Array.isArray(optList) || optList.length < 2) {
|
|
26
25
|
return { success: false, message: t(context.locale, 'pollOptionCount') };
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
// `telegram:poll` is the Telegram adapter's namespaced outbound segment.
|
|
28
|
+
const result = await sendToCurrentChat(context, { type: 'telegram:poll', data: {
|
|
29
|
+
question, options: optList, is_anonymous: is_anonymous ?? true, allows_multiple_answers: allows_multiple ?? false,
|
|
30
|
+
} });
|
|
31
|
+
return { ...result, message: t(context.locale, result.success ? 'pollSent' : 'operationFailed') };
|
|
31
32
|
},
|
|
32
33
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { sendToCurrentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
|
-
export default defineAgentTool<{
|
|
6
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ question: string; options: string; is_anonymous?: boolean; allows_multiple?: boolean }>({
|
|
7
|
+
description: '在当前 Telegram 会话中发起投票',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
chat_id: z.string().describe('聊天 ID'),
|
|
9
9
|
question: z.string().describe('投票问题'),
|
|
10
10
|
options: z.string().describe('选项 JSON 数组,如 ["A","B","C"]'),
|
|
11
11
|
is_anonymous: z.boolean().optional().describe('是否匿名投票,默认 true'),
|
|
@@ -13,8 +13,7 @@ export default defineAgentTool<{ chat_id: string; question: string; options: str
|
|
|
13
13
|
}),
|
|
14
14
|
adapter: 'telegram',
|
|
15
15
|
tags: ['telegram'],
|
|
16
|
-
async execute({
|
|
17
|
-
const endpoint = context.$client;
|
|
16
|
+
async execute({ question, options, is_anonymous, allows_multiple }, context) {
|
|
18
17
|
let optList: string[];
|
|
19
18
|
try {
|
|
20
19
|
optList = JSON.parse(options);
|
|
@@ -24,8 +23,10 @@ export default defineAgentTool<{ chat_id: string; question: string; options: str
|
|
|
24
23
|
if (!Array.isArray(optList) || optList.length < 2) {
|
|
25
24
|
return { success: false, message: t(context.locale, 'pollOptionCount') };
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
// `telegram:poll` is the Telegram adapter's namespaced outbound segment.
|
|
27
|
+
const result = await sendToCurrentChat(context, { type: 'telegram:poll', data: {
|
|
28
|
+
question, options: optList, is_anonymous: is_anonymous ?? true, allows_multiple_answers: allows_multiple ?? false,
|
|
29
|
+
} });
|
|
30
|
+
return { ...result, message: t(context.locale, result.success ? 'pollSent' : 'operationFailed') };
|
|
30
31
|
},
|
|
31
32
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { messages as t } from "../../../../messages.js";
|
|
3
|
+
import { sendToCurrentChat } from "../../../../conversation.js";
|
|
3
4
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
export default defineAgentTool({
|
|
6
|
-
description: '
|
|
7
|
+
description: '在当前 Telegram 会话发送贴纸',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
|
|
9
|
-
sticker: z.string().describe('贴纸 file_id 或 URL'),
|
|
9
|
+
sticker: z.string().describe('贴纸 file_id 或 http(s) URL'),
|
|
10
10
|
}),
|
|
11
11
|
adapter: 'telegram',
|
|
12
12
|
tags: ['telegram'],
|
|
13
|
-
async execute({
|
|
14
|
-
|
|
15
|
-
const result = await
|
|
16
|
-
return {
|
|
13
|
+
async execute({ sticker }, context) {
|
|
14
|
+
// `telegram:sticker` is the Telegram adapter's namespaced outbound segment.
|
|
15
|
+
const result = await sendToCurrentChat(context, { type: 'telegram:sticker', data: { sticker } });
|
|
16
|
+
return { ...result, message: t(context.locale, result.success ? 'stickerSent' : 'operationFailed') };
|
|
17
17
|
},
|
|
18
18
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { messages as t } from "../../../../messages.js";
|
|
2
|
+
import { sendToCurrentChat } from "../../../../conversation.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
|
-
export default defineAgentTool<{
|
|
6
|
-
description: '
|
|
6
|
+
export default defineAgentTool<{ sticker: string }>({
|
|
7
|
+
description: '在当前 Telegram 会话发送贴纸',
|
|
7
8
|
inputSchema: z.object({
|
|
8
|
-
|
|
9
|
-
sticker: z.string().describe('贴纸 file_id 或 URL'),
|
|
9
|
+
sticker: z.string().describe('贴纸 file_id 或 http(s) URL'),
|
|
10
10
|
}),
|
|
11
11
|
adapter: 'telegram',
|
|
12
12
|
tags: ['telegram'],
|
|
13
|
-
async execute({
|
|
14
|
-
|
|
15
|
-
const result = await
|
|
16
|
-
return {
|
|
13
|
+
async execute({ sticker }, context) {
|
|
14
|
+
// `telegram:sticker` is the Telegram adapter's namespaced outbound segment.
|
|
15
|
+
const result = await sendToCurrentChat(context, { type: 'telegram:sticker', data: { sticker } });
|
|
16
|
+
return { ...result, message: t(context.locale, result.success ? 'stickerSent' : 'operationFailed') };
|
|
17
17
|
},
|
|
18
18
|
});
|
package/lib/console-spec.js
CHANGED
|
@@ -2,14 +2,91 @@ export const telegramConsoleSpec = {
|
|
|
2
2
|
adapterKey: 'telegram',
|
|
3
3
|
adapterDisplayName: 'Telegram',
|
|
4
4
|
fields: [
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
{
|
|
6
|
+
key: 'token',
|
|
7
|
+
required: true,
|
|
8
|
+
env: true,
|
|
9
|
+
label: 'Bot Token (机器人令牌)',
|
|
10
|
+
labelI18n: { en: 'Bot Token' },
|
|
11
|
+
group: '基础认证',
|
|
12
|
+
groupI18n: { en: 'Basic Auth' },
|
|
13
|
+
placeholder: '123456789:AAH...',
|
|
14
|
+
description: '从 @BotFather 获取的 Telegram Bot Token',
|
|
15
|
+
descriptionI18n: { en: 'Telegram bot token from @BotFather' },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: 'polling',
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
label: '长轮询模式 (Polling)',
|
|
21
|
+
labelI18n: { en: 'Long Polling Mode' },
|
|
22
|
+
group: '连接与回调',
|
|
23
|
+
groupI18n: { en: 'Connection & Webhook' },
|
|
24
|
+
description: '开启后使用长轮询拉取消息;关闭则使用 Webhook 模式',
|
|
25
|
+
descriptionI18n: { en: 'Use long polling; false selects webhook mode' },
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: 'webhook.domain',
|
|
29
|
+
label: 'Webhook 公网域名',
|
|
30
|
+
labelI18n: { en: 'Webhook Public Domain' },
|
|
31
|
+
group: '连接与回调',
|
|
32
|
+
groupI18n: { en: 'Connection & Webhook' },
|
|
33
|
+
placeholder: 'https://bot.example.com',
|
|
34
|
+
description: 'Webhook 模式的公网访问域名(Origin)',
|
|
35
|
+
descriptionI18n: { en: 'Public webhook origin' },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: 'webhook.path',
|
|
39
|
+
label: 'Webhook 本地路由',
|
|
40
|
+
labelI18n: { en: 'Webhook Local Path' },
|
|
41
|
+
group: '连接与回调',
|
|
42
|
+
groupI18n: { en: 'Connection & Webhook' },
|
|
43
|
+
placeholder: '/telegram/webhook',
|
|
44
|
+
description: '本地 HTTP 服务监听的 Webhook 路径',
|
|
45
|
+
descriptionI18n: { en: 'Local webhook route' },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'webhook.secretToken',
|
|
49
|
+
env: true,
|
|
50
|
+
label: 'Webhook 签名密钥',
|
|
51
|
+
labelI18n: { en: 'Webhook Secret Token' },
|
|
52
|
+
group: '连接与回调',
|
|
53
|
+
groupI18n: { en: 'Connection & Webhook' },
|
|
54
|
+
placeholder: '自定义随机字符串(校验 X-Telegram-Bot-Api-Secret-Token)',
|
|
55
|
+
placeholderI18n: { en: 'Optional secret token for webhook header verification' },
|
|
56
|
+
description: 'Webhook 请求头校验密钥(可选)',
|
|
57
|
+
descriptionI18n: { en: 'Webhook secret token' },
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: 'streaming',
|
|
61
|
+
type: 'boolean',
|
|
62
|
+
label: '流式草稿回复',
|
|
63
|
+
labelI18n: { en: 'Streaming Draft Reply' },
|
|
64
|
+
group: '流式体验与代理',
|
|
65
|
+
groupI18n: { en: 'Streaming & Proxy' },
|
|
66
|
+
description: '私聊生成回复时实时更新草稿内容(默认开启)',
|
|
67
|
+
descriptionI18n: { en: 'Show private-chat drafts while generating (default true)' },
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'streamingIntervalMs',
|
|
71
|
+
type: 'number',
|
|
72
|
+
label: '流式刷新间隔 (ms)',
|
|
73
|
+
labelI18n: { en: 'Streaming Interval (ms)' },
|
|
74
|
+
group: '流式体验与代理',
|
|
75
|
+
groupI18n: { en: 'Streaming & Proxy' },
|
|
76
|
+
placeholder: '500',
|
|
77
|
+
description: '流式消息每次编辑的最小间隔毫秒数(默认 500)',
|
|
78
|
+
descriptionI18n: { en: 'Delay between draft updates in milliseconds (default 500)' },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: 'apiBaseUrl',
|
|
82
|
+
label: '自定义 Bot API 地址',
|
|
83
|
+
labelI18n: { en: 'Custom Bot API URL' },
|
|
84
|
+
group: '流式体验与代理',
|
|
85
|
+
groupI18n: { en: 'Streaming & Proxy' },
|
|
86
|
+
placeholder: 'https://api.telegram.org',
|
|
87
|
+
description: '自建 Telegram Bot API 反代或本地服务地址(可选)',
|
|
88
|
+
descriptionI18n: { en: 'Telegram Bot API URL' },
|
|
89
|
+
},
|
|
13
90
|
],
|
|
14
91
|
docsUrl: 'https://zhin.js.org/adapters/telegram',
|
|
15
92
|
readPermission: 'telegram:read',
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export { TelegramClient, type TelegramClientApi, type TelegramFetch } from './te
|
|
|
17
17
|
/**
|
|
18
18
|
* Telegram Bot API 无列表类接口(无 getMyChats/getChatMembers),
|
|
19
19
|
* 仅 getChat/getChatMember 按已知 id 单查,不构成列表能力;
|
|
20
|
-
* 因此本 endpoint
|
|
20
|
+
* 因此本 endpoint 的 EndpointManagement 只有 `inspectSelfStanding`(ADR 0056 §1:getChatMember bot),
|
|
21
|
+
* Console 社交面 RPC 对该平台保持未接线。
|
|
21
22
|
*/
|
|
22
23
|
export declare class TelegramEndpoint extends TelegramClient implements Endpoint {
|
|
23
24
|
#private;
|