@alemonjs/qq-bot 2.1.32 → 2.1.33

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/lib/sdk/api.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { type AxiosRequestConfig } from 'axios';
2
- import { ApiRequestData, FileType } from './typing.js';
2
+ import { ApiRequestData, FileType, GroupAction, SetMemberMuteState, StreamMessageData, UploadPartFinishData, UploadPrepareData } from './typing.js';
3
3
  import { QQBotConfig } from './config.js';
4
- export declare const BOTS_API_RUL = "https://bots.qq.com";
4
+ export declare const BOTS_API_RUL = "https://api.bot.qq.com";
5
5
  export declare const API_URL_SANDBOX = "https://sandbox.api.sgroup.qq.com";
6
- export declare const API_URL = "https://api.sgroup.qq.com";
6
+ export declare const API_URL = "https://api.bot.qq.com";
7
7
  export type QQBotConnectionState = 'idle' | 'connecting' | 'ready' | 'reconnecting' | 'offline' | 'stopped';
8
8
  export type QQBotConnectionStatus = {
9
9
  state: QQBotConnectionState;
@@ -64,20 +64,28 @@ export declare class QQBotAPI {
64
64
  file_type: FileType;
65
65
  url?: string;
66
66
  file_data?: any;
67
+ upload_id?: string;
68
+ file_name?: string;
67
69
  }): Promise<{
68
70
  file_uuid: string;
69
71
  file_info: string;
70
72
  ttl: number;
73
+ id?: string;
74
+ raw_url?: string;
71
75
  }>;
72
76
  postRichMediaByGroup(openid: string, data: {
73
77
  srv_send_msg?: boolean;
74
78
  file_type: FileType;
75
79
  url?: string;
76
80
  file_data?: any;
81
+ upload_id?: string;
82
+ file_name?: string;
77
83
  }): Promise<{
78
84
  file_uuid: string;
79
85
  file_info: string;
80
86
  ttl: number;
87
+ id?: string;
88
+ raw_url?: string;
81
89
  }>;
82
90
  getMediaFileHashes(filePath: string): Promise<QQBotMediaHashes>;
83
91
  postChunkedRichMedia(params: {
@@ -96,7 +104,54 @@ export declare class QQBotAPI {
96
104
  ttl: number;
97
105
  }>;
98
106
  userMessageDelete(openid: string, message_id: string): Promise<any>;
107
+ groupMessageDelete(group_openid: string, message_id: string): Promise<any>;
99
108
  grouMessageDelte(group_openid: string, message_id: string): Promise<any>;
109
+ groupsInfo(group_openid: string): Promise<any>;
110
+ groupsBotState(group_openid: string): Promise<any>;
111
+ groupsMembersMessage(group_openid: string, member_openid: string): Promise<any>;
112
+ groupsJoinRequestList(group_openid: string, params?: {
113
+ cursor?: string;
114
+ limit?: number;
115
+ }): Promise<any>;
116
+ groupsApprovalJoinRequest(group_openid: string, member_openid: string, data: {
117
+ op: 'approve' | 'decline';
118
+ join_request_id?: string;
119
+ reject_reason?: string;
120
+ add_to_member_blacklist?: boolean;
121
+ }): Promise<any>;
122
+ groupsRestrictChatSetting(group_openid: string): Promise<any>;
123
+ groupsRestrictChatSettingPost(group_openid: string, data: {
124
+ members?: SetMemberMuteState[];
125
+ }): Promise<any>;
126
+ groupsJoinApprovalStrategies(params?: {
127
+ cursor?: string;
128
+ limit?: number;
129
+ }): Promise<any>;
130
+ groupsJoinApprovalStrategyCreate(data: {
131
+ group_openids?: string[];
132
+ group_ids?: string[];
133
+ is_enable?: 'on' | 'off';
134
+ expire_at?: string;
135
+ remark?: string;
136
+ }): Promise<any>;
137
+ groupsJoinApprovalStrategyPatch(strategy_id: string, data: {
138
+ is_enable?: 'on' | 'off';
139
+ expire_at?: string;
140
+ group_action?: GroupAction;
141
+ remark?: string;
142
+ }): Promise<any>;
143
+ groupsJoinApprovalStrategyDelete(strategy_id: string): Promise<any>;
144
+ groupsJoinApprovalStrategyExecute(strategy_id: string): Promise<any>;
145
+ groupsJoinApprovalStrategyWhitelistUsers(strategy_id: string, data: {
146
+ op: 'add' | 'del';
147
+ whitelist_users: string[];
148
+ }): Promise<any>;
149
+ usersUploadPrepare(userId: string, data: UploadPrepareData): Promise<any>;
150
+ groupUploadPrepare(groupId: string, data: UploadPrepareData): Promise<any>;
151
+ usersUploadPartFinish(userId: string, data: UploadPartFinishData): Promise<any>;
152
+ groupUploadPartFinish(groupId: string, data: UploadPartFinishData): Promise<any>;
153
+ uploadPartDirect(presignedUrl: string, part: Buffer): Promise<import("axios").AxiosResponse<any, any, {}>>;
154
+ streamMessages(userId: string, data: StreamMessageData): Promise<any>;
100
155
  channelsMessages(channel_id: string, message: {
101
156
  content?: string;
102
157
  embed?: any;
package/lib/sdk/api.js CHANGED
@@ -5,10 +5,11 @@ import { createPicFrom } from 'alemonjs/utils';
5
5
  import { createAxiosInstance } from './instance.js';
6
6
  import { randomUUID, createHash } from 'node:crypto';
7
7
  import { createReadStream } from 'node:fs';
8
+ import { fileDataToBuffer, CHUNK_THRESHOLD, chunkedUpload } from '../upload.js';
8
9
 
9
- const BOTS_API_RUL = 'https://bots.qq.com';
10
+ const BOTS_API_RUL = 'https://api.bot.qq.com';
10
11
  const API_URL_SANDBOX = 'https://sandbox.api.sgroup.qq.com';
11
- const API_URL = 'https://api.sgroup.qq.com';
12
+ const API_URL = 'https://api.bot.qq.com';
12
13
  class QQBotAPI {
13
14
  config;
14
15
  #msgMap = new Map();
@@ -237,6 +238,10 @@ class QQBotAPI {
237
238
  });
238
239
  }
239
240
  postRichMediaByUser(openid, data) {
241
+ const fileBuffer = fileDataToBuffer(data.file_data);
242
+ if (!data.upload_id && fileBuffer && fileBuffer.byteLength > CHUNK_THRESHOLD) {
243
+ return chunkedUpload(this, 'user', openid, fileBuffer, { file_type: data.file_type, file_name: data.file_name, srv_send_msg: data.srv_send_msg });
244
+ }
240
245
  return this.groupService({
241
246
  url: `/v2/users/${openid}/files`,
242
247
  method: 'post',
@@ -244,6 +249,10 @@ class QQBotAPI {
244
249
  });
245
250
  }
246
251
  postRichMediaByGroup(openid, data) {
252
+ const fileBuffer = fileDataToBuffer(data.file_data);
253
+ if (!data.upload_id && fileBuffer && fileBuffer.byteLength > CHUNK_THRESHOLD) {
254
+ return chunkedUpload(this, 'group', openid, fileBuffer, { file_type: data.file_type, file_name: data.file_name, srv_send_msg: data.srv_send_msg });
255
+ }
247
256
  return this.groupService({
248
257
  url: `/v2/groups/${openid}/files`,
249
258
  method: 'post',
@@ -362,12 +371,138 @@ class QQBotAPI {
362
371
  method: 'delete'
363
372
  });
364
373
  }
365
- grouMessageDelte(group_openid, message_id) {
374
+ groupMessageDelete(group_openid, message_id) {
366
375
  return this.groupService({
367
376
  url: `/v2/groups/${group_openid}/messages/${message_id}`,
368
377
  method: 'delete'
369
378
  });
370
379
  }
380
+ grouMessageDelte(group_openid, message_id) {
381
+ return this.groupMessageDelete(group_openid, message_id);
382
+ }
383
+ groupsInfo(group_openid) {
384
+ return this.groupService({
385
+ url: `/v2/groups/${group_openid}/info`,
386
+ method: 'get'
387
+ });
388
+ }
389
+ groupsBotState(group_openid) {
390
+ return this.groupService({
391
+ url: `/v2/groups/${group_openid}/bot_state`,
392
+ method: 'get'
393
+ });
394
+ }
395
+ groupsMembersMessage(group_openid, member_openid) {
396
+ return this.groupService({
397
+ url: `/v2/groups/${group_openid}/members/${member_openid}`,
398
+ method: 'get'
399
+ });
400
+ }
401
+ groupsJoinRequestList(group_openid, params) {
402
+ return this.groupService({
403
+ url: `/v2/groups/${group_openid}/join_request_list`,
404
+ method: 'get',
405
+ params
406
+ });
407
+ }
408
+ groupsApprovalJoinRequest(group_openid, member_openid, data) {
409
+ return this.groupService({
410
+ url: `/v2/groups/${group_openid}/approval_join_request/${member_openid}`,
411
+ method: 'post',
412
+ data
413
+ });
414
+ }
415
+ groupsRestrictChatSetting(group_openid) {
416
+ return this.groupService({
417
+ url: `/v2/groups/${group_openid}/restrict_chat_setting`,
418
+ method: 'get'
419
+ });
420
+ }
421
+ groupsRestrictChatSettingPost(group_openid, data) {
422
+ return this.groupService({
423
+ url: `/v2/groups/${group_openid}/restrict_chat_setting`,
424
+ method: 'post',
425
+ data
426
+ });
427
+ }
428
+ groupsJoinApprovalStrategies(params) {
429
+ return this.groupService({
430
+ url: '/v2/groups/join_approval_strategy',
431
+ method: 'get',
432
+ params
433
+ });
434
+ }
435
+ groupsJoinApprovalStrategyCreate(data) {
436
+ return this.groupService({
437
+ url: '/v2/groups/join_approval_strategy',
438
+ method: 'post',
439
+ data
440
+ });
441
+ }
442
+ groupsJoinApprovalStrategyPatch(strategy_id, data) {
443
+ return this.groupService({
444
+ url: `/v2/groups/join_approval_strategy/${strategy_id}`,
445
+ method: 'patch',
446
+ data
447
+ });
448
+ }
449
+ groupsJoinApprovalStrategyDelete(strategy_id) {
450
+ return this.groupService({
451
+ url: `/v2/groups/join_approval_strategy/${strategy_id}`,
452
+ method: 'delete'
453
+ });
454
+ }
455
+ groupsJoinApprovalStrategyExecute(strategy_id) {
456
+ return this.groupService({
457
+ url: `/v2/groups/join_approval_strategy/${strategy_id}/execute`,
458
+ method: 'post'
459
+ });
460
+ }
461
+ groupsJoinApprovalStrategyWhitelistUsers(strategy_id, data) {
462
+ return this.groupService({
463
+ url: `/v2/groups/join_approval_strategy/${strategy_id}/whitelist_users`,
464
+ method: 'post',
465
+ data
466
+ });
467
+ }
468
+ usersUploadPrepare(userId, data) {
469
+ return this.groupService({
470
+ url: `/v2/users/${userId}/upload_prepare`,
471
+ method: 'post',
472
+ data
473
+ });
474
+ }
475
+ groupUploadPrepare(groupId, data) {
476
+ return this.groupService({
477
+ url: `/v2/groups/${groupId}/upload_prepare`,
478
+ method: 'post',
479
+ data
480
+ });
481
+ }
482
+ usersUploadPartFinish(userId, data) {
483
+ return this.groupService({
484
+ url: `/v2/users/${userId}/upload_part_finish`,
485
+ method: 'post',
486
+ data
487
+ });
488
+ }
489
+ groupUploadPartFinish(groupId, data) {
490
+ return this.groupService({
491
+ url: `/v2/groups/${groupId}/upload_part_finish`,
492
+ method: 'post',
493
+ data
494
+ });
495
+ }
496
+ uploadPartDirect(presignedUrl, part) {
497
+ return axios.put(presignedUrl, part);
498
+ }
499
+ streamMessages(userId, data) {
500
+ return this.groupService({
501
+ url: `/v2/users/${userId}/stream_messages`,
502
+ method: 'post',
503
+ data
504
+ });
505
+ }
371
506
  async channelsMessages(channel_id, message, image) {
372
507
  const formdata = new FormData();
373
508
  for (const key in message) {
@@ -1,3 +1,5 @@
1
+ import { logger } from 'alemonjs';
2
+
1
3
  const filterHeaders = (headers = {}) => {
2
4
  if (!headers) {
3
5
  return headers;
@@ -1,3 +1,3 @@
1
- export declare const AvailableIntentsEventsEnum: readonly ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGE", "INTERACTION", "MESSAGE_AUDIT", "FORUMS_EVENT", "AUDIO_ACTION", "PUBLIC_GUILD_MESSAGES", "GROUP_AND_C2C_EVENT"];
1
+ export declare const AvailableIntentsEventsEnum: readonly ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGE", "GROUP_MEMBER_EVENT", "INTERACTION", "MESSAGE_AUDIT", "FORUMS_EVENT", "AUDIO_ACTION", "PUBLIC_GUILD_MESSAGES", "GROUP_AND_C2C_EVENT"];
2
2
  export type IntentsEnum = (typeof AvailableIntentsEventsEnum)[number];
3
3
  export declare function getIntentsMask(intents: IntentsEnum[]): number;
@@ -4,6 +4,7 @@ const AvailableIntentsEventsEnum = [
4
4
  'GUILD_MESSAGES',
5
5
  'GUILD_MESSAGE_REACTIONS',
6
6
  'DIRECT_MESSAGE',
7
+ 'GROUP_MEMBER_EVENT',
7
8
  'INTERACTION',
8
9
  'MESSAGE_AUDIT',
9
10
  'FORUMS_EVENT',
@@ -17,6 +18,7 @@ const intentsMap = {
17
18
  GUILD_MESSAGES: 1 << 9,
18
19
  GUILD_MESSAGE_REACTIONS: 1 << 10,
19
20
  DIRECT_MESSAGE: 1 << 12,
21
+ GROUP_MEMBER_EVENT: 1 << 24,
20
22
  INTERACTION: 1 << 26,
21
23
  MESSAGE_AUDIT: 1 << 27,
22
24
  FORUMS_EVENT: 1 << 28,
@@ -14,6 +14,7 @@ import { FRIEND_DEL_TYPE } from '../message/group/FRIEND_DEL';
14
14
  import { ERROR_TYPE } from '../message/ERROR';
15
15
  import { GROUP_MEMBER_REMOVE } from '../message/group/GROUP_MEMBER_REMOVE';
16
16
  import { GROUP_MEMBER_ADD } from '../message/group/GROUP_MEMBER_ADD';
17
+ import { GROUP_JOIN_REQUEST_TYPE } from '../message/group/GROUP_JOIN_REQUEST';
17
18
  export type QQBotGroupEventMap = {
18
19
  C2C_MESSAGE_CREATE: C2C_MESSAGE_CREATE_TYPE;
19
20
  C2C_MSG_REJECT: C2C_MSG_REJECT_TYPE;
@@ -31,4 +32,5 @@ export type QQBotGroupEventMap = {
31
32
  ERROR: ERROR_TYPE;
32
33
  GROUP_MEMBER_ADD: GROUP_MEMBER_ADD;
33
34
  GROUP_MEMBER_REMOVE: GROUP_MEMBER_REMOVE;
35
+ GROUP_JOIN_REQUEST: GROUP_JOIN_REQUEST_TYPE;
34
36
  };
@@ -1,6 +1,6 @@
1
1
  import { IntentsEnum } from './intents';
2
2
  import type { SessionStore } from './session.js';
3
- export type MessageType = 0 | 1 | 2 | 3 | 4 | 7;
3
+ export type MessageType = 0 | 1 | 2 | 3 | 4 | 6 | 7;
4
4
  export type FileType = 1 | 2 | 3 | 4;
5
5
  export interface ButtonType {
6
6
  id: string;
@@ -55,6 +55,128 @@ export interface ApiRequestData {
55
55
  event_id?: any;
56
56
  msg_id?: string;
57
57
  msg_seq?: number;
58
+ is_wakeup?: boolean;
59
+ force_verify_image_resource?: boolean;
60
+ input_notify?: {
61
+ input_type: number;
62
+ input_second: number;
63
+ };
64
+ }
65
+ export interface VerifyInfo {
66
+ method: string;
67
+ verify_message?: string;
68
+ review_qa_list?: {
69
+ question: string;
70
+ answer: string;
71
+ }[];
72
+ }
73
+ export interface JoinRequest {
74
+ join_request_id: string;
75
+ risk_tips?: string;
76
+ union_openid?: string;
77
+ member_openid: string;
78
+ username: string;
79
+ apply_at: string;
80
+ apply_source: string;
81
+ invited_by?: string;
82
+ bot: boolean;
83
+ verify_info?: VerifyInfo;
84
+ auto_approved?: {
85
+ strategy_id: string;
86
+ };
87
+ }
88
+ export interface GlobalMuteRule {
89
+ mode: 'none' | 'always' | 'schedule';
90
+ schedule_rules?: {
91
+ task_id: string;
92
+ start_at: string;
93
+ end_at: string;
94
+ enabled: boolean;
95
+ }[];
96
+ recurring_rules?: {
97
+ task_id: string;
98
+ weekdays: number[];
99
+ start_time: string;
100
+ end_time: string;
101
+ enabled: boolean;
102
+ }[];
103
+ }
104
+ export interface MemberMuteState {
105
+ member_openid: string;
106
+ mute_expire_at: string;
107
+ username: string;
108
+ union_openid: string;
109
+ }
110
+ export interface SetMemberMuteState {
111
+ op: 'add' | 'update' | 'del';
112
+ member_openid: string;
113
+ mute_expire_at?: string;
114
+ }
115
+ export interface JoinApprovalStrategy {
116
+ strategy_id: string;
117
+ group_openids: string[];
118
+ group_ids: string[];
119
+ whitelist_user_count: number;
120
+ is_enable: 'on' | 'off';
121
+ expire_at: string;
122
+ created_at: string;
123
+ updated_at: string;
124
+ remark: string;
125
+ }
126
+ export interface GroupAction {
127
+ op: 'add' | 'del';
128
+ group_openids?: string[];
129
+ group_ids?: string[];
130
+ }
131
+ export interface UploadPrepareData {
132
+ file_type: FileType;
133
+ file_name: string;
134
+ file_size: string;
135
+ md5: string;
136
+ sha1: string;
137
+ md5_10m: string;
138
+ }
139
+ export interface UploadPart {
140
+ index: number;
141
+ presigned_url: string;
142
+ block_size: string;
143
+ }
144
+ export interface UploadConfig {
145
+ concurrency: number;
146
+ retry_timeout: number;
147
+ retry_delay: number;
148
+ }
149
+ export interface UploadPrepareResult {
150
+ upload_id: string;
151
+ block_size: string;
152
+ parts: UploadPart[];
153
+ upload_config: UploadConfig;
154
+ }
155
+ export interface UploadPartFinishData {
156
+ upload_id: string;
157
+ part_index: number;
158
+ block_size: string;
159
+ md5: string;
160
+ }
161
+ export interface StreamMessageData {
162
+ input_mode?: 'append' | 'replace';
163
+ input_state?: 1 | 10;
164
+ content_type?: 'text' | 'markdown';
165
+ content_raw?: string;
166
+ event_id?: string;
167
+ msg_id?: string;
168
+ msg_seq?: number;
169
+ index?: number;
170
+ stream_msg_id?: string;
171
+ is_wakeup?: boolean;
172
+ }
173
+ export interface StreamMessageResult {
174
+ id: string;
175
+ timestamp: string;
176
+ ext_info?: {
177
+ ref_idx?: string;
178
+ };
179
+ remain_msg_len?: number;
58
180
  }
59
181
  export interface Options {
60
182
  app_id: string;
package/lib/sends.d.ts CHANGED
@@ -5,12 +5,16 @@ export declare const GROUP_AT_MESSAGE_CREATE: (client: Client, event: {
5
5
  ChannelId: string;
6
6
  MessageId?: string;
7
7
  _tag?: string;
8
- }, val: DataEnums[]) => Promise<ClientAPIMessageResult[]>;
8
+ }, val: DataEnums[], options?: {
9
+ forceVerifyImageResource?: boolean;
10
+ }) => Promise<ClientAPIMessageResult[]>;
9
11
  export declare const C2C_MESSAGE_CREATE: (client: Client, event: {
10
12
  UserId: string;
11
13
  MessageId?: string;
12
14
  _tag?: string;
13
- }, val: DataEnums[]) => Promise<ClientAPIMessageResult[]>;
15
+ }, val: DataEnums[], options?: {
16
+ forceVerifyImageResource?: boolean;
17
+ }) => Promise<ClientAPIMessageResult[]>;
14
18
  export declare const DIRECT_MESSAGE_CREATE: (client: Client, event: {
15
19
  UserId: string;
16
20
  MessageId?: string;