@softtynet/zca-js 2.2.8 → 2.2.9

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.
Files changed (142) hide show
  1. package/README.md +1 -0
  2. package/dist/apis/clearUnreadFriendRequests.d.ts +2 -0
  3. package/dist/apis/clearUnreadFriendRequests.js +29 -0
  4. package/dist/apis/encryptGids.d.ts +4 -0
  5. package/dist/apis/encryptGids.js +24 -0
  6. package/dist/apis/getAliasListV2.d.ts +10 -0
  7. package/dist/apis/getAliasListV2.js +28 -0
  8. package/dist/apis/getBlockFriends.d.ts +6 -0
  9. package/dist/apis/getBlockFriends.js +28 -0
  10. package/dist/apis/getCloudInfo.d.ts +3 -0
  11. package/dist/apis/getCloudInfo.js +34 -0
  12. package/dist/apis/getCloudSettings.d.ts +10 -0
  13. package/dist/apis/getCloudSettings.js +34 -0
  14. package/dist/apis/getCloudViewerKey.d.ts +5 -0
  15. package/dist/apis/getCloudViewerKey.js +25 -0
  16. package/dist/apis/getConversationMedia.d.ts +26 -0
  17. package/dist/apis/getConversationMedia.js +39 -0
  18. package/dist/apis/getEmojiStatusConfig.d.ts +17 -0
  19. package/dist/apis/getEmojiStatusConfig.js +23 -0
  20. package/dist/apis/getExtraFriendInfo.d.ts +3 -0
  21. package/dist/apis/getExtraFriendInfo.js +31 -0
  22. package/dist/apis/getExtraGroupInfo.d.ts +7 -0
  23. package/dist/apis/getExtraGroupInfo.js +32 -0
  24. package/dist/apis/getFamilyProfile.d.ts +3 -0
  25. package/dist/apis/getFamilyProfile.js +34 -0
  26. package/dist/apis/getFamilyUsage.d.ts +7 -0
  27. package/dist/apis/getFamilyUsage.js +34 -0
  28. package/dist/apis/getFamilyViewerKey.d.ts +5 -0
  29. package/dist/apis/getFamilyViewerKey.js +25 -0
  30. package/dist/apis/getFriendsEmojiStatus.d.ts +17 -0
  31. package/dist/apis/getFriendsEmojiStatus.js +30 -0
  32. package/dist/apis/getGroupCloudMessageJump.d.ts +3 -0
  33. package/dist/apis/getGroupCloudMessageJump.js +46 -0
  34. package/dist/apis/getLastReadContactTab.d.ts +4 -0
  35. package/dist/apis/getLastReadContactTab.js +15 -0
  36. package/dist/apis/getLastSeen.d.ts +11 -0
  37. package/dist/apis/getLastSeen.js +40 -0
  38. package/dist/apis/getLastSeenReaction.d.ts +9 -0
  39. package/dist/apis/getLastSeenReaction.js +28 -0
  40. package/dist/apis/getListPinTopics.d.ts +5 -0
  41. package/dist/apis/getListPinTopics.js +28 -0
  42. package/dist/apis/getMediaStorePreview.d.ts +3 -0
  43. package/dist/apis/getMediaStorePreview.js +31 -0
  44. package/dist/apis/getMiniProfile.d.ts +13 -0
  45. package/dist/apis/getMiniProfile.js +34 -0
  46. package/dist/apis/getPersonalizedStickerList.d.ts +5 -0
  47. package/dist/apis/getPersonalizedStickerList.js +24 -0
  48. package/dist/apis/getPhonebookV2.d.ts +6 -0
  49. package/dist/apis/getPhonebookV2.js +21 -0
  50. package/dist/apis/getProfileRank.d.ts +5 -0
  51. package/dist/apis/getProfileRank.js +25 -0
  52. package/dist/apis/getProfileVerificationStatus.d.ts +5 -0
  53. package/dist/apis/getProfileVerificationStatus.js +20 -0
  54. package/dist/apis/getQuotaCommunity.d.ts +8 -0
  55. package/dist/apis/getQuotaCommunity.js +27 -0
  56. package/dist/apis/getRecentSearchList.d.ts +6 -0
  57. package/dist/apis/getRecentSearchList.js +25 -0
  58. package/dist/apis/getStickerCategoriesV2.d.ts +17 -0
  59. package/dist/apis/getStickerCategoriesV2.js +21 -0
  60. package/dist/apis/getStickerCategoryData.d.ts +3 -0
  61. package/dist/apis/getStickerCategoryData.js +25 -0
  62. package/dist/apis/getStickerHello.d.ts +16 -0
  63. package/dist/apis/getStickerHello.js +34 -0
  64. package/dist/apis/getStickerSuggestKeywords.d.ts +12 -0
  65. package/dist/apis/getStickerSuggestKeywords.js +24 -0
  66. package/dist/apis/getStickerSuggestion.d.ts +12 -0
  67. package/dist/apis/getStickerSuggestion.js +30 -0
  68. package/dist/apis/getUsageMyCloud.d.ts +7 -0
  69. package/dist/apis/getUsageMyCloud.js +34 -0
  70. package/dist/apis/getUsageZCloud.d.ts +11 -0
  71. package/dist/apis/getUsageZCloud.js +34 -0
  72. package/dist/apis/keepAlive.d.ts +2 -1
  73. package/dist/apis/keepAlive.js +5 -3
  74. package/dist/apis/listen.d.ts +13 -0
  75. package/dist/apis/listen.js +10 -0
  76. package/dist/apis/readContactTab.d.ts +2 -0
  77. package/dist/apis/readContactTab.js +26 -0
  78. package/dist/apis/removeConversationMedia.d.ts +8 -0
  79. package/dist/apis/removeConversationMedia.js +30 -0
  80. package/dist/apis/undoMultiMessage.d.ts +9 -0
  81. package/dist/apis/undoMultiMessage.js +46 -0
  82. package/dist/apis/updateRecentSearch.d.ts +11 -0
  83. package/dist/apis/updateRecentSearch.js +41 -0
  84. package/dist/apis/verifyCloudMedia.d.ts +14 -0
  85. package/dist/apis/verifyCloudMedia.js +43 -0
  86. package/dist/apis/voiceToText.d.ts +4 -0
  87. package/dist/apis/voiceToText.js +30 -0
  88. package/dist/apis.d.ts +82 -0
  89. package/dist/apis.js +82 -0
  90. package/dist/cjs/apis/clearUnreadFriendRequests.cjs +34 -0
  91. package/dist/cjs/apis/encryptGids.cjs +29 -0
  92. package/dist/cjs/apis/getAliasListV2.cjs +33 -0
  93. package/dist/cjs/apis/getBlockFriends.cjs +33 -0
  94. package/dist/cjs/apis/getCloudInfo.cjs +39 -0
  95. package/dist/cjs/apis/getCloudSettings.cjs +39 -0
  96. package/dist/cjs/apis/getCloudViewerKey.cjs +30 -0
  97. package/dist/cjs/apis/getConversationMedia.cjs +44 -0
  98. package/dist/cjs/apis/getEmojiStatusConfig.cjs +28 -0
  99. package/dist/cjs/apis/getExtraFriendInfo.cjs +36 -0
  100. package/dist/cjs/apis/getExtraGroupInfo.cjs +37 -0
  101. package/dist/cjs/apis/getFamilyProfile.cjs +39 -0
  102. package/dist/cjs/apis/getFamilyUsage.cjs +39 -0
  103. package/dist/cjs/apis/getFamilyViewerKey.cjs +30 -0
  104. package/dist/cjs/apis/getFriendsEmojiStatus.cjs +35 -0
  105. package/dist/cjs/apis/getGroupCloudMessageJump.cjs +63 -0
  106. package/dist/cjs/apis/getLastReadContactTab.cjs +20 -0
  107. package/dist/cjs/apis/getLastSeen.cjs +45 -0
  108. package/dist/cjs/apis/getLastSeenReaction.cjs +33 -0
  109. package/dist/cjs/apis/getListPinTopics.cjs +33 -0
  110. package/dist/cjs/apis/getMediaStorePreview.cjs +36 -0
  111. package/dist/cjs/apis/getMiniProfile.cjs +39 -0
  112. package/dist/cjs/apis/getPersonalizedStickerList.cjs +29 -0
  113. package/dist/cjs/apis/getPhonebookV2.cjs +26 -0
  114. package/dist/cjs/apis/getProfileRank.cjs +30 -0
  115. package/dist/cjs/apis/getProfileVerificationStatus.cjs +25 -0
  116. package/dist/cjs/apis/getQuotaCommunity.cjs +32 -0
  117. package/dist/cjs/apis/getRecentSearchList.cjs +30 -0
  118. package/dist/cjs/apis/getStickerCategoriesV2.cjs +26 -0
  119. package/dist/cjs/apis/getStickerCategoryData.cjs +30 -0
  120. package/dist/cjs/apis/getStickerHello.cjs +39 -0
  121. package/dist/cjs/apis/getStickerSuggestKeywords.cjs +29 -0
  122. package/dist/cjs/apis/getStickerSuggestion.cjs +35 -0
  123. package/dist/cjs/apis/getUsageMyCloud.cjs +39 -0
  124. package/dist/cjs/apis/getUsageZCloud.cjs +39 -0
  125. package/dist/cjs/apis/keepAlive.cjs +5 -3
  126. package/dist/cjs/apis/listen.cjs +10 -0
  127. package/dist/cjs/apis/readContactTab.cjs +31 -0
  128. package/dist/cjs/apis/removeConversationMedia.cjs +35 -0
  129. package/dist/cjs/apis/undoMultiMessage.cjs +62 -0
  130. package/dist/cjs/apis/updateRecentSearch.cjs +46 -0
  131. package/dist/cjs/apis/verifyCloudMedia.cjs +48 -0
  132. package/dist/cjs/apis/voiceToText.cjs +35 -0
  133. package/dist/cjs/apis.cjs +82 -0
  134. package/dist/cjs/index.cjs +2 -0
  135. package/dist/cjs/utils.cjs +25 -0
  136. package/dist/context.d.ts +4 -0
  137. package/dist/index.d.ts +42 -1
  138. package/dist/index.js +1 -1
  139. package/dist/utils.d.ts +10 -0
  140. package/dist/utils.js +23 -0
  141. package/docs/INTEGRATION_GUIDE_SYNC_AND_CALL.md +110 -0
  142. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ export type GetStickerSuggestionOptions = {
2
+ keyword: string;
3
+ gif?: 0 | 1;
4
+ guggy?: 0 | 1;
5
+ };
6
+ export type GetStickerSuggestionResponse = {
7
+ sdata: unknown;
8
+ gif?: unknown;
9
+ guggy?: unknown;
10
+ [key: string]: unknown;
11
+ };
12
+ export declare const getStickerSuggestionFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: GetStickerSuggestionOptions | string) => Promise<GetStickerSuggestionResponse>;
@@ -0,0 +1,30 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../utils.js";
3
+ export const getStickerSuggestionFactory = apiFactory()((api, ctx, utils) => {
4
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.sticker[0]}/api/message/sticker/suggest/stickers`);
5
+ /**
6
+ * Gợi ý Sticker/GIF theo từ khóa đang nhập (command 11741)
7
+ *
8
+ * @param options Từ khóa và tùy chọn kèm theo (`gif`, `guggy`)
9
+ * @throws {ZaloApiError}
10
+ */
11
+ return async function getStickerSuggestion(options) {
12
+ var _a, _b;
13
+ const normalized = typeof options === "string" ? { keyword: options } : options;
14
+ const params = {
15
+ keyword: normalized.keyword,
16
+ gif: (_a = normalized.gif) !== null && _a !== void 0 ? _a : 1,
17
+ guggy: (_b = normalized.guggy) !== null && _b !== void 0 ? _b : 0,
18
+ imei: ctx.imei,
19
+ };
20
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
21
+ if (!encryptedParams)
22
+ throw new ZaloApiError("Failed to encrypt params");
23
+ const response = await utils.request(utils.makeURL(serviceURL, {
24
+ params: encryptedParams,
25
+ }), {
26
+ method: "GET",
27
+ });
28
+ return utils.resolve(response);
29
+ };
30
+ });
@@ -0,0 +1,7 @@
1
+ import type { GetCloudViewerKeyResponse } from "./getCloudViewerKey.js";
2
+ export type GetUsageMyCloudResponse = {
3
+ usage: number;
4
+ quota: number;
5
+ plan: number;
6
+ };
7
+ export declare const getUsageMyCloudFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (viewerKeyInfo?: GetCloudViewerKeyResponse) => Promise<GetUsageMyCloudResponse>;
@@ -0,0 +1,34 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory, decryptZCloudAES } from "../utils.js";
3
+ export const getUsageMyCloudFactory = apiFactory()((api, _ctx, utils) => {
4
+ var _a;
5
+ const baseDomain = ((_a = api.zpwServiceMap.zcloud) === null || _a === void 0 ? void 0 : _a[0]) || "https://zcld.chat.zalo.me";
6
+ const serviceURL = utils.makeURL(`${baseDomain}/cloudmedia/info/pc/v1/usage-mycloud`);
7
+ /**
8
+ * Kiểm tra hạn mức và dung lượng sử dụng Cloud của tôi (MyCloud - command 12748)
9
+ *
10
+ * @param viewerKeyInfo (Tùy chọn) Cặp `{ viewer_key, enk }` từ `api.getCloudViewerKey()`. Nếu không truyền sẽ tự động lấy mới.
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function getUsageMyCloud(viewerKeyInfo) {
14
+ const keyInfo = viewerKeyInfo !== null && viewerKeyInfo !== void 0 ? viewerKeyInfo : (await api.getCloudViewerKey());
15
+ if (!(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.viewer_key) || !(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.enk)) {
16
+ throw new ZaloApiError("Invalid CloudViewerKey");
17
+ }
18
+ const response = await utils.request(serviceURL, {
19
+ method: "GET",
20
+ headers: {
21
+ "cloud-viewer-key": keyInfo.viewer_key,
22
+ },
23
+ });
24
+ const json = (await response.json());
25
+ if (json.error_code !== 0 && json.error_code !== -904) {
26
+ throw new ZaloApiError(json.error_message || "getUsageMyCloud failed", json.error_code);
27
+ }
28
+ if (!json.data) {
29
+ throw new ZaloApiError("Empty MyCloud usage data", json.error_code);
30
+ }
31
+ const decrypted = decryptZCloudAES(json.data, keyInfo.enk);
32
+ return JSON.parse(decrypted);
33
+ };
34
+ });
@@ -0,0 +1,11 @@
1
+ import type { GetCloudViewerKeyResponse } from "./getCloudViewerKey.js";
2
+ export type GetUsageZCloudResponse = {
3
+ service_usage: {
4
+ my_cloud: number;
5
+ message_backup: number;
6
+ };
7
+ usage: number;
8
+ quota: number;
9
+ plan: number;
10
+ };
11
+ export declare const getUsageZCloudFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (viewerKeyInfo?: GetCloudViewerKeyResponse) => Promise<GetUsageZCloudResponse>;
@@ -0,0 +1,34 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory, decryptZCloudAES } from "../utils.js";
3
+ export const getUsageZCloudFactory = apiFactory()((api, _ctx, utils) => {
4
+ var _a;
5
+ const baseDomain = ((_a = api.zpwServiceMap.zcloud) === null || _a === void 0 ? void 0 : _a[0]) || "https://zcld.chat.zalo.me";
6
+ const serviceURL = utils.makeURL(`${baseDomain}/cloudmedia/info/pc/v2/usage`);
7
+ /**
8
+ * Kiểm tra dung lượng sử dụng ZCloud V2 (bao gồm MyCloud và Sao lưu tin nhắn - command 12749)
9
+ *
10
+ * @param viewerKeyInfo (Tùy chọn) Cặp `{ viewer_key, enk }` từ `api.getCloudViewerKey()`. Nếu không truyền sẽ tự động lấy mới.
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function getUsageZCloud(viewerKeyInfo) {
14
+ const keyInfo = viewerKeyInfo !== null && viewerKeyInfo !== void 0 ? viewerKeyInfo : (await api.getCloudViewerKey());
15
+ if (!(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.viewer_key) || !(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.enk)) {
16
+ throw new ZaloApiError("Invalid CloudViewerKey");
17
+ }
18
+ const response = await utils.request(serviceURL, {
19
+ method: "GET",
20
+ headers: {
21
+ "cloud-viewer-key": keyInfo.viewer_key,
22
+ },
23
+ });
24
+ const json = (await response.json());
25
+ if (json.error_code !== 0 && json.error_code !== -904) {
26
+ throw new ZaloApiError(json.error_message || "getUsageZCloud failed", json.error_code);
27
+ }
28
+ if (!json.data) {
29
+ throw new ZaloApiError("Empty ZCloud usage data", json.error_code);
30
+ }
31
+ const decrypted = decryptZCloudAES(json.data, keyInfo.enk);
32
+ return JSON.parse(decrypted);
33
+ };
34
+ });
@@ -1,4 +1,5 @@
1
1
  export type KeepAliveResponse = {
2
- config_vesion: number;
2
+ config_vesion?: number;
3
+ [key: string]: unknown;
3
4
  };
4
5
  export declare const keepAliveFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<KeepAliveResponse>;
@@ -3,7 +3,7 @@ import { apiFactory } from "../utils.js";
3
3
  export const keepAliveFactory = apiFactory()((api, ctx, utils) => {
4
4
  const serviceURL = utils.makeURL(`${api.zpwServiceMap.chat[0]}/keepalive`);
5
5
  /**
6
- * Keep Alive?
6
+ * Gửi tín hiệu duy trì phiên kết nối HTTP tới máy chủ Chat (KeepAlive - command 11770)
7
7
  *
8
8
  * @throws {ZaloApiError}
9
9
  */
@@ -14,9 +14,11 @@ export const keepAliveFactory = apiFactory()((api, ctx, utils) => {
14
14
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
15
15
  if (!encryptedParams)
16
16
  throw new ZaloApiError("Failed to encrypt params");
17
- const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
17
+ const response = await utils.request(utils.makeURL(serviceURL, {
18
+ params: encryptedParams,
19
+ }), {
18
20
  method: "GET",
19
21
  });
20
- return utils.resolve(response, undefined, false);
22
+ return utils.resolve(response);
21
23
  };
22
24
  });
@@ -13,6 +13,18 @@ type UploadEventData = {
13
13
  fileUrl: string;
14
14
  fileId: string;
15
15
  };
16
+ export type Voice2TextEventData = {
17
+ req_id: string;
18
+ err?: number;
19
+ text?: string;
20
+ content?: string;
21
+ [key: string]: unknown;
22
+ };
23
+ export type Voice2TextEvent = {
24
+ act: string;
25
+ act_type: "voice2text";
26
+ data: Voice2TextEventData;
27
+ };
16
28
  export type WsPayload<T = Record<string, unknown>> = {
17
29
  version: number;
18
30
  cmd: number;
@@ -48,6 +60,7 @@ interface ListenerEvents {
48
60
  group_event: [data: GroupEvent];
49
61
  sync_event: [data: SyncEvent];
50
62
  call_event: [data: CallEvent];
63
+ voice2text_event: [data: Voice2TextEvent];
51
64
  cipher_key: [key: string];
52
65
  ping: [];
53
66
  pong: [];
@@ -360,6 +360,16 @@ export class Listener extends EventEmitter {
360
360
  const callEvent = initializeCallEvent(callEventData, control.content.act, control.content.act_type);
361
361
  this.emit("call_event", callEvent);
362
362
  }
363
+ else if (control.content.act_type == "voice2text") {
364
+ const v2tData = typeof control.content.data == "string"
365
+ ? JSON.parse(control.content.data)
366
+ : control.content.data;
367
+ this.emit("voice2text_event", {
368
+ act: control.content.act,
369
+ act_type: "voice2text",
370
+ data: v2tData,
371
+ });
372
+ }
363
373
  }
364
374
  }
365
375
  if (cmd == 612) {
@@ -0,0 +1,2 @@
1
+ export type ReadContactTabResponse = Record<string, unknown> | string;
2
+ export declare const readContactTabFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (ts?: number) => Promise<ReadContactTabResponse>;
@@ -0,0 +1,26 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../utils.js";
3
+ export const readContactTabFactory = apiFactory()((api, _ctx, utils) => {
4
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/read-contact-tab`);
5
+ /**
6
+ * Đánh dấu đã đọc tab Danh bạ (command 12231)
7
+ *
8
+ * @param ts Dấu thời gian (mặc định: `Date.now()`)
9
+ * @throws {ZaloApiError}
10
+ */
11
+ return async function readContactTab(ts = Date.now()) {
12
+ const params = {
13
+ ts,
14
+ };
15
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
16
+ if (!encryptedParams)
17
+ throw new ZaloApiError("Failed to encrypt params");
18
+ const response = await utils.request(serviceURL, {
19
+ method: "POST",
20
+ body: new URLSearchParams({
21
+ params: encryptedParams,
22
+ }),
23
+ });
24
+ return utils.resolve(response);
25
+ };
26
+ });
@@ -0,0 +1,8 @@
1
+ import type { MediaStoreType } from "./getConversationMedia.js";
2
+ export type RemoveConversationMediaOptions = {
3
+ groupId: string;
4
+ mediaType: MediaStoreType;
5
+ mediaId: string | number | (string | number)[];
6
+ };
7
+ export type RemoveConversationMediaResponse = unknown;
8
+ export declare const removeConversationMediaFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: RemoveConversationMediaOptions) => Promise<unknown>;
@@ -0,0 +1,30 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../utils.js";
3
+ export const removeConversationMediaFactory = apiFactory()((api, _ctx, utils) => {
4
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store[0]}/api/mediastore/remove`);
5
+ /**
6
+ * Xóa mục Ảnh/Video, File hoặc Link khỏi Kho Lưu Trữ của nhóm (command 11842)
7
+ *
8
+ * @param options Thông tin mục cần xóa (`groupId`, `mediaType`, `mediaId`)
9
+ * @throws {ZaloApiError}
10
+ */
11
+ return async function removeConversationMedia(options) {
12
+ if (!options.groupId) {
13
+ throw new ZaloApiError("Missing groupId");
14
+ }
15
+ const cleanGroupId = options.groupId.startsWith("g") ? options.groupId.slice(1) : options.groupId;
16
+ const params = {
17
+ media_type: options.mediaType,
18
+ media_id: options.mediaId,
19
+ group_id: cleanGroupId,
20
+ };
21
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
22
+ if (!encryptedParams) {
23
+ throw new ZaloApiError("Failed to encrypt params");
24
+ }
25
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
26
+ method: "POST",
27
+ });
28
+ return utils.resolve(response);
29
+ };
30
+ });
@@ -0,0 +1,9 @@
1
+ import { ThreadType } from "../models/index.js";
2
+ export type UndoMultiMessageItem = {
3
+ globalMsgId: string | number;
4
+ cliMsgId: string | number;
5
+ cliMsgIdUndo?: string | number;
6
+ destId?: string;
7
+ };
8
+ export type UndoMultiMessageResponse = Record<string, unknown>;
9
+ export declare const undoMultiMessageFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (msgs: UndoMultiMessageItem[], threadId: string, type?: ThreadType) => Promise<UndoMultiMessageResponse>;
@@ -0,0 +1,46 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { ThreadType } from "../models/index.js";
3
+ import { apiFactory } from "../utils.js";
4
+ export const undoMultiMessageFactory = apiFactory()((api, _ctx, utils) => {
5
+ /**
6
+ * Thu hồi hàng loạt nhiều tin nhắn cùng lúc trong hội thoại cá nhân hoặc nhóm (command 12115 / 12116)
7
+ *
8
+ * @param msgs Danh sách tin nhắn cần thu hồi (`globalMsgId`, `cliMsgId` của tin nhắn gốc)
9
+ * @param threadId ID người nhận hoặc ID nhóm
10
+ * @param type Loại hội thoại (`ThreadType.User` hoặc `ThreadType.Group`)
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function undoMultiMessage(msgs, threadId, type = ThreadType.User) {
14
+ if (!Array.isArray(msgs) || msgs.length === 0) {
15
+ throw new ZaloApiError("Missing messages to undo");
16
+ }
17
+ if (!threadId) {
18
+ throw new ZaloApiError("Missing threadId");
19
+ }
20
+ const isGroup = type === ThreadType.Group || threadId.startsWith("g");
21
+ const cleanThreadId = threadId.startsWith("g") ? threadId.slice(1) : threadId;
22
+ const serviceURL = isGroup
23
+ ? utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/multi_undomsg`)
24
+ : utils.makeURL(`${api.zpwServiceMap.chat[0]}/api/message/multi_undo`);
25
+ const now = Date.now();
26
+ const normalizedMsgs = msgs.map((m, idx) => ({
27
+ cliMsgId: m.cliMsgIdUndo !== undefined ? m.cliMsgId : now + idx,
28
+ cliMsgIdUndo: m.cliMsgIdUndo !== undefined ? m.cliMsgIdUndo : m.cliMsgId,
29
+ globalMsgId: String(m.globalMsgId),
30
+ }));
31
+ const payload = isGroup
32
+ ? { grid: cleanThreadId, msgs: normalizedMsgs }
33
+ : { toid: cleanThreadId, msgs: normalizedMsgs };
34
+ const encryptedParams = utils.encodeAES(JSON.stringify(payload));
35
+ if (!encryptedParams) {
36
+ throw new ZaloApiError("Failed to encrypt params");
37
+ }
38
+ const response = await utils.request(serviceURL, {
39
+ method: "POST",
40
+ body: new URLSearchParams({
41
+ params: encryptedParams,
42
+ }),
43
+ });
44
+ return utils.resolve(response);
45
+ };
46
+ });
@@ -0,0 +1,11 @@
1
+ export type UpdateRecentSearchOptions = {
2
+ listRecent?: Record<string, unknown>[];
3
+ listKeyword?: string[];
4
+ version?: number;
5
+ };
6
+ export type UpdateRecentSearchResponse = {
7
+ version: number;
8
+ list_recent: Record<string, unknown>[];
9
+ list_keyword: string[];
10
+ };
11
+ export declare const updateRecentSearchFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options?: UpdateRecentSearchOptions) => Promise<UpdateRecentSearchResponse>;
@@ -0,0 +1,41 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../utils.js";
3
+ export const updateRecentSearchFactory = apiFactory()((api, ctx, utils) => {
4
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.recent_search[0]}/api/recentsearch/update`);
5
+ /**
6
+ * Cập nhật danh sách lịch sử tìm kiếm gần đây trên Zalo (command 12126)
7
+ *
8
+ * @param options Danh sách tìm kiếm gần đây và từ khóa (`listRecent`, `listKeyword`, `version`)
9
+ * @throws {ZaloApiError}
10
+ */
11
+ return async function updateRecentSearch(options = {}) {
12
+ var _a, _b, _c;
13
+ let currentVersion = options.version;
14
+ if (currentVersion === undefined) {
15
+ try {
16
+ const current = await api.getRecentSearchList(0);
17
+ currentVersion = (_a = current === null || current === void 0 ? void 0 : current.version) !== null && _a !== void 0 ? _a : 0;
18
+ }
19
+ catch (_d) {
20
+ currentVersion = 0;
21
+ }
22
+ }
23
+ const params = {
24
+ list_recent: (_b = options.listRecent) !== null && _b !== void 0 ? _b : [],
25
+ version: currentVersion,
26
+ list_keyword: (_c = options.listKeyword) !== null && _c !== void 0 ? _c : [],
27
+ imei: ctx.imei,
28
+ };
29
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
30
+ if (!encryptedParams) {
31
+ throw new ZaloApiError("Failed to encrypt params");
32
+ }
33
+ const response = await utils.request(serviceURL, {
34
+ method: "POST",
35
+ body: new URLSearchParams({
36
+ params: encryptedParams,
37
+ }),
38
+ });
39
+ return utils.resolve(response);
40
+ };
41
+ });
@@ -0,0 +1,14 @@
1
+ import type { GetCloudViewerKeyResponse } from "./getCloudViewerKey.js";
2
+ export type VerifyCloudMediaOptions = {
3
+ lastNoiseId?: string;
4
+ loadType?: number;
5
+ listNoiseIds?: string[];
6
+ trackingSource?: number;
7
+ };
8
+ export type VerifyCloudMediaResponse = {
9
+ lastNoiseId: string;
10
+ hasMore: number;
11
+ mediaItems: Record<string, unknown>[];
12
+ listVerifyNoiseIds: string[];
13
+ };
14
+ export declare const verifyCloudMediaFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options?: VerifyCloudMediaOptions, viewerKeyInfo?: GetCloudViewerKeyResponse) => Promise<VerifyCloudMediaResponse>;
@@ -0,0 +1,43 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory, decryptZCloudAES, encryptZCloudAES } from "../utils.js";
3
+ export const verifyCloudMediaFactory = apiFactory()((api, _ctx, utils) => {
4
+ var _a;
5
+ const baseDomain = ((_a = api.zpwServiceMap.zcloud) === null || _a === void 0 ? void 0 : _a[0]) || "https://zcld.chat.zalo.me";
6
+ const serviceURL = utils.makeURL(`${baseDomain}/cloudmedia/queue/pc/verify`);
7
+ /**
8
+ * Kiểm tra và lấy danh sách mục Media lưu trữ trên ZCloud (command 12740 / 12761)
9
+ *
10
+ * @param options Tùy chọn truy vấn (`lastNoiseId`, `loadType`, `listNoiseIds`, `trackingSource`)
11
+ * @param viewerKeyInfo (Tùy chọn) Cặp `{ viewer_key, enk }` từ `api.getCloudViewerKey()`.
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function verifyCloudMedia(options = {}, viewerKeyInfo) {
15
+ var _a, _b, _c, _d;
16
+ const keyInfo = viewerKeyInfo !== null && viewerKeyInfo !== void 0 ? viewerKeyInfo : (await api.getCloudViewerKey());
17
+ if (!(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.viewer_key) || !(keyInfo === null || keyInfo === void 0 ? void 0 : keyInfo.enk)) {
18
+ throw new ZaloApiError("Invalid CloudViewerKey");
19
+ }
20
+ const payload = {
21
+ lastNoiseId: (_a = options.lastNoiseId) !== null && _a !== void 0 ? _a : "",
22
+ loadType: (_b = options.loadType) !== null && _b !== void 0 ? _b : 0,
23
+ listNoiseIds: (_c = options.listNoiseIds) !== null && _c !== void 0 ? _c : [],
24
+ tracking_source: (_d = options.trackingSource) !== null && _d !== void 0 ? _d : 0,
25
+ };
26
+ const encryptedParams = encryptZCloudAES(JSON.stringify(payload), keyInfo.enk);
27
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
28
+ method: "GET",
29
+ headers: {
30
+ "cloud-viewer-key": keyInfo.viewer_key,
31
+ },
32
+ });
33
+ const json = (await response.json());
34
+ if (json.error_code !== 0 && json.error_code !== -904) {
35
+ throw new ZaloApiError(json.error_message || "verifyCloudMedia failed", json.error_code);
36
+ }
37
+ if (!json.data) {
38
+ throw new ZaloApiError("Empty verifyCloudMedia response", json.error_code);
39
+ }
40
+ const decrypted = decryptZCloudAES(json.data, keyInfo.enk);
41
+ return JSON.parse(decrypted);
42
+ };
43
+ });
@@ -0,0 +1,4 @@
1
+ export type VoiceToTextResponse = {
2
+ req_id: string;
3
+ };
4
+ export declare const voiceToTextFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (voiceUrl: string) => Promise<VoiceToTextResponse>;
@@ -0,0 +1,30 @@
1
+ import { ZaloApiError } from "../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../utils.js";
3
+ export const voiceToTextFactory = apiFactory()((api, _ctx, utils) => {
4
+ var _a;
5
+ const baseDomain = ((_a = api.zpwServiceMap.ai_features) === null || _a === void 0 ? void 0 : _a[0]) || "https://tt-ai-features-wpa.chat.zalo.me";
6
+ const serviceURL = utils.makeURL(`${baseDomain}/api/aifeatures/voice2text`);
7
+ /**
8
+ * Gửi yêu cầu chuyển đổi tin nhắn thoại sang văn bản bằng Zalo AI (command 13394).
9
+ * Kết quả văn bản sau khi xử lý xong sẽ được đẩy về qua sự kiện `api.listener.on("voice2text_event", ...)` khớp với `req_id`.
10
+ *
11
+ * @param voiceUrl Đường dẫn URL của tệp ghi âm tin nhắn thoại (`.aac` / `.mp3` / `.m4a`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function voiceToText(voiceUrl) {
15
+ if (!voiceUrl) {
16
+ throw new ZaloApiError("Missing voiceUrl");
17
+ }
18
+ const encryptedParams = utils.encodeAES(JSON.stringify({ url: voiceUrl }));
19
+ if (!encryptedParams) {
20
+ throw new ZaloApiError("Failed to encrypt params");
21
+ }
22
+ const response = await utils.request(serviceURL, {
23
+ method: "POST",
24
+ body: new URLSearchParams({
25
+ params: encryptedParams,
26
+ }),
27
+ });
28
+ return utils.resolve(response);
29
+ };
30
+ });