@hyl_aa/openclaw-napcat 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 HylAa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # openclaw-napcat
2
+
3
+ [English](./README_EN.md) | 中文
4
+
5
+ OpenClaw 的 QQ 消息通道插件,基于 [NapCat](https://github.com/NapNeko/NapCatQQ) 的 OneBot 11 反向 WebSocket 协议。
6
+
7
+ 让 AI 助手通过自然语言完全控制 QQ 交互 —— 点赞、戳一戳、禁言、踢人、查看用户资料、管理群组等。
8
+
9
+ ## 功能特性
10
+
11
+ - **17 个 AI Agent 工具** —— AI 通过自然语言指令执行 QQ 操作
12
+ - **语音转文字 (STT)** —— 自动将语音消息转录为文字后发送给 AI
13
+ - **@提及识别** —— 自动识别消息中的 `@QQ号` 并映射到用户 ID
14
+ - **群管理** —— 完整的管理工具集:禁言、踢人、设置管理员、改群名、发公告
15
+ - **多账号支持** —— 支持配置多个 NapCat 机器人账号
16
+
17
+ ## Agent 工具列表
18
+
19
+ | 工具 | 功能 | 仅群主 |
20
+ |------|------|:------:|
21
+ | `qq_like_user` | 给用户点赞 | |
22
+ | `qq_get_user_info` | 获取用户资料(昵称、年龄、签名等) | |
23
+ | `qq_get_group_info` | 获取群信息(群名、成员数) | |
24
+ | `qq_get_group_member_info` | 获取群内某成员的详细信息 | |
25
+ | `qq_get_friend_list` | 获取机器人好友列表 | |
26
+ | `qq_get_group_list` | 获取机器人群列表 | |
27
+ | `qq_get_group_member_list` | 获取群全部成员列表 | |
28
+ | `qq_get_group_honor_info` | 获取群荣誉信息(龙王等) | |
29
+ | `qq_poke` | 戳一戳 | |
30
+ | `qq_mute_group_member` | 禁言群成员 | Yes |
31
+ | `qq_kick_group_member` | 踢出群成员 | Yes |
32
+ | `qq_recall_message` | 撤回消息 | Yes |
33
+ | `qq_set_group_card` | 设置群名片 | Yes |
34
+ | `qq_set_group_admin` | 设置/取消群管理员 | Yes |
35
+ | `qq_set_group_name` | 修改群名称 | Yes |
36
+ | `qq_set_group_whole_ban` | 全员禁言开关 | Yes |
37
+ | `qq_send_group_notice` | 发送群公告 | Yes |
38
+
39
+ ## 前置要求
40
+
41
+ - 已安装并运行 [OpenClaw](https://github.com/openclaw/openclaw)
42
+ - 已运行 [NapCat](https://github.com/NapNeko/NapCatQQ) 并开启 HTTP API
43
+ - Node.js 22+
44
+
45
+ ## 安装
46
+
47
+ ```bash
48
+ openclaw install extensions/napcat
49
+ ```
50
+
51
+ 或者手动克隆到 OpenClaw 扩展目录:
52
+
53
+ ```bash
54
+ cd ~/.openclaw/extensions
55
+ git clone https://github.com/HylAa/openclaw-napcat.git napcat
56
+ cd napcat && npm install --omit=dev
57
+ ```
58
+
59
+ ## 配置
60
+
61
+ 在 OpenClaw 配置中添加(`openclaw config edit`):
62
+
63
+ ```json
64
+ {
65
+ "channels": {
66
+ "napcat": {
67
+ "httpApi": "http://127.0.0.1:3000",
68
+ "accessToken": "你的token",
69
+ "selfId": "123456789",
70
+ "dmPolicy": "allowlist",
71
+ "allowFrom": ["好友QQ号"],
72
+ "groupPolicy": "allowlist",
73
+ "groupAllowFrom": ["群号"]
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### 配置字段说明
80
+
81
+ | 字段 | 说明 |
82
+ |------|------|
83
+ | `httpApi` | NapCat OneBot 11 HTTP API 地址 |
84
+ | `accessToken` | API 鉴权 token(可选) |
85
+ | `selfId` | 机器人自身 QQ 号(用于 @机器人检测) |
86
+ | `dmPolicy` | 私聊策略:`allowlist` / `pairing` / `open` / `disabled` |
87
+ | `allowFrom` | 允许私聊的 QQ 号列表 |
88
+ | `groupPolicy` | 群聊策略:`allowlist` / `open` / `disabled` |
89
+ | `groupAllowFrom` | 允许在群聊中触发的 QQ 号列表 |
90
+
91
+ **重要:** 需要在 OpenClaw 配置中将 `tools.profile` 设置为 `"full"`,否则 `qq_*` 工具会被默认的 `"coding"` profile 过滤掉。
92
+
93
+ ## 使用示例
94
+
95
+ 配置完成后,直接在 QQ 中与 AI 对话即可:
96
+
97
+ - "帮我给 3870871935 点赞" —— AI 调用 `qq_like_user`
98
+ - "帮我分析 @某人 的签名" —— AI 从 @提及中提取 QQ 号,调用 `qq_get_user_info`
99
+ - "查看群成员列表" —— AI 调用 `qq_get_group_member_list`
100
+ - "把 @某人 禁言10分钟" —— AI 调用 `qq_mute_group_member`(仅群主)
101
+ - "发个群公告:明天开会" —— AI 调用 `qq_send_group_notice`(仅群主)
102
+
103
+ ## 语音消息
104
+
105
+ 启用语音 STT 后(`tools.media.audio.enabled: true`),语音消息会自动转录为文字再发送给 AI 模型。
106
+
107
+ ## 项目结构
108
+
109
+ ```
110
+ .
111
+ ├── index.ts # 插件入口
112
+ ├── package.json
113
+ ├── openclaw.plugin.json # 插件元数据
114
+ └── src/
115
+ ├── accounts.ts # 多账号解析
116
+ ├── api.ts # OneBot 11 HTTP API 客户端
117
+ ├── channel.ts # Channel 插件与 Dock 定义
118
+ ├── config-schema.ts # 配置 JSON Schema + UI 提示
119
+ ├── monitor.ts # WebSocket 消息监听 + STT
120
+ ├── probe.ts # 连接探测 / 健康检查
121
+ ├── runtime.ts # 运行时上下文
122
+ ├── send.ts # 消息发送
123
+ ├── tools.ts # 17 个 AI Agent 工具
124
+ └── types.ts # TypeScript 类型定义
125
+ ```
126
+
127
+ ## 许可证
128
+
129
+ MIT
package/README_EN.md ADDED
@@ -0,0 +1,129 @@
1
+ # openclaw-napcat
2
+
3
+ English | [中文](./README.md)
4
+
5
+ OpenClaw extension for QQ messaging via [NapCat](https://github.com/NapNeko/NapCatQQ) (OneBot 11 reverse WebSocket).
6
+
7
+ Let your AI assistant fully control QQ interactions through natural language -- like, poke, mute, kick, query user profiles, manage groups, and more.
8
+
9
+ ## Features
10
+
11
+ - **17 AI Agent Tools** -- AI can execute QQ actions via natural language commands
12
+ - **Voice-to-Text (STT)** -- Auto-transcribes voice messages before sending to AI
13
+ - **@Mention Resolution** -- Recognizes `@QQNumber` in messages and maps to user IDs
14
+ - **Group Management** -- Full admin toolkit: mute, kick, set admin, rename group, announcements
15
+ - **Multi-Account** -- Supports multiple NapCat bot accounts
16
+
17
+ ## Agent Tools
18
+
19
+ | Tool | Description | Owner Only |
20
+ |------|-------------|:----------:|
21
+ | `qq_like_user` | Give a user thumbs-up (like) | |
22
+ | `qq_get_user_info` | Get user profile (nickname, age, signature, etc.) | |
23
+ | `qq_get_group_info` | Get group info (name, member count) | |
24
+ | `qq_get_group_member_info` | Get a member's info within a group | |
25
+ | `qq_get_friend_list` | Get bot's friend list | |
26
+ | `qq_get_group_list` | Get bot's group list | |
27
+ | `qq_get_group_member_list` | Get all members of a group | |
28
+ | `qq_get_group_honor_info` | Get group honor/achievements (Dragon King, etc.) | |
29
+ | `qq_poke` | Send a poke/nudge to a user | |
30
+ | `qq_mute_group_member` | Mute a member for specified duration | Yes |
31
+ | `qq_kick_group_member` | Kick a member from a group | Yes |
32
+ | `qq_recall_message` | Recall (delete) a sent message | Yes |
33
+ | `qq_set_group_card` | Set member's display name in group | Yes |
34
+ | `qq_set_group_admin` | Set/unset group admin | Yes |
35
+ | `qq_set_group_name` | Change group name | Yes |
36
+ | `qq_set_group_whole_ban` | Toggle whole-group mute | Yes |
37
+ | `qq_send_group_notice` | Send group announcement | Yes |
38
+
39
+ ## Prerequisites
40
+
41
+ - [OpenClaw](https://github.com/openclaw/openclaw) installed and running
42
+ - [NapCat](https://github.com/NapNeko/NapCatQQ) running with HTTP API enabled
43
+ - Node.js 22+
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ openclaw install extensions/napcat
49
+ ```
50
+
51
+ Or clone this repo into your OpenClaw extensions directory:
52
+
53
+ ```bash
54
+ cd ~/.openclaw/extensions
55
+ git clone https://github.com/HylAa/openclaw-napcat.git napcat
56
+ cd napcat && npm install --omit=dev
57
+ ```
58
+
59
+ ## Configuration
60
+
61
+ Add to your OpenClaw config (`openclaw config edit`):
62
+
63
+ ```json
64
+ {
65
+ "channels": {
66
+ "napcat": {
67
+ "httpApi": "http://127.0.0.1:3000",
68
+ "accessToken": "your-token-here",
69
+ "selfId": "123456789",
70
+ "dmPolicy": "allowlist",
71
+ "allowFrom": ["friend_qq_number"],
72
+ "groupPolicy": "allowlist",
73
+ "groupAllowFrom": ["group_number"]
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Config Fields
80
+
81
+ | Field | Description |
82
+ |-------|-------------|
83
+ | `httpApi` | NapCat OneBot 11 HTTP API address |
84
+ | `accessToken` | API auth token (optional) |
85
+ | `selfId` | Bot's own QQ number (for @mention detection) |
86
+ | `dmPolicy` | DM policy: `allowlist` / `pairing` / `open` / `disabled` |
87
+ | `allowFrom` | Allowed QQ numbers for DM |
88
+ | `groupPolicy` | Group policy: `allowlist` / `open` / `disabled` |
89
+ | `groupAllowFrom` | Allowed QQ numbers in groups |
90
+
91
+ **Important:** Set `tools.profile` to `"full"` in your OpenClaw config, otherwise `qq_*` tools will be filtered out by the default `"coding"` profile.
92
+
93
+ ## Usage Examples
94
+
95
+ Once configured, just talk to your AI in QQ:
96
+
97
+ - "Help me like user 3870871935" -- AI calls `qq_like_user`
98
+ - "Analyze @someone's signature" -- AI extracts QQ number from @mention, calls `qq_get_user_info`
99
+ - "Show group member list" -- AI calls `qq_get_group_member_list`
100
+ - "Mute @someone for 10 minutes" -- AI calls `qq_mute_group_member` (owner only)
101
+ - "Post a group announcement: meeting tomorrow" -- AI calls `qq_send_group_notice` (owner only)
102
+
103
+ ## Voice Messages
104
+
105
+ When voice STT is enabled (`tools.media.audio.enabled: true`), voice messages are automatically transcribed to text before being sent to the AI model.
106
+
107
+ ## Project Structure
108
+
109
+ ```
110
+ .
111
+ ├── index.ts # Plugin entry point
112
+ ├── package.json
113
+ ├── openclaw.plugin.json # Plugin metadata
114
+ └── src/
115
+ ├── accounts.ts # Multi-account resolution
116
+ ├── api.ts # OneBot 11 HTTP API client
117
+ ├── channel.ts # Channel plugin & dock definition
118
+ ├── config-schema.ts # Config JSON Schema + UI hints
119
+ ├── monitor.ts # WebSocket message monitor + STT
120
+ ├── probe.ts # Connection probe / health check
121
+ ├── runtime.ts # Runtime context
122
+ ├── send.ts # Outbound message sending
123
+ ├── tools.ts # 17 AI agent tools
124
+ └── types.ts # TypeScript type definitions
125
+ ```
126
+
127
+ ## License
128
+
129
+ MIT
package/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+ import { napCatDock, napCatPlugin } from "./src/channel.js";
4
+ import { setNapCatRuntime } from "./src/runtime.js";
5
+
6
+ const plugin = {
7
+ id: "napcat",
8
+ name: "QQ (NapCat)",
9
+ description: "QQ channel plugin via NapCat (OneBot 11 reverse WebSocket)",
10
+ configSchema: emptyPluginConfigSchema(),
11
+ register(api: OpenClawPluginApi) {
12
+ setNapCatRuntime(api.runtime);
13
+ api.registerChannel({ plugin: napCatPlugin, dock: napCatDock });
14
+ },
15
+ };
16
+
17
+ export default plugin;
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "napcat",
3
+ "channels": ["napcat"],
4
+ "configSchema": {
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {}
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@hyl_aa/openclaw-napcat",
3
+ "version": "0.1.0",
4
+ "description": "OpenClaw QQ channel plugin via NapCat (OneBot 11)",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/HylAa/openclaw-napcat.git"
10
+ },
11
+ "keywords": [
12
+ "openclaw",
13
+ "openclaw-plugin",
14
+ "qq",
15
+ "napcat",
16
+ "onebot",
17
+ "chatbot"
18
+ ],
19
+ "dependencies": {
20
+ "ws": "^8.18.0"
21
+ },
22
+ "peerDependencies": {
23
+ "openclaw": "*"
24
+ },
25
+ "openclaw": {
26
+ "extensions": [
27
+ "./index.ts"
28
+ ],
29
+ "channel": {
30
+ "id": "napcat",
31
+ "label": "QQ (NapCat)",
32
+ "selectionLabel": "QQ via NapCat (OneBot 11)",
33
+ "docsPath": "/channels/napcat",
34
+ "docsLabel": "napcat",
35
+ "blurb": "QQ messaging via NapCat OneBot 11 reverse WebSocket.",
36
+ "aliases": [
37
+ "qq",
38
+ "onebot"
39
+ ],
40
+ "order": 90,
41
+ "quickstartAllowFrom": true
42
+ },
43
+ "install": {
44
+ "npmSpec": "@hyl_aa/openclaw-napcat",
45
+ "localPath": "extensions/napcat",
46
+ "defaultChoice": "npm"
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,101 @@
1
+ import type { OpenClawConfig } from "openclaw/plugin-sdk";
2
+ import {
3
+ DEFAULT_ACCOUNT_ID,
4
+ normalizeAccountId,
5
+ normalizeResolvedSecretInputString,
6
+ } from "openclaw/plugin-sdk";
7
+ import type { NapCatAccountConfig, NapCatConfig, ResolvedNapCatAccount } from "./types.js";
8
+
9
+ function getNapCatSection(cfg: OpenClawConfig): NapCatConfig | undefined {
10
+ return (cfg as Record<string, unknown>).channels?.napcat as NapCatConfig | undefined;
11
+ }
12
+
13
+ function mergeNapCatAccountConfig(
14
+ cfg: OpenClawConfig,
15
+ accountId: string,
16
+ ): NapCatAccountConfig {
17
+ const section = getNapCatSection(cfg);
18
+ if (!section) return {};
19
+
20
+ const base: NapCatAccountConfig = {
21
+ name: section.name,
22
+ enabled: section.enabled,
23
+ httpApi: section.httpApi,
24
+ accessToken: section.accessToken,
25
+ selfId: section.selfId,
26
+ dmPolicy: section.dmPolicy,
27
+ allowFrom: section.allowFrom,
28
+ groupPolicy: section.groupPolicy,
29
+ groupAllowFrom: section.groupAllowFrom,
30
+ mediaMaxMb: section.mediaMaxMb,
31
+ responsePrefix: section.responsePrefix,
32
+ };
33
+
34
+ if (accountId === DEFAULT_ACCOUNT_ID) {
35
+ return base;
36
+ }
37
+
38
+ const accountConfig = section.accounts?.[accountId];
39
+ if (!accountConfig) return base;
40
+
41
+ // Account-level overrides base-level
42
+ return {
43
+ ...base,
44
+ ...Object.fromEntries(
45
+ Object.entries(accountConfig).filter(([, v]) => v !== undefined),
46
+ ),
47
+ };
48
+ }
49
+
50
+ export function resolveNapCatAccount(params: {
51
+ cfg: OpenClawConfig;
52
+ accountId?: string | null;
53
+ }): ResolvedNapCatAccount {
54
+ const accountId = normalizeAccountId(params.accountId);
55
+ const config = mergeNapCatAccountConfig(params.cfg, accountId);
56
+ const section = getNapCatSection(params.cfg);
57
+
58
+ const baseEnabled = section?.enabled !== false;
59
+ const accountEnabled = config.enabled !== false;
60
+ const enabled = baseEnabled && accountEnabled;
61
+
62
+ const httpApi = (config.httpApi ?? "").trim();
63
+ const accessToken = normalizeResolvedSecretInputString(config.accessToken) ?? "";
64
+ const selfId = String(config.selfId ?? "").trim();
65
+
66
+ return {
67
+ accountId,
68
+ name: config.name?.trim(),
69
+ enabled,
70
+ httpApi,
71
+ accessToken,
72
+ selfId,
73
+ config,
74
+ };
75
+ }
76
+
77
+ export function listNapCatAccountIds(cfg: OpenClawConfig): string[] {
78
+ const section = getNapCatSection(cfg);
79
+ if (!section) return [];
80
+
81
+ const ids = new Set<string>();
82
+ // Base config counts as default account
83
+ if (section.httpApi || section.accessToken || section.selfId) {
84
+ ids.add(DEFAULT_ACCOUNT_ID);
85
+ }
86
+ if (section.accounts) {
87
+ for (const id of Object.keys(section.accounts)) {
88
+ ids.add(normalizeAccountId(id));
89
+ }
90
+ }
91
+ if (ids.size === 0) ids.add(DEFAULT_ACCOUNT_ID);
92
+ return [...ids];
93
+ }
94
+
95
+ export function resolveDefaultNapCatAccountId(cfg: OpenClawConfig): string {
96
+ const section = getNapCatSection(cfg);
97
+ if (section?.defaultAccount) {
98
+ return normalizeAccountId(section.defaultAccount);
99
+ }
100
+ return DEFAULT_ACCOUNT_ID;
101
+ }
package/src/api.ts ADDED
@@ -0,0 +1,134 @@
1
+ import type {
2
+ OneBotApiResponse,
3
+ OneBotLoginInfo,
4
+ OneBotSegment,
5
+ OneBotSendMsgResult,
6
+ } from "./types.js";
7
+
8
+ const DEFAULT_TIMEOUT_MS = 10_000;
9
+
10
+ export class OneBotApiError extends Error {
11
+ constructor(
12
+ public readonly retcode: number,
13
+ message: string,
14
+ ) {
15
+ super(message);
16
+ this.name = "OneBotApiError";
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Call OneBot 11 HTTP API.
22
+ * NapCat exposes HTTP endpoints at `{baseUrl}/{action}`.
23
+ */
24
+ export async function callOneBotApi<T>(
25
+ baseUrl: string,
26
+ action: string,
27
+ params: Record<string, unknown> = {},
28
+ options?: { accessToken?: string; timeoutMs?: number },
29
+ ): Promise<OneBotApiResponse<T>> {
30
+ const url = `${baseUrl.replace(/\/+$/, "")}/${action}`;
31
+ const headers: Record<string, string> = {
32
+ "Content-Type": "application/json",
33
+ };
34
+ if (options?.accessToken) {
35
+ headers["Authorization"] = `Bearer ${options.accessToken}`;
36
+ }
37
+
38
+ const controller = new AbortController();
39
+ const timeout = setTimeout(
40
+ () => controller.abort(),
41
+ options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
42
+ );
43
+
44
+ try {
45
+ const res = await fetch(url, {
46
+ method: "POST",
47
+ headers,
48
+ body: JSON.stringify(params),
49
+ signal: controller.signal,
50
+ });
51
+
52
+ if (!res.ok) {
53
+ throw new OneBotApiError(res.status, `HTTP ${res.status}: ${res.statusText}`);
54
+ }
55
+
56
+ const data = (await res.json()) as OneBotApiResponse<T>;
57
+ if (data.retcode !== 0) {
58
+ throw new OneBotApiError(
59
+ data.retcode,
60
+ `OneBot API error: retcode=${data.retcode} status=${data.status}`,
61
+ );
62
+ }
63
+
64
+ return data;
65
+ } finally {
66
+ clearTimeout(timeout);
67
+ }
68
+ }
69
+
70
+ /** Get bot login info (QQ number + nickname). */
71
+ export async function getLoginInfo(
72
+ baseUrl: string,
73
+ accessToken?: string,
74
+ ): Promise<OneBotLoginInfo> {
75
+ const resp = await callOneBotApi<OneBotLoginInfo>(baseUrl, "get_login_info", {}, { accessToken });
76
+ return resp.data;
77
+ }
78
+
79
+ /** Send a private message. */
80
+ export async function sendPrivateMsg(
81
+ baseUrl: string,
82
+ userId: number,
83
+ message: OneBotSegment[],
84
+ accessToken?: string,
85
+ ): Promise<OneBotSendMsgResult> {
86
+ const resp = await callOneBotApi<OneBotSendMsgResult>(
87
+ baseUrl,
88
+ "send_private_msg",
89
+ { user_id: userId, message },
90
+ { accessToken },
91
+ );
92
+ return resp.data;
93
+ }
94
+
95
+ /** Send a group message. */
96
+ export async function sendGroupMsg(
97
+ baseUrl: string,
98
+ groupId: number,
99
+ message: OneBotSegment[],
100
+ accessToken?: string,
101
+ ): Promise<OneBotSendMsgResult> {
102
+ const resp = await callOneBotApi<OneBotSendMsgResult>(
103
+ baseUrl,
104
+ "send_group_msg",
105
+ { group_id: groupId, message },
106
+ { accessToken },
107
+ );
108
+ return resp.data;
109
+ }
110
+
111
+ /** Build a text message segment. */
112
+ export function textSegment(text: string): OneBotSegment {
113
+ return { type: "text", data: { text } };
114
+ }
115
+
116
+ /** Build an image message segment. */
117
+ export function imageSegment(fileUrl: string): OneBotSegment {
118
+ return { type: "image", data: { file: fileUrl } };
119
+ }
120
+
121
+ /** Build an @mention segment. */
122
+ export function atSegment(qq: string | number): OneBotSegment {
123
+ return { type: "at", data: { qq: String(qq) } };
124
+ }
125
+
126
+ /** Build a reply (quote) segment referencing an earlier message. */
127
+ export function replySegment(messageId: number | string): OneBotSegment {
128
+ return { type: "reply", data: { id: String(messageId) } };
129
+ }
130
+
131
+ /** Build a voice/record message segment. */
132
+ export function recordSegment(fileUrl: string): OneBotSegment {
133
+ return { type: "record", data: { file: fileUrl } };
134
+ }