@karinjs/adapter-qqbot 1.3.1 → 2.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/dist/index.d.ts CHANGED
@@ -1,499 +1,670 @@
1
- import FormData from 'form-data';
2
- import * as axios from 'axios';
3
- import { karinToQQBot, AdapterBase, LogMethodNames, Contact, ButtonElement, KeyboardElement, MarkdownElement, MarkdownTplElement, SendMsgResults } from 'node-karin';
4
-
5
- /**
6
- * @description 创建axios实例
7
- * @param url 请求地址
8
- * @param appId 机器人ID
9
- */
10
- declare const createAxiosInstance: (url: string, appId: string) => axios.AxiosInstance;
1
+ import { AdapterBase, AdapterType, Contact, CreateGroupFolderResponse, DownloadFileOptions, DownloadFileResponse, ElementTypes, ForwardOptions, GetAiCharactersResponse, GetAtAllCountResponse, GetGroupFileListResponse, GetGroupFileSystemInfoResponse, GetGroupHighlightsResponse, GetGroupMuteListResponse, GetRkeyResponse, GroupInfo, GroupMemberInfo, LogMethodNames, Message, MessageResponse, NodeElement, QQGroupHonorInfo, SendMsgResults, UserInfo, karinToQQBot } from "node-karin";
2
+ import FormData from "form-data";
3
+ import * as _$node_karin_axios0 from "node-karin/axios";
11
4
 
5
+ //#region src/core/api/types.d.ts
12
6
  /** 上传富媒体文件场景 */
13
7
  type Scene = 'user' | 'group';
14
8
  /** 上传富媒体文件类型 */
15
9
  type MediaType = 'image' | 'video' | 'record' | 'file';
16
10
  /** 发送QQ消息请求参数基类 */
17
11
  interface SendQQMessageRequest {
18
- /** 消息类型:0 是文本,2 是 markdown, 3 ark,4 embed,7 media 富媒体 */
19
- msg_type: 0 | 2 | 3 | 4 | 7;
12
+ /** 消息类型:0 是文本,2 是 markdown, 3 ark,4 embed,7 media 富媒体 */
13
+ msg_type: 0 | 2 | 3 | 4 | 7;
14
+ }
15
+ /** 消息引用对象 */
16
+ interface MessageReference {
17
+ /** 需要引用回复的消息 id */
18
+ message_id: string;
19
+ /** 是否忽略获取引用消息详情错误,默认否 */
20
+ ignore_get_message_error?: boolean;
20
21
  }
21
22
  /** 发送QQ被动消息参数 */
22
23
  interface QQMessageID {
23
- /** 前置收到的事件 ID,用于发送被动消息,支持事件:"INTERACTION_CREATE"、"C2C_MSG_RECEIVE"、"FRIEND_ADD" */
24
- event_id?: string;
25
- /** 前置收到的用户发送过来的消息 ID,用于发送被动(回复)消息 */
26
- msg_id?: string;
27
- /** 回复消息的序号,与 msg_id 联合使用,避免相同消息id回复重复发送,不填默认是1。相同的 msg_id + msg_seq 重复发送会失败。 */
28
- msg_seq?: number;
24
+ /** 前置收到的事件 ID,用于发送被动消息,支持事件:"INTERACTION_CREATE"、"C2C_MSG_RECEIVE"、"FRIEND_ADD" */
25
+ event_id?: string;
26
+ /** 前置收到的用户发送过来的消息 ID,用于发送被动(回复)消息 */
27
+ msg_id?: string;
28
+ /** 回复消息的序号,与 msg_id 联合使用,避免相同消息id回复重复发送,不填默认是1。相同的 msg_id + msg_seq 重复发送会失败。 */
29
+ msg_seq?: number;
30
+ /** 指明发送消息为互动召回消息,与 msg_id,event_id 互斥使用 */
31
+ is_wakeup?: boolean;
32
+ /** 引用消息对象,QQ单聊和群聊场景均支持 */
33
+ message_reference?: MessageReference;
29
34
  }
30
35
  /** 发送QQ文本消息请求参数 */
31
36
  interface SendQQTextMessageRequest extends SendQQMessageRequest, QQMessageID {
32
- msg_type: 0;
33
- /**
34
- * 消息内容 支持如下内嵌格式
35
- * - `<qqbot-at-user id="" />` `@用户` **注意双引号不能省略**
36
- * - `<qqbot-at-everyone />` `@所有人`
37
- */
38
- content: string;
39
- }
40
- /** markdown消息结构 */
41
- type Markdown = {
42
- /** markdown 文本 */
43
- content: string;
44
- } | {
45
- /** markdown 模版id,申请模版后获得 */
46
- custom_template_id: string;
47
- /** 模版内变量与填充值的kv映射 */
48
- params: {
49
- key: string;
50
- values: string[];
51
- }[];
52
- };
53
- /** 按钮消息结构 */
54
- type Keyboard = {
55
- content: {
56
- rows: ReturnType<typeof karinToQQBot>;
57
- };
58
- } | {
59
- /** 按钮模版id */
60
- id: string;
61
- };
37
+ msg_type: 0;
38
+ /**
39
+ * 消息内容 支持如下内嵌格式
40
+ * - `<qqbot-at-user id="" />` `@用户` **注意双引号不能省略**
41
+ * - `<qqbot-at-everyone />` `@所有人`
42
+ */
43
+ content: string;
44
+ }
45
+ /** markdown 消息结构(官方已全量开放原生 markdown,2.0 不再支持模板模式) */
46
+ interface Markdown {
47
+ /** markdown 文本 */
48
+ content: string;
49
+ }
50
+ /** 按钮消息结构(官方已全量开放自定义 keyboard,2.0 不再支持模板按钮) */
51
+ interface Keyboard {
52
+ content: {
53
+ rows: ReturnType<typeof karinToQQBot>;
54
+ };
55
+ }
62
56
  /** 发送QQ Markdown 消息请求参数 */
63
57
  interface SendQQMarkdownMessageRequest extends SendQQMessageRequest, QQMessageID {
64
- msg_type: 2;
65
- /**
66
- * markdown 消息内容 支持如下内嵌格式
67
- * - `<qqbot-cmd-enter text="xxx" />` `回车按钮: 点击后,文本直接发送`
68
- * - `<qqbot-cmd-input text="xxx" show="xxx" reference="false" />` `点击后,文本输入框弹出`
69
- * - `text 用户点击后插入输入框的文本,参数必填,最大限制 100 字符,传值时需要 urlencode`
70
- * - `show 用户在消息内看到的文本,参数选填,默认取 text 值,最大限制 100 字符,传值时需要 urlencode。`
71
- * - `reference 插入输入框时是否带消息原文回复引用,参数选填,默认为 false,填入 true 时则带引用回复到输入框中。`
72
- *
73
- * {@link https://bot.q.qq.com/wiki/develop/api-v2/server-inter/message/trans/text-chain.html}
74
- */
75
- markdown: Markdown;
76
- /** 按钮 */
77
- keyboard?: Keyboard;
58
+ msg_type: 2;
59
+ /**
60
+ * markdown 消息内容 支持如下内嵌格式
61
+ * - `<qqbot-cmd-enter text="xxx" />` `回车按钮: 点击后,文本直接发送`
62
+ * - `<qqbot-cmd-input text="xxx" show="xxx" reference="false" />` `点击后,文本输入框弹出`
63
+ * - `text 用户点击后插入输入框的文本,参数必填,最大限制 100 字符,传值时需要 urlencode`
64
+ * - `show 用户在消息内看到的文本,参数选填,默认取 text 值,最大限制 100 字符,传值时需要 urlencode。`
65
+ * - `reference 插入输入框时是否带消息原文回复引用,参数选填,默认为 false,填入 true 时则带引用回复到输入框中。`
66
+ *
67
+ * {@link https://bot.q.qq.com/wiki/develop/api-v2/server-inter/message/trans/text-chain.html}
68
+ */
69
+ markdown: Markdown;
70
+ /** 按钮 */
71
+ keyboard?: Keyboard;
78
72
  }
79
73
  /** 发送QQ Ark 消息请求参数 */
80
74
  interface SendQQArkMessageRequest extends SendQQMessageRequest, QQMessageID {
81
- msg_type: 3;
82
- /** ark 消息内容 */
83
- ark: {
84
- /** ark 模版id */
85
- template_id: number;
86
- /** 模版内变量与填充值的kv映射 tips: 未经测试 先any */
87
- kv: any[];
88
- };
75
+ msg_type: 3;
76
+ /** ark 消息内容 */
77
+ ark: {
78
+ /** ark 模版id */template_id: number; /** 模版内变量与填充值的kv映射 tips: 未经测试 先any */
79
+ kv: any[];
80
+ };
89
81
  }
90
82
  /** 发送QQ Embed 消息请求参数 文档没看到发送接口 */
91
83
  /** 发送QQ Media 消息请求参数 */
92
84
  interface SendQQMediaMessageRequest extends SendQQMessageRequest, QQMessageID {
93
- msg_type: 7;
94
- /** media 消息内容 */
95
- media: {
96
- /** 文件信息,用于发消息接口的 media 字段使用 */
97
- file_info: string;
98
- };
99
- /** 当 msg_type = 7 时,content 字段需要填入一个值,譬如一个空格 “ ”,后续版本会修复该问题。 */
100
- content: string;
85
+ msg_type: 7;
86
+ /** media 消息内容 */
87
+ media: {
88
+ /** 文件信息,用于发消息接口的 media 字段使用 */file_info: string;
89
+ };
90
+ /** 当 msg_type = 7 时,content 字段需要填入一个值,譬如一个空格 “ ”,后续版本会修复该问题。 */
91
+ content: string;
101
92
  }
102
93
  /** 发送QQ消息请求参数 */
103
94
  type SendQQMsg = SendQQTextMessageRequest | SendQQMarkdownMessageRequest | SendQQArkMessageRequest | SendQQMediaMessageRequest;
104
95
  /** 发送频道被动消息参数 */
105
96
  interface SendGuildMessageID {
106
- /** 消息ID */
107
- msg_id?: string;
108
- /** 事件id */
109
- event_id?: string;
97
+ /** 消息ID */
98
+ msg_id?: string;
99
+ /** 事件id */
100
+ event_id?: string;
101
+ /** 引用消息对象 */
102
+ message_reference?: MessageReference;
110
103
  }
111
104
  /** 发送频道引用消息参数 */
112
105
  interface SendGuildQuoteMessage {
113
- /** 引用消息的ID */
114
- message_id?: string;
115
- /** 是否忽略获取引用消息详情错误,默认否 */
116
- ignore_get_message_error?: boolean;
106
+ /** 引用消息的ID */
107
+ message_id?: string;
108
+ /** 是否忽略获取引用消息详情错误,默认否 */
109
+ ignore_get_message_error?: boolean;
117
110
  }
118
111
  /** 发送频道消息请求参数基类 */
119
112
  interface SendGuildMessageRequest {
120
- /** 单独加一个类型 用于区分不同的消息类型 */
121
- type: 'text' | 'image' | 'embed' | 'ark' | 'markdown';
113
+ /** 单独加一个类型 用于区分不同的消息类型 */
114
+ type: 'text' | 'image' | 'embed' | 'ark' | 'markdown';
122
115
  }
123
116
  /** 发送频道 文本 消息请求参数 */
124
117
  interface SendGuildTextMessageRequest extends SendGuildMessageID, SendGuildQuoteMessage, SendGuildMessageRequest {
125
- type: 'text';
126
- /**
127
- * 消息内容 支持如下内嵌格式
128
- * - `<@user_id>` `@用户`
129
- * - `@everyone` `@所有人`
130
- * - `<#channel_id>` `#子频道`
131
- * - `<emoji:id>` `表情`
132
- */
133
- content: string;
134
- /** 图片url地址 */
135
- image?: string;
118
+ type: 'text';
119
+ /**
120
+ * 消息内容 支持如下内嵌格式
121
+ * - `<@user_id>` `@用户`
122
+ * - `@everyone` `@所有人`
123
+ * - `<#channel_id>` `#子频道`
124
+ * - `<emoji:id>` `表情`
125
+ */
126
+ content: string;
127
+ /** 图片url地址 */
128
+ image?: string;
136
129
  }
137
130
  /** 发送频道 图片 消息请求参数 */
138
131
  interface SendGuildImageMessageRequest extends SendGuildMessageID, SendGuildQuoteMessage, SendGuildMessageRequest {
139
- type: 'image';
140
- /** 图片url地址 */
141
- image: string;
132
+ type: 'image';
133
+ /** 图片url地址 */
134
+ image: string;
142
135
  }
143
136
  /** embeds消息结构 */
144
137
  interface Embeds {
145
- /** 标题 */
146
- title: string;
147
- /** 消息弹窗内容 */
148
- prompt: string;
149
- /** 缩略图 */
150
- thumbnail: {
151
- /** 图片地址 */
152
- url: string;
153
- };
154
- /** embed 字段数据 */
155
- fields: Record<string, any>[];
138
+ /** 标题 */
139
+ title: string;
140
+ /** 消息弹窗内容 */
141
+ prompt: string;
142
+ /** 缩略图 */
143
+ thumbnail: {
144
+ /** 图片地址 */url: string;
145
+ };
146
+ /** embed 字段数据 */
147
+ fields: Record<string, any>[];
156
148
  }
157
149
  /** 发送频道 embed 消息请求参数 */
158
150
  interface SendGuildEmbedMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
159
- type: 'embed';
160
- /** embed 消息内容 */
161
- embed: Embeds;
151
+ type: 'embed';
152
+ /** embed 消息内容 */
153
+ embed: Embeds;
162
154
  }
163
155
  /** ark消息结构 */
164
156
  interface Ark {
165
- /** 模版id */
166
- template_id: number;
167
- /** 模版内变量与填充值的kv映射 */
168
- kv: {
157
+ /** 模版id */
158
+ template_id: number;
159
+ /** 模版内变量与填充值的kv映射 */
160
+ kv: {
161
+ key: string;
162
+ value: string; /** 这个嵌套是认真的嘛... */
163
+ obj: {
164
+ obj_kv: {
169
165
  key: string;
170
166
  value: string;
171
- /** 这个嵌套是认真的嘛... */
172
- obj: {
173
- obj_kv: {
174
- key: string;
175
- value: string;
176
- }[];
177
- }[];
167
+ }[];
178
168
  }[];
169
+ }[];
179
170
  }
180
171
  /** 发送频道 ark 消息请求参数 */
181
172
  interface SendGuildArkMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
182
- type: 'ark';
183
- /** ark 消息内容 */
184
- ark: Ark;
173
+ type: 'ark';
174
+ /** ark 消息内容 */
175
+ ark: Ark;
185
176
  }
186
177
  /** 发送频道 markdown 消息请求参数 */
187
178
  interface SendGuildMarkdownMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
188
- type: 'markdown';
189
- /** markdown 消息内容 */
190
- markdown: Markdown;
191
- /** 按钮 */
192
- keyboard?: Keyboard;
179
+ type: 'markdown';
180
+ /** markdown 消息内容 */
181
+ markdown: Markdown;
182
+ /** 按钮 */
183
+ keyboard?: Keyboard;
193
184
  }
194
185
  /** 发送频道消息请求参数 */
195
186
  type SendGuildMsg = SendGuildTextMessageRequest | SendGuildImageMessageRequest | SendGuildEmbedMessageRequest | SendGuildArkMessageRequest | SendGuildMarkdownMessageRequest;
196
187
  /** 获取当前机器人详情接口响应 */
197
188
  interface GetMeResponse {
198
- /** 机器人的频道ID */
199
- id: string;
200
- /** 机器人的昵称 */
201
- username: string;
202
- /** 用户头像 */
203
- avatar: string;
204
- /** 特殊关联应用的 openid */
205
- union_openid: string;
206
- /** 机器人关联的互联应用的用户信息 */
207
- union_user_account: string;
208
- /** 机器人的分享url */
209
- share_url: string;
210
- /** 机器人介绍 */
211
- welcome_msg: string;
189
+ /** 机器人的频道ID */
190
+ id: string;
191
+ /** 机器人的昵称 */
192
+ username: string;
193
+ /** 用户头像 */
194
+ avatar: string;
195
+ /** 特殊关联应用的 openid */
196
+ union_openid: string;
197
+ /** 机器人关联的互联应用的用户信息 */
198
+ union_user_account: string;
199
+ /** 机器人的分享url */
200
+ share_url: string;
201
+ /** 机器人介绍 */
202
+ welcome_msg: string;
212
203
  }
213
204
  /** 创建私信会话接口响应 */
214
205
  interface DmsResponse {
215
- /** 频道ID 用于私信会话使用 */
216
- guild_id: string;
217
- /** 子频道ID 用于私信会话使用 */
218
- channel_id: string;
219
- /** 创建时间 */
220
- create_time: string;
206
+ /** 频道ID 用于私信会话使用 */
207
+ guild_id: string;
208
+ /** 子频道ID 用于私信会话使用 */
209
+ channel_id: string;
210
+ /** 创建时间 */
211
+ create_time: string;
221
212
  }
222
213
  /** 发送QQ消息后响应 */
223
214
  interface SendQQMsgResponse {
224
- /** 消息唯一 ID */
225
- id: string;
226
- /** 发送时间 */
227
- timestamp: number;
215
+ /** 消息唯一 ID */
216
+ id: string;
217
+ /** 发送时间 */
218
+ timestamp: number;
228
219
  }
229
220
  /** 发送频道消息后响应 */
230
221
  interface SendGuildResponse {
231
- /** 消息唯一 ID */
232
- id: string;
233
- /** 发送时间 ISO8601 timestamp */
234
- timestamp: string;
222
+ /** 消息唯一 ID */
223
+ id: string;
224
+ /** 发送时间 ISO8601 timestamp */
225
+ timestamp: string;
235
226
  }
236
227
  /** 上传富媒体文件响应 */
237
228
  interface UploadMediaResponse {
238
- /** 文件 ID */
239
- file_uuid: string;
240
- /** 文件信息,用于发消息接口的 media 字段使用 */
241
- file_info: string;
242
- /** 有效期,表示剩余多少秒到期,到期后 file_info 失效,当等于 0 时,表示可长期使用 */
243
- ttl: number;
244
- /** 发送消息的唯一ID,当srv_send_msg设置为true时返回 */
245
- id: string;
229
+ /** 文件 ID */
230
+ file_uuid: string;
231
+ /** 文件信息,用于发消息接口的 media 字段使用 */
232
+ file_info: string;
233
+ /** 有效期,表示剩余多少秒到期,到期后 file_info 失效,当等于 0 时,表示可长期使用 */
234
+ ttl: number;
235
+ /** 发送消息的唯一ID,当srv_send_msg设置为true时返回 */
236
+ id: string;
246
237
  }
247
-
238
+ //#endregion
239
+ //#region src/core/internal/axios.d.ts
240
+ /**
241
+ * 创建 axios 实例,自动从 tokens map 取最新 access_token
242
+ */
243
+ declare const createAxiosInstance: (baseURL: string, appId: string) => _$node_karin_axios0.AxiosInstance;
244
+ //#endregion
245
+ //#region src/core/api/http.d.ts
246
+ type AxiosInstance = ReturnType<typeof createAxiosInstance>;
247
+ /**
248
+ * Http 基础类,子模块继承此类共享 axios 实例与错误格式化
249
+ */
250
+ declare class Http {
251
+ readonly axios: AxiosInstance;
252
+ constructor(axios: AxiosInstance);
253
+ protected get<T>(path: string): Promise<T>;
254
+ protected post<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
255
+ protected put<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
256
+ protected delete<T>(path: string): Promise<T>;
257
+ }
258
+ //#endregion
259
+ //#region src/core/api/messages.d.ts
260
+ /**
261
+ * 消息发送 + 撤回
262
+ */
263
+ declare class MessagesApi extends Http {
264
+ /** 单聊消息 */
265
+ sendFriendMsg(openid: string, body: SendQQMsg): Promise<SendQQMsgResponse>;
266
+ /** 群聊消息 */
267
+ sendGroupMsg(groupOpenid: string, body: SendQQMsg): Promise<SendQQMsgResponse>;
268
+ /** 文字子频道消息 */
269
+ sendChannelMsg(channelId: string, body: SendGuildMsg | FormData): Promise<SendGuildResponse>;
270
+ /**
271
+ * 频道私信消息
272
+ * - 单参 (guildId, body):guildId 已知
273
+ * - 双参 (recipientId, srcGuildId, body):先创建会话再发送
274
+ */
275
+ sendDmsMsg(guildId: string, body: SendGuildMsg | FormData): Promise<SendGuildResponse>;
276
+ sendDmsMsg(recipientId: string, srcGuildId: string, body: SendGuildMsg | FormData): Promise<SendGuildResponse>;
277
+ /**
278
+ * 撤回消息
279
+ * - 'user' / 'group' 对应 QQ 单聊 / 群聊
280
+ * - 'channels' / 'dms' 对应频道 / 频道私信,支持 hidetip
281
+ */
282
+ recall(type: 'user' | 'group', peer: string, messageId: string): Promise<true>;
283
+ recall(type: 'channels' | 'dms', peer: string, messageId: string, hidetip?: boolean): Promise<true>;
284
+ }
285
+ //#endregion
286
+ //#region src/core/api/media.d.ts
287
+ /**
288
+ * 富媒体上传
289
+ */
290
+ declare class MediaApi extends Http {
291
+ /**
292
+ * @param scene user(单聊) / group(群聊)
293
+ * @param peer openid 或 group_openid
294
+ * @param type 文件类型
295
+ * @param source 必须是 http url 或 base64 字符串
296
+ * @param srvSendMsg 上传后是否由服务端直接发送
297
+ */
298
+ upload(scene: Scene, peer: string, type: MediaType, source: string, srvSendMsg?: boolean): Promise<UploadMediaResponse>;
299
+ }
300
+ //#endregion
301
+ //#region src/core/api/interaction.d.ts
302
+ /** ack 返回码 */
303
+ type AckCode = 0 | 1 | 2 | 3 | 4 | 5;
304
+ /**
305
+ * INTERACTION_CREATE 回应
306
+ */
307
+ declare class InteractionApi extends Http {
308
+ /**
309
+ * @param interactionId INTERACTION_CREATE 事件中的 id
310
+ * @param code 0 成功 / 1 操作失败 / 2 操作频繁 / 3 重复操作 / 4 无权限 / 5 仅管理员
311
+ */
312
+ ack(interactionId: string, code?: AckCode): Promise<void>;
313
+ }
314
+ //#endregion
315
+ //#region src/core/api/meta.d.ts
316
+ /**
317
+ * 元信息接口:@me / dms / gateway
318
+ */
319
+ declare class MetaApi extends Http {
320
+ /** 当前机器人详情 */
321
+ getMe(): Promise<GetMeResponse>;
322
+ /** 创建频道私信会话 */
323
+ createDms(recipientId: string, srcGuildId: string): Promise<DmsResponse>;
324
+ /** 获取通用 WSS 地址 */
325
+ getGateway(): Promise<{
326
+ url: string;
327
+ }>;
328
+ }
329
+ //#endregion
330
+ //#region src/core/api/index.d.ts
331
+ /**
332
+ * QQBot 官方 API 门面
333
+ *
334
+ * 子模块按职能拆分:
335
+ * - messages:发送 / 撤回
336
+ * - media:富媒体上传
337
+ * - interaction:按钮回调 ack
338
+ * - meta:@me / dms / gateway
339
+ *
340
+ * 请求体构造器 {@link buildQQMsg} / {@link buildGuildMsg} 独立导出,避免与 HTTP 调用耦合
341
+ */
248
342
  declare class QQBotApi {
249
- /** axios 实例 */
250
- axios: ReturnType<typeof createAxiosInstance>;
251
- constructor(axios: ReturnType<typeof createAxiosInstance>);
252
- /**
253
- * 发送get请求
254
- * @param path 请求路径
255
- * @returns 请求结果
256
- */
257
- get<T>(path: string): Promise<T>;
258
- /**
259
- * 发送post请求
260
- * @param path 请求路径
261
- * @param options 请求数据
262
- * @param headers 请求头
263
- */
264
- post<T>(path: string, options?: {}, headers?: Record<string, string>): Promise<T>;
265
- /**
266
- * 处理请求错误
267
- * @param error 错误信息
268
- */
269
- handleError(path: string, options: any, error: any): void;
270
- /**
271
- * 发送单聊消息
272
- * @param targetId 目标QQ用户的 openid
273
- * @param options 消息参数
274
- */
275
- sendFriendMsg(targetId: string, options: SendQQMsg): Promise<SendQQMsgResponse>;
276
- /**
277
- * 发送群聊消息
278
- * @param targetId 目标QQ群的 openid
279
- * @param options 消息参数
280
- */
281
- sendGroupMsg(targetId: string, options: SendQQMsg): Promise<SendQQMsgResponse>;
282
- /**
283
- * 构建QQBot文本消息参数
284
- * @param content 消息文本内容
285
- */
286
- QQdMsgOptions(type: 'text', content: string): SendQQTextMessageRequest;
287
- /**
288
- * 构建Markdown消息参数
289
- * @param markdown Markdown文本内容
290
- * @param keyboard 按钮
291
- */
292
- QQdMsgOptions(type: 'markdown', markdown: Markdown, keyboard?: Keyboard): SendQQMarkdownMessageRequest;
293
- /**
294
- * 构建Ark消息参数
295
- * @param ark Ark参数
296
- */
297
- QQdMsgOptions(type: 'ark', ark: SendQQArkMessageRequest['ark']): SendQQArkMessageRequest;
298
- /**
299
- * 构建Media消息参数
300
- * @param file 文件信息
301
- */
302
- QQdMsgOptions(type: 'media', file: string): SendQQMediaMessageRequest;
303
- /**
304
- * 构建频道文本、文本图片消息参数
305
- * @param type 消息类型
306
- * @param content 消息内容
307
- * @param image 图片url
308
- */
309
- GuildMsgOptions(type: 'text', content: string, image?: string): SendGuildTextMessageRequest;
310
- /**
311
- * 构建图片消息参数
312
- * @param type 消息类型
313
- * @param image 图片url
314
- */
315
- GuildMsgOptions(type: 'image', image: string): SendGuildTextMessageRequest;
316
- /**
317
- * 构建Embed消息参数
318
- * @param type 消息类型
319
- * @param embed Embed参数
320
- */
321
- GuildMsgOptions(type: 'embed', embed: Embeds): SendGuildEmbedMessageRequest;
322
- /**
323
- * 构建Ark消息参数
324
- * @param type 消息类型
325
- * @param ark Ark参数
326
- */
327
- GuildMsgOptions(type: 'ark', ark: Ark): SendGuildArkMessageRequest;
328
- /**
329
- * 构建Markdown消息参数
330
- * @param type 消息类型
331
- * @param markdown Markdown文本
332
- */
333
- GuildMsgOptions(type: 'markdown', markdown: Markdown): SendGuildMarkdownMessageRequest;
334
- /**
335
- * 上传富媒体文件
336
- * @param scene 上传场景
337
- * @param targetId 目标id
338
- * @param type 文件类型
339
- * @param url 需要上传的文件的url
340
- * @param srvSendMsg 是否发送消息
341
- */
342
- uploadMedia(scene: Scene, targetId: string, type: MediaType, url: string, srvSendMsg?: boolean): Promise<UploadMediaResponse>;
343
- /**
344
- * 上传富媒体文件
345
- * @param scene 上传场景
346
- * @param targetId 目标id
347
- * @param type 文件类型
348
- * @param base64 需要上传的文件的base64编码
349
- * @param srvSendMsg 是否发送消息
350
- */
351
- uploadMedia(scene: Scene, targetId: string, type: MediaType, base64: string, srvSendMsg?: boolean): Promise<UploadMediaResponse>;
352
- /**
353
- * 单聊撤回消息
354
- * @param type 场景类型
355
- * @param targetId 目标QQ用户的openid
356
- * @param messageId 消息id
357
- */
358
- recallMsg(type: 'user', targetId: string, messageId: string): Promise<boolean>;
359
- /**
360
- * 群聊撤回消息
361
- * @param type 场景类型
362
- * @param targetId 目标QQ群的openid
363
- * @param messageId 消息id
364
- */
365
- recallMsg(type: 'group', targetId: string, messageId: string): Promise<boolean>;
366
- /**
367
- * 文字子频道撤回消息
368
- * @param type 场景类型
369
- * @param channelId 子频道的id
370
- * @param messageId 消息id
371
- * @param hidetip 是否隐藏提示小灰条,true 为隐藏,false 为显示。默认为false
372
- */
373
- recallMsg(type: 'channels', channelId: string, messageId: string, hidetip?: boolean): Promise<boolean>;
374
- /**
375
- * 频道私信撤回消息
376
- * @param type 场景类型
377
- * @param guildId 频道的id
378
- * @param messageId 消息id
379
- * @param hidetip 是否隐藏提示小灰条,true 为隐藏,false 为显示。默认为false
380
- */
381
- recallMsg(type: 'dms', guildId: string, messageId: string, hidetip?: boolean): Promise<boolean>;
382
- /**
383
- * 发送文字子频道消息
384
- * @param targetId 目标子频道的id
385
- * @param options 消息参数
386
- */
387
- sendChannelMsg(targetId: string, options: SendGuildMsg | FormData): Promise<SendGuildResponse>;
388
- /**
389
- * 直接发送频道消息
390
- * @param guildID 频道的id
391
- * @param options 消息参数
392
- */
393
- sendDmsMsg(guildID: string, options: SendGuildMsg | FormData): Promise<SendGuildResponse>;
394
- /**
395
- * 发送频道私信消息
396
- * @param targetId 目标的id
397
- * @param srcGuildId 源频道的id
398
- * @param options 消息参数
399
- */
400
- sendDmsMsg(targetId: string, srcGuildId: string, options: SendGuildMsg | FormData): Promise<SendGuildResponse>;
401
- /**
402
- * 获取当前机器人详情
403
- */
404
- getMe(): Promise<GetMeResponse>;
405
- /**
406
- * 创建私信会话
407
- * @param recipientID 接受者id
408
- * @param srcGuildID 源频道id
409
- */
410
- dms(recipientID: string, srcGuildID: string): Promise<DmsResponse>;
343
+ readonly axios: AxiosInstance;
344
+ readonly messages: MessagesApi;
345
+ readonly media: MediaApi;
346
+ readonly interaction: InteractionApi;
347
+ readonly meta: MetaApi;
348
+ /** 请求体构造器(静态便利) */
349
+ readonly qq: {
350
+ text(content: string): SendQQTextMessageRequest;
351
+ markdown(markdown: Markdown, keyboard?: Keyboard): SendQQMarkdownMessageRequest;
352
+ ark(ark: SendQQArkMessageRequest["ark"]): SendQQArkMessageRequest;
353
+ media(fileInfo: string): SendQQMediaMessageRequest;
354
+ };
355
+ readonly guild: {
356
+ text(content: string, image?: string): SendGuildTextMessageRequest;
357
+ image(image: string): SendGuildImageMessageRequest;
358
+ embed(embed: Embeds): SendGuildEmbedMessageRequest;
359
+ ark(ark: Ark): SendGuildArkMessageRequest;
360
+ markdown(markdown: Markdown, keyboard?: Keyboard): SendGuildMarkdownMessageRequest;
361
+ };
362
+ constructor(axios: AxiosInstance);
411
363
  }
412
-
413
- /** 发送函数所需参数 */
414
- type Options<T extends 'qq' | 'guild'> = T extends 'qq' ? SendQQMsg : SendGuildMsg | FormData;
415
- type Pasmsg<T extends 'qq' | 'guild'> = {
416
- type: 'msg' | 'event';
417
- msg_id: string;
418
- msg_seq: T extends 'qq' ? number : never;
419
- };
420
- interface Grouping<T extends 'qq' | 'guild'> {
421
- /** 文本 */
422
- content: string[];
423
- /** 图片 QQ专属 */
424
- image: string[];
425
- /** 单行按钮 */
426
- button: ButtonElement[];
427
- /** 多行按钮 */
428
- keyboard: KeyboardElement[];
429
- /** markdown */
430
- markdown: MarkdownElement[];
431
- /** markdown模板 */
432
- markdownTpl: MarkdownTplElement[];
433
- /** 频道专属 图片url */
434
- imageUrls: string[];
435
- /** 频道专属 图片file */
436
- imageFiles: string[];
437
- /** 引用回复 频道专属 */
438
- reply: {
439
- message_id: string;
440
- };
441
- /** pasmsg */
442
- pasmsg: Pasmsg<T>;
443
- /** 代发送列表 */
444
- list: Array<Options<T>>;
445
- /**
446
- * 处理按钮、markdown
447
- * 统一格式后推入待发送消息列表
448
- * @param type 构建类型
449
- * @param list 分类列表
450
- * @returns
451
- */
452
- markdownToButton: (type: T, list: Grouping<T>) => void;
364
+ //#endregion
365
+ //#region src/types/config.d.ts
366
+ /**
367
+ * 单个 QQBot 配置
368
+ */
369
+ interface QQBotConfig {
370
+ /** 机器人名称 */
371
+ name: string;
372
+ /** 机器人 ID */
373
+ appId: string;
374
+ /** 机器人密钥 */
375
+ secret: string;
376
+ /** 正式环境 API */
377
+ prodApi: string;
378
+ /** 测试环境 API */
379
+ sandboxApi: string;
380
+ /** 调用凭证 API */
381
+ tokenApi: string;
382
+ /** 开启沙盒环境 */
383
+ sandbox: boolean;
384
+ /** 开启 QQ 场景能力(单聊 / 群聊) */
385
+ qqEnable: boolean;
386
+ /** 开启频道场景能力 */
387
+ guildEnable: boolean;
388
+ /** 频道场景模式 0 公域 / 1 私域 */
389
+ guildMode: 0 | 1;
390
+ /** 收到消息后对文本进行表达式处理 */
391
+ regex: {
392
+ reg: string | RegExp;
393
+ rep: string;
394
+ }[];
395
+ /** 按钮自动化 */
396
+ keyboard: {
397
+ /** 是否将文本中的 URL 自动转换为 keyboard 按钮 */enable: boolean;
398
+ };
399
+ /** 事件接收配置 */
400
+ event: {
401
+ /** 接收方式 0 关闭 / 1 webhook / 2 ws */type: 0 | 1 | 2;
402
+ };
453
403
  }
404
+ //#endregion
405
+ //#region src/core/adapter/base.d.ts
454
406
  /**
455
- * @adaoter QQBot
456
- * @version 1.8.0
407
+ * QQ Official Bot 适配器
408
+ *
409
+ * 全场景统一走 msg_type=2 Markdown 通道(详见 pipeline-qq / pipeline-guild)。
410
+ * 视频 / 语音 / 文件由 pipeline 内部以 msg_type=7 紧随主消息补发。
457
411
  */
458
- declare abstract class AdapterQQBot extends AdapterBase {
459
- super: QQBotApi;
460
- constructor(QQBot: QQBotApi);
461
- logger(level: LogMethodNames, ...args: any[]): void;
462
- /**
463
- * 被动消息结构
464
- * @param type 消息类型
465
- */
466
- pasmsg<T extends 'qq' | 'guild'>(type: T): Pasmsg<T>;
467
- /**
468
- * 撤回消息
469
- * @param contact 联系人
470
- * @param messageId 消息id
471
- */
472
- recallMsg(contact: Contact, messageId: string): Promise<void>;
473
- /**
474
- * 初始化消息分类对象
475
- */
476
- initList<T extends 'qq' | 'guild'>(type: T): Grouping<T>;
477
- /**
478
- * 初始化发送消息返回值
479
- */
480
- initSendMsgResults(): SendMsgResults;
481
- /**
482
- * 处理返回值
483
- * @param data 返回值
484
- */
485
- handleResponse(data: SendMsgResults): SendMsgResults;
486
- /**
487
- * - 处理按钮、markdown
488
- * - 统一格式后推入待发送消息列表
489
- * @param type 消息类型
490
- * @param button 按钮
491
- * @param keyboard 键盘
492
- * @param markdown markdown
493
- * @param markdownTpl markdown模板
494
- * @returns 消息列表
495
- */
496
- markdownToButton<T extends 'qq' | 'guild'>(type: T, list: Grouping<T>): void;
412
+ declare class AdapterQQBot extends AdapterBase implements AdapterType {
413
+ /** 与官方 API 交互 */
414
+ super: QQBotApi;
415
+ /** 当前 bot 配置 */
416
+ cfg: QQBotConfig;
417
+ /** openId / member_openid -> 昵称 缓存 */
418
+ nicknameCache: Map<string, string>;
419
+ constructor(cfg: QQBotConfig, api: QQBotApi);
420
+ logger(level: LogMethodNames, ...args: any[]): void;
421
+ /**
422
+ * 主消息回复入口(karin 调用)
423
+ */
424
+ srcReply(e: Message, elements: ElementTypes[]): Promise<SendMsgResults>;
425
+ /**
426
+ * 发送消息
427
+ */
428
+ sendMsg(contact: Contact, elements: Array<ElementTypes>, _retryCount?: number): Promise<SendMsgResults>;
429
+ /**
430
+ * 撤回消息
431
+ */
432
+ recallMsg(contact: Contact, messageId: string): Promise<void>;
433
+ /**
434
+ * 构造空发送结果,pipeline 内填充 rawData
435
+ */
436
+ initSendMsgResults(): SendMsgResults;
437
+ /**
438
+ * 将 rawData[0].id / timestamp 同步到顶层字段
439
+ */
440
+ handleResponse(data: SendMsgResults): SendMsgResults;
441
+ /**
442
+ * 发送长消息
443
+ */
444
+ sendLongMsg(_contact: Contact, _resId: string): Promise<SendMsgResults>;
445
+ /**
446
+ * 发送合并转发消息
447
+ *
448
+ * 将 NodeElement 拆解为文本 + 图片等元素,拼接成 markdown 发送。
449
+ * 节点之间仅用换行隔开,不添加任何前缀提示文本。
450
+ */
451
+ sendForwardMsg(contact: Contact, elements: Array<NodeElement>, _options?: ForwardOptions): Promise<{
452
+ messageId: string;
453
+ forwardId: string;
454
+ }>;
455
+ /**
456
+ * 获取头像 url
457
+ */
458
+ getAvatarUrl(_userId: string, _size?: 0 | 40 | 100 | 140): Promise<string>;
459
+ /**
460
+ * 获取群头像 url
461
+ */
462
+ getGroupAvatarUrl(_groupId: string, _size?: 0 | 40 | 100 | 140, _history?: number): Promise<string>;
463
+ /**
464
+ * 获取消息
465
+ */
466
+ getMsg(_contact: Contact | string, _messageId?: string): Promise<MessageResponse>;
467
+ /**
468
+ * 获取历史消息(通过消息 ID)
469
+ */
470
+ getHistoryMsg(_contact: Contact, _startMsgId: string, _count: number): Promise<Array<MessageResponse>>;
471
+ /**
472
+ * 获取历史消息(通过消息序列号)
473
+ */
474
+ getHistoryMsg(_contact: Contact, _startMsgSeq: number, _count: number): Promise<Array<MessageResponse>>;
475
+ /**
476
+ * 获取合并转发消息
477
+ */
478
+ getForwardMsg(_resId: string): Promise<Array<MessageResponse>>;
479
+ /**
480
+ * 获取精华消息
481
+ */
482
+ getGroupHighlights(_groupId: string, _page: number, _pageSize: number): Promise<Array<GetGroupHighlightsResponse>>;
483
+ /**
484
+ * 构造资源 ID
485
+ */
486
+ createResId(_contact: Contact, _elements: Array<NodeElement>): Promise<string>;
487
+ /**
488
+ * 设置、取消群精华消息
489
+ */
490
+ setGroupHighlights(_groupId: string, _messageId: string, _create: boolean): Promise<void>;
491
+ /**
492
+ * 发送好友赞
493
+ */
494
+ sendLike(_targetId: string, _count: number): Promise<void>;
495
+ /**
496
+ * 群踢人
497
+ */
498
+ groupKickMember(_groupId: string, _targetId: string, _rejectAddRequest?: boolean, _kickReason?: string): Promise<void>;
499
+ /**
500
+ * 禁言群成员
501
+ */
502
+ setGroupMute(_groupId: string, _targetId: string, _duration: number): Promise<void>;
503
+ /**
504
+ * 群全员禁言
505
+ */
506
+ setGroupAllMute(_groupId: string, _isBan: boolean): Promise<void>;
507
+ /**
508
+ * 设置群管理员
509
+ */
510
+ setGroupAdmin(_groupId: string, _targetId: string, _isAdmin: boolean): Promise<void>;
511
+ /**
512
+ * 设置群名片
513
+ */
514
+ setGroupMemberCard(_groupId: string, _targetId: string, _card: string): Promise<void>;
515
+ /**
516
+ * 设置群名
517
+ */
518
+ setGroupName(_groupId: string, _groupName: string): Promise<void>;
519
+ /**
520
+ * 退出群组
521
+ */
522
+ setGroupQuit(_groupId: string, _isDismiss: boolean): Promise<void>;
523
+ /**
524
+ * 设置群专属头衔
525
+ */
526
+ setGroupMemberTitle(_groupId: string, _targetId: string, _title: string): Promise<void>;
527
+ /**
528
+ * 获取陌生人信息
529
+ */
530
+ getStrangerInfo(_targetId: string): Promise<UserInfo>;
531
+ /**
532
+ * 获取好友列表
533
+ */
534
+ getFriendList(_refresh?: boolean): Promise<Array<UserInfo>>;
535
+ /**
536
+ * 获取群信息
537
+ */
538
+ getGroupInfo(_groupId: string, _noCache?: boolean): Promise<GroupInfo>;
539
+ /**
540
+ * 获取群列表
541
+ */
542
+ getGroupList(_refresh?: boolean): Promise<Array<GroupInfo>>;
543
+ /**
544
+ * 获取群成员信息
545
+ */
546
+ getGroupMemberInfo(_groupId: string, _targetId: string, _refresh?: boolean): Promise<GroupMemberInfo>;
547
+ /**
548
+ * 获取群成员列表
549
+ */
550
+ getGroupMemberList(_groupId: string, _refresh?: boolean): Promise<Array<GroupMemberInfo>>;
551
+ /**
552
+ * 获取群荣誉信息
553
+ */
554
+ getGroupHonor(_groupId: string): Promise<Array<QQGroupHonorInfo>>;
555
+ /**
556
+ * 设置好友请求结果
557
+ */
558
+ setFriendApplyResult(_requestId: string, _isApprove: boolean, _remark?: string): Promise<void>;
559
+ /**
560
+ * 设置申请加入群请求结果
561
+ */
562
+ setGroupApplyResult(_requestId: string, _isApprove: boolean, _denyReason?: string): Promise<void>;
563
+ /**
564
+ * 设置邀请加入群请求结果
565
+ */
566
+ setInvitedJoinGroupResult(_requestId: string, _isApprove: boolean): Promise<void>;
567
+ /**
568
+ * 设置消息表情回应
569
+ */
570
+ setMsgReaction(_contact: Contact, _messageId: string, _faceId: number | string, _isSet: boolean): Promise<void>;
571
+ /**
572
+ * 上传群文件、私聊文件
573
+ */
574
+ uploadFile(_contact: Contact, _file: string, _name: string, _folder?: string): Promise<void>;
575
+ /**
576
+ * 下载文件到协议端本地
577
+ */
578
+ downloadFile(_options?: DownloadFileOptions): Promise<DownloadFileResponse>;
579
+ /**
580
+ * 创建群文件夹
581
+ */
582
+ createGroupFolder(_groupId: string, _name: string): Promise<CreateGroupFolderResponse>;
583
+ /**
584
+ * 重命名群文件夹
585
+ */
586
+ renameGroupFolder(_groupId: string, _folderId: string, _name: string): Promise<boolean>;
587
+ /**
588
+ * 删除群文件夹
589
+ */
590
+ delGroupFolder(_groupId: string, _folderId: string): Promise<boolean>;
591
+ /**
592
+ * 上传群文件
593
+ */
594
+ uploadGroupFile(_groupId: string, _file: string, _name?: string): Promise<boolean>;
595
+ /**
596
+ * 获取文件 url
597
+ */
598
+ getFileUrl(_contact: Contact, _fileId: string): Promise<string>;
599
+ /**
600
+ * 删除群文件
601
+ */
602
+ delGroupFile(_groupId: string, _fileId: string, _busId: number): Promise<boolean>;
603
+ /**
604
+ * 获取群文件系统信息
605
+ */
606
+ getGroupFileSystemInfo(_groupId: string): Promise<GetGroupFileSystemInfoResponse>;
607
+ /**
608
+ * 获取群文件夹下文件列表
609
+ */
610
+ getGroupFileList(_groupId: string, _folderId?: string): Promise<GetGroupFileListResponse>;
611
+ /**
612
+ * 设置群备注
613
+ */
614
+ setGroupRemark(_groupId: string, _remark: string): Promise<boolean>;
615
+ /**
616
+ * 获取陌生群信息
617
+ */
618
+ getNotJoinedGroupInfo(_groupId: string): Promise<GroupInfo>;
619
+ /**
620
+ * 获取艾特全体成员剩余次数
621
+ */
622
+ getAtAllCount(_groupId: string): Promise<GetAtAllCountResponse>;
623
+ /**
624
+ * 获取群被禁言用户列表
625
+ */
626
+ getGroupMuteList(_groupId: string): Promise<Array<GetGroupMuteListResponse>>;
627
+ /**
628
+ * 戳一戳用户
629
+ */
630
+ pokeUser(_contact: Contact, _targetId: string, _count?: number): Promise<boolean>;
631
+ /**
632
+ * 获取 Cookies
633
+ */
634
+ getCookies(_domain: string): Promise<{
635
+ cookie: string;
636
+ }>;
637
+ /**
638
+ * 获取 QQ 相关接口凭证
639
+ */
640
+ getCredentials(_domain: string): Promise<{
641
+ cookies: string;
642
+ csrf_token: number;
643
+ }>;
644
+ /**
645
+ * 获取 CSRF Token
646
+ */
647
+ getCSRFToken(): Promise<{
648
+ token: number;
649
+ }>;
650
+ /**
651
+ * 设置头像
652
+ */
653
+ setAvatar(_file: string): Promise<void>;
654
+ /**
655
+ * 获取 rkey
656
+ */
657
+ getRkey(): Promise<Array<GetRkeyResponse>>;
658
+ /**
659
+ * 获取群 Ai 语音可用声色列表
660
+ */
661
+ getAiCharacters(): Promise<Array<GetAiCharactersResponse>>;
662
+ /**
663
+ * 设置群 Ai 语音声色
664
+ */
665
+ sendAiCharacter(_groupId: string, _characterId: string, _text: string): Promise<{
666
+ messageId: string;
667
+ }>;
497
668
  }
498
-
499
- export { AdapterQQBot };
669
+ //#endregion
670
+ export { type AdapterQQBot };