@softtynet/zca-js 2.3.2 → 2.3.4

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 (90) hide show
  1. package/README.md +63 -21
  2. package/dist/apis/auth/exportSession.d.ts +7 -0
  3. package/dist/apis/auth/exportSession.js +17 -0
  4. package/dist/apis/chat/getDirectMessageStatus.d.ts +14 -0
  5. package/dist/apis/chat/getDirectMessageStatus.js +52 -0
  6. package/dist/apis/chat/getSuggestedConversations.d.ts +5 -0
  7. package/dist/apis/chat/getSuggestedConversations.js +24 -0
  8. package/dist/apis/chat/updatePinConversations.d.ts +24 -0
  9. package/dist/apis/chat/updatePinConversations.js +40 -0
  10. package/dist/apis/friend/getFriendProfilesV2.d.ts +26 -0
  11. package/dist/apis/friend/getFriendProfilesV2.js +38 -0
  12. package/dist/apis/friend/getFriendsActivePCWeb.d.ts +6 -0
  13. package/dist/apis/friend/getFriendsActivePCWeb.js +15 -0
  14. package/dist/apis/friend/verifyFriend.d.ts +11 -0
  15. package/dist/apis/friend/verifyFriend.js +37 -0
  16. package/dist/apis/group/analyseGroup.d.ts +4 -0
  17. package/dist/apis/group/analyseGroup.js +28 -0
  18. package/dist/apis/group/checkQuotaCommunityMember.d.ts +6 -0
  19. package/dist/apis/group/checkQuotaCommunityMember.js +34 -0
  20. package/dist/apis/group/getE2eeGroupList.d.ts +7 -0
  21. package/dist/apis/group/getE2eeGroupList.js +15 -0
  22. package/dist/apis/group/getGroupChatHistory.d.ts +37 -6
  23. package/dist/apis/group/getGroupChatHistory.js +41 -19
  24. package/dist/apis/group/getGroupCloudMessagePath.d.ts +19 -0
  25. package/dist/apis/group/getGroupCloudMessagePath.js +51 -0
  26. package/dist/apis/group/getGroupHistoryLegacy.d.ts +7 -0
  27. package/dist/apis/group/getGroupHistoryLegacy.js +62 -0
  28. package/dist/apis/group/getGroupInfoV2.d.ts +30 -0
  29. package/dist/apis/group/getGroupInfoV2.js +48 -0
  30. package/dist/apis/group/getGroupListV3.d.ts +19 -0
  31. package/dist/apis/group/getGroupListV3.js +29 -0
  32. package/dist/apis/group/getGroupMessageStatus.d.ts +26 -0
  33. package/dist/apis/group/getGroupMessageStatus.js +77 -0
  34. package/dist/apis/group/getMultiGroupCloudMessages.d.ts +5 -0
  35. package/dist/apis/group/getMultiGroupCloudMessages.js +29 -0
  36. package/dist/apis/media/getConversationMedia.d.ts +10 -0
  37. package/dist/apis/media/getPersonalMedia.d.ts +8 -0
  38. package/dist/apis/media/getPersonalMedia.js +31 -0
  39. package/dist/apis/media/getPersonalMediaPreview.d.ts +3 -0
  40. package/dist/apis/media/getPersonalMediaPreview.js +24 -0
  41. package/dist/apis/media/removePersonalMedia.d.ts +9 -0
  42. package/dist/apis/media/removePersonalMedia.js +28 -0
  43. package/dist/apis.d.ts +57 -0
  44. package/dist/apis.js +95 -0
  45. package/dist/cjs/apis/auth/exportSession.cjs +22 -0
  46. package/dist/cjs/apis/chat/getDirectMessageStatus.cjs +58 -0
  47. package/dist/cjs/apis/chat/getSuggestedConversations.cjs +29 -0
  48. package/dist/cjs/apis/chat/updatePinConversations.cjs +45 -0
  49. package/dist/cjs/apis/friend/getFriendProfilesV2.cjs +43 -0
  50. package/dist/cjs/apis/friend/getFriendsActivePCWeb.cjs +20 -0
  51. package/dist/cjs/apis/friend/verifyFriend.cjs +42 -0
  52. package/dist/cjs/apis/group/analyseGroup.cjs +33 -0
  53. package/dist/cjs/apis/group/checkQuotaCommunityMember.cjs +39 -0
  54. package/dist/cjs/apis/group/getE2eeGroupList.cjs +20 -0
  55. package/dist/cjs/apis/group/getGroupChatHistory.cjs +41 -18
  56. package/dist/cjs/apis/group/getGroupCloudMessagePath.cjs +69 -0
  57. package/dist/cjs/apis/group/getGroupHistoryLegacy.cjs +80 -0
  58. package/dist/cjs/apis/group/getGroupInfoV2.cjs +53 -0
  59. package/dist/cjs/apis/group/getGroupListV3.cjs +34 -0
  60. package/dist/cjs/apis/group/getGroupMessageStatus.cjs +83 -0
  61. package/dist/cjs/apis/group/getMultiGroupCloudMessages.cjs +34 -0
  62. package/dist/cjs/apis/media/getPersonalMedia.cjs +36 -0
  63. package/dist/cjs/apis/media/getPersonalMediaPreview.cjs +29 -0
  64. package/dist/cjs/apis/media/removePersonalMedia.cjs +33 -0
  65. package/dist/cjs/apis.cjs +95 -0
  66. package/dist/cjs/constants/endpoints.cjs +13 -0
  67. package/dist/cjs/constants/protocol.cjs +1 -1
  68. package/dist/cjs/context.cjs +20 -2
  69. package/dist/cjs/core/zcloud-client.cjs +1 -2
  70. package/dist/cjs/crypto/ws-cipher.cjs +66 -2
  71. package/dist/cjs/index.cjs +2 -0
  72. package/dist/cjs/realtime/listener.cjs +18 -6
  73. package/dist/cjs/update.cjs +10 -1
  74. package/dist/cjs/utils.cjs +22 -5
  75. package/dist/constants/endpoints.d.ts +13 -0
  76. package/dist/constants/endpoints.js +13 -0
  77. package/dist/constants/protocol.d.ts +1 -1
  78. package/dist/constants/protocol.js +1 -1
  79. package/dist/context.d.ts +10 -0
  80. package/dist/context.js +20 -2
  81. package/dist/crypto/ws-cipher.d.ts +7 -0
  82. package/dist/crypto/ws-cipher.js +64 -2
  83. package/dist/index.d.ts +22 -3
  84. package/dist/index.js +1 -1
  85. package/dist/realtime/listener.d.ts +1 -0
  86. package/dist/realtime/listener.js +18 -6
  87. package/dist/update.js +10 -1
  88. package/dist/utils.js +17 -4
  89. package/index.d.ts +1 -1
  90. package/package.json +15 -5
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const checkQuotaCommunityMemberFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/quota/members-comm`);
8
+ /**
9
+ * Kiểm tra điều kiện/hạn mức thành viên Cộng đồng đối với một thành viên cụ thể trong nhóm (command 12182)
10
+ *
11
+ * @param groupId ID của nhóm
12
+ * @param uid UID của thành viên cần kiểm tra
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function checkQuotaCommunityMember(groupId, uid) {
16
+ if (!groupId) {
17
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
18
+ }
19
+ if (!uid) {
20
+ throw new ZaloApiError.ZaloApiError("Missing uid");
21
+ }
22
+ const cleanGroupId = groupId.startsWith("g") ? groupId.slice(1) : groupId;
23
+ const params = {
24
+ language: ctx.language || "vi",
25
+ grId: cleanGroupId,
26
+ uid: String(uid),
27
+ };
28
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
29
+ if (!encryptedParams) {
30
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
31
+ }
32
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
33
+ method: "GET",
34
+ });
35
+ return utils.resolve(response);
36
+ };
37
+ });
38
+
39
+ exports.checkQuotaCommunityMemberFactory = checkQuotaCommunityMemberFactory;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../../utils.cjs');
4
+
5
+ const getE2eeGroupListFactory = utils.apiFactory()((api, _ctx, utils) => {
6
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getlg/e2ee`);
7
+ /**
8
+ * Lấy danh sách các nhóm đang bật mã hóa đầu cuối E2EE (command 12146)
9
+ *
10
+ * @throws {ZaloApiError}
11
+ */
12
+ return async function getE2eeGroupList() {
13
+ const response = await utils.request(serviceURL, {
14
+ method: "GET",
15
+ });
16
+ return utils.resolve(response);
17
+ };
18
+ });
19
+
20
+ exports.getE2eeGroupListFactory = getE2eeGroupListFactory;
@@ -15,66 +15,89 @@ require('../../models/Reminder.cjs');
15
15
  require('../../models/ZBusiness.cjs');
16
16
  require('../../models/SyncEvent.cjs');
17
17
  require('../../models/CallEvent.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
18
19
 
19
20
  const getGroupChatHistoryFactory = utils.apiFactory()((api, ctx, utils) => {
20
- const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getrecentv2`);
21
+ const recentServiceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getrecentv2`);
22
+ const oldServiceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getoldv2`);
21
23
  /**
22
- * Get group chat history from Zalo Cloud Message (newest first)
24
+ * Lấy lịch sử tin nhắn nhóm từ Zalo Cloud Message (hỗ trợ cả `/api/cm/getrecentv2` cmd 12506 và `/api/cm/getoldv2` cmd 12507)
23
25
  *
24
- * @param groupId group id
25
- * @param count count of messages to return (default: 50, max safe limit: 200)
26
+ * @param groupId ID nhóm
27
+ * @param countOrOptions Số lượng tin nhắn cần tải (mặc định: `50`) hoặc đối tượng cấu hình phân trang `GetGroupChatHistoryOptions`
26
28
  *
27
29
  * @throws {ZaloApiError}
28
30
  */
29
- return async function getGroupChatHistory(groupId, count = 50) {
31
+ return async function getGroupChatHistory(groupId, countOrOptions = 50) {
30
32
  if (!groupId)
31
33
  throw new ZaloApiError.ZaloApiError("Missing groupId");
32
34
  if (groupId.startsWith("g"))
33
35
  groupId = groupId.slice(1);
34
- const safeCount = Math.min(Math.max(count, 1), 200);
36
+ const options = typeof countOrOptions === "number" ? { count: countOrOptions } : countOrOptions || {};
37
+ const requestedCount = Math.max(options.count ?? 50, 1);
38
+ const maxPages = options.maxPages ?? Math.max(10, Math.ceil(requestedCount / 50) + 2);
39
+ const targetServiceURL = options.useOldEndpoint ? oldServiceURL : recentServiceURL;
40
+ const msgIds = options.msgIds ?? [];
41
+ const src = options.src ?? 3;
35
42
  const messages = [];
36
- let cursor = 0;
43
+ const seenMsgIds = new Set();
44
+ let cursor = options.cursor ?? 0;
37
45
  let lastPage = null;
38
46
  let pageCount = 0;
39
- while (messages.length < safeCount && pageCount < 10) {
47
+ while (messages.length < requestedCount && pageCount < maxPages) {
40
48
  pageCount++;
41
49
  const params = {
42
50
  groupId,
43
51
  globalMsgId: cursor,
44
- count: Math.min(50, safeCount - messages.length),
45
- msgIds: [],
52
+ count: Math.min(50, requestedCount - messages.length),
53
+ msgIds,
46
54
  imei: ctx.imei,
47
- src: 3,
55
+ src,
48
56
  };
57
+ if (options.isOA) {
58
+ params.isOA = 1;
59
+ }
49
60
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
50
61
  if (!encryptedParams)
51
62
  throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
52
- const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams, nretry: 0 }), {
63
+ const response = await utils.request(utils.makeURL(targetServiceURL, { params: encryptedParams, nretry: 0 }), {
53
64
  method: "GET",
54
65
  });
55
66
  lastPage = await utils.resolve(response, (result) => {
56
67
  let data = result.data;
57
68
  if (typeof data === "string") {
58
- data = JSON.parse(data);
69
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
59
70
  }
60
71
  return data;
61
72
  });
62
73
  if (!lastPage || !Array.isArray(lastPage.groupMsgs))
63
74
  break;
64
75
  for (const rawMsg of lastPage.groupMsgs) {
65
- if (messages.length >= safeCount)
76
+ if (messages.length >= requestedCount)
66
77
  break;
67
- if (messages.some((m) => m.msgId === rawMsg.msgId))
78
+ const msgIdKey = String(rawMsg.msgId ?? rawMsg.cliMsgId ?? "");
79
+ if (msgIdKey && seenMsgIds.has(msgIdKey))
68
80
  continue;
81
+ if (msgIdKey)
82
+ seenMsgIds.add(msgIdKey);
69
83
  messages.push(rawMsg);
70
84
  }
71
- const nextCursor = Number(lastPage.lastMsgId);
72
- if (!lastPage.hasMore || !nextCursor || nextCursor === cursor)
85
+ const nextCursor = lastPage.lastMsgId;
86
+ if (!lastPage.hasMore ||
87
+ nextCursor === undefined ||
88
+ nextCursor === null ||
89
+ nextCursor === "" ||
90
+ nextCursor === 0 ||
91
+ String(nextCursor) === String(cursor)) {
73
92
  break;
93
+ }
74
94
  cursor = nextCursor;
75
95
  }
76
96
  const groupMsgs = messages.map((data) => new Message.GroupMessage(ctx.uid, data));
77
- return Object.assign({}, lastPage || {}, { groupMsgs });
97
+ return Object.assign({}, lastPage || {}, {
98
+ groupMsgs,
99
+ nextCursor: lastPage?.lastMsgId,
100
+ });
78
101
  };
79
102
  });
80
103
 
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ require('../../models/AutoReply.cjs');
5
+ require('../../models/Bank.cjs');
6
+ require('../../models/Board.cjs');
7
+ require('../../models/Enum.cjs');
8
+ require('../../models/FriendEvent.cjs');
9
+ require('../../models/Group.cjs');
10
+ require('../../models/GroupEvent.cjs');
11
+ var Message = require('../../models/Message.cjs');
12
+ require('../../models/Reaction.cjs');
13
+ require('../../models/Reminder.cjs');
14
+ require('../../models/ZBusiness.cjs');
15
+ require('../../models/SyncEvent.cjs');
16
+ require('../../models/CallEvent.cjs');
17
+ var utils = require('../../utils.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
19
+
20
+ const getGroupCloudMessagePathFactory = utils.apiFactory()((api, ctx, utils) => {
21
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getpath`);
22
+ /**
23
+ * Lấy chuỗi tin nhắn nhóm theo đường dẫn nhảy tới một tin nhắn cụ thể (`globalMsgId` / `rGlobalMsgId`) qua `/api/cm/getpath` (command 12504)
24
+ *
25
+ * @param options Cấu hình truy vấn đường dẫn tin nhắn nhóm
26
+ * @throws {ZaloApiError}
27
+ */
28
+ return async function getGroupCloudMessagePath(options) {
29
+ if (!options?.groupId) {
30
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
31
+ }
32
+ const cleanGroupId = options.groupId.startsWith("g") ? options.groupId.slice(1) : options.groupId;
33
+ const params = {
34
+ groupId: cleanGroupId,
35
+ globalMsgId: options.globalMsgId,
36
+ count: options.count ?? 50,
37
+ reverse: typeof options.reverse === "boolean" ? (options.reverse ? 1 : 0) : (options.reverse ?? 0),
38
+ };
39
+ if (options.rGlobalMsgId !== undefined && options.rOwnerId) {
40
+ params.rGlobalMsgId = options.rGlobalMsgId;
41
+ params.rOwnerId = options.rOwnerId;
42
+ if (options.rClientMsgId !== undefined) {
43
+ params.rClientMsgId = options.rClientMsgId;
44
+ }
45
+ }
46
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
47
+ if (!encryptedParams) {
48
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
49
+ }
50
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams, nretry: 0 }), {
51
+ method: "GET",
52
+ });
53
+ return utils.resolve(response, (result) => {
54
+ let data = result.data;
55
+ if (typeof data === "string") {
56
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
57
+ }
58
+ const rawObj = (data && typeof data === "object" ? data : {});
59
+ const rawMsgs = Array.isArray(rawObj.groupMsgs) ? rawObj.groupMsgs : [];
60
+ const groupMsgs = rawMsgs.map((m) => new Message.GroupMessage(ctx.uid, m));
61
+ return {
62
+ ...rawObj,
63
+ groupMsgs,
64
+ };
65
+ });
66
+ };
67
+ });
68
+
69
+ exports.getGroupCloudMessagePathFactory = getGroupCloudMessagePathFactory;
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ require('../../models/AutoReply.cjs');
5
+ require('../../models/Bank.cjs');
6
+ require('../../models/Board.cjs');
7
+ require('../../models/Enum.cjs');
8
+ require('../../models/FriendEvent.cjs');
9
+ require('../../models/Group.cjs');
10
+ require('../../models/GroupEvent.cjs');
11
+ var Message = require('../../models/Message.cjs');
12
+ require('../../models/Reaction.cjs');
13
+ require('../../models/Reminder.cjs');
14
+ require('../../models/ZBusiness.cjs');
15
+ require('../../models/SyncEvent.cjs');
16
+ require('../../models/CallEvent.cjs');
17
+ var utils = require('../../utils.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
19
+
20
+ const getGroupHistoryLegacyFactory = utils.apiFactory()((api, ctx, utils) => {
21
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/history`);
22
+ /**
23
+ * Lấy lịch sử tin nhắn nhóm qua endpoint `/api/group/history` trên miền `group` (command 11240)
24
+ *
25
+ * @param groupId ID của nhóm
26
+ * @param count Số lượng tin nhắn cần tải (mặc định: `20`)
27
+ * @throws {ZaloApiError}
28
+ */
29
+ return async function getGroupHistoryLegacy(groupId, count = 20) {
30
+ if (!groupId) {
31
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
32
+ }
33
+ const cleanGroupId = groupId.startsWith("g") ? groupId.slice(1) : groupId;
34
+ const params = {
35
+ grid: cleanGroupId,
36
+ count,
37
+ };
38
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
39
+ if (!encryptedParams) {
40
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
41
+ }
42
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
43
+ method: "GET",
44
+ });
45
+ return utils.resolve(response, (result) => {
46
+ let data = result.data;
47
+ if (typeof data === "string") {
48
+ try {
49
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
50
+ }
51
+ catch {
52
+ data = {};
53
+ }
54
+ }
55
+ if (Array.isArray(data)) {
56
+ const groupMsgs = data.map((m) => new Message.GroupMessage(ctx.uid, m));
57
+ return { groupMsgs };
58
+ }
59
+ if (data && typeof data === "object") {
60
+ const obj = data;
61
+ const rawList = Array.isArray(obj.groupMsgs)
62
+ ? obj.groupMsgs
63
+ : Array.isArray(obj.msgs)
64
+ ? obj.msgs
65
+ : null;
66
+ if (rawList) {
67
+ const groupMsgs = rawList.map((m) => new Message.GroupMessage(ctx.uid, m));
68
+ return {
69
+ ...obj,
70
+ groupMsgs,
71
+ };
72
+ }
73
+ return obj;
74
+ }
75
+ return { groupMsgs: [] };
76
+ });
77
+ };
78
+ });
79
+
80
+ exports.getGroupHistoryLegacyFactory = getGroupHistoryLegacyFactory;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getGroupInfoV2Factory = utils.apiFactory()((api, ctx, utils) => {
7
+ const v2ServiceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getgi/v2`);
8
+ const v1ServiceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getgi`);
9
+ /**
10
+ * Lấy thông tin nhóm và danh sách thành viên theo trang qua `/api/group/getgi/v2` hoặc `/api/group/getgi` (command 11162)
11
+ *
12
+ * @param groupId ID của nhóm
13
+ * @param pageOrOptions Số trang `mpage` (mặc định: `1`) hoặc cấu hình `GetGroupInfoV2Options`
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function getGroupInfoV2(groupId, pageOrOptions = 1) {
17
+ if (!groupId) {
18
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
19
+ }
20
+ const cleanGroupId = groupId.startsWith("g") ? groupId.slice(1) : groupId;
21
+ const options = typeof pageOrOptions === "number" ? { mpage: pageOrOptions } : pageOrOptions || {};
22
+ const mpage = options.mpage ?? 1;
23
+ const mcount = options.mcount ?? 100;
24
+ const avatarSize = options.avatarSize ?? 120;
25
+ const memberAvatarSize = options.memberAvatarSize ?? 120;
26
+ const useV1 = Boolean(options.useV1Endpoint);
27
+ const targetURL = useV1 ? v1ServiceURL : v2ServiceURL;
28
+ const params = useV1
29
+ ? {
30
+ grid: cleanGroupId,
31
+ avatar_size: avatarSize,
32
+ member_avatar_size: memberAvatarSize,
33
+ }
34
+ : {
35
+ grid: cleanGroupId,
36
+ avatar_size: avatarSize,
37
+ member_avatar_size: memberAvatarSize,
38
+ mpage,
39
+ mcount,
40
+ imei: ctx.imei,
41
+ };
42
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
43
+ if (!encryptedParams) {
44
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
45
+ }
46
+ const response = await utils.request(utils.makeURL(targetURL, { params: encryptedParams }), {
47
+ method: "GET",
48
+ });
49
+ return utils.resolve(response);
50
+ };
51
+ });
52
+
53
+ exports.getGroupInfoV2Factory = getGroupInfoV2Factory;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getGroupListV3Factory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getlg/v3`);
8
+ /**
9
+ * Lấy danh sách nhóm theo trang kèm thông tin thành viên đại diện (`currentMems`) và gợi ý nhóm (`suggestGroup`) qua `/api/group/getlg/v3` (command 11161)
10
+ *
11
+ * @param pageOrOptions Số trang (mặc định: `1`) hoặc cấu hình `GetGroupListV3Options`
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getGroupListV3(pageOrOptions = 1) {
15
+ const options = typeof pageOrOptions === "number" ? { page: pageOrOptions } : pageOrOptions || {};
16
+ const params = {
17
+ page: options.page ?? 1,
18
+ count: options.count ?? 100,
19
+ avatar_size: 120,
20
+ member_avatar_size: 120,
21
+ imei: ctx.imei,
22
+ };
23
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
24
+ if (!encryptedParams) {
25
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
26
+ }
27
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
28
+ method: "GET",
29
+ });
30
+ return utils.resolve(response);
31
+ };
32
+ });
33
+
34
+ exports.getGroupListV3Factory = getGroupListV3Factory;
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
6
+
7
+ const getGroupMessageStatusFactory = utils.apiFactory()((api, _ctx, utils) => {
8
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getStatusMsg`);
9
+ /**
10
+ * Truy vấn trạng thái Đã nhận (`deliver`) và Đã xem (`seen`) tin nhắn của danh sách thành viên trong nhóm (command 12017)
11
+ *
12
+ * @param groupIdOrItems ID nhóm (hoặc mảng cấu hình `{ tId, ids }`)
13
+ * @param memberIds Danh sách UID thành viên cần kiểm tra (khi tham số đầu là `groupId`)
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function getGroupMessageStatus(groupIdOrItems, memberIds = []) {
17
+ let queryData;
18
+ if (Array.isArray(groupIdOrItems)) {
19
+ queryData = groupIdOrItems.map((item) => ({
20
+ tId: item.tId.startsWith("g") ? item.tId.slice(1) : item.tId,
21
+ ids: item.ids.map(String),
22
+ }));
23
+ }
24
+ else {
25
+ if (!groupIdOrItems) {
26
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
27
+ }
28
+ const cleanGroupId = groupIdOrItems.startsWith("g") ? groupIdOrItems.slice(1) : groupIdOrItems;
29
+ queryData = [
30
+ {
31
+ tId: cleanGroupId,
32
+ ids: memberIds.map(String),
33
+ },
34
+ ];
35
+ }
36
+ const params = {
37
+ param: JSON.stringify({
38
+ data: queryData,
39
+ }),
40
+ };
41
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
42
+ if (!encryptedParams) {
43
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
44
+ }
45
+ const response = await utils.request(serviceURL, {
46
+ method: "POST",
47
+ body: new URLSearchParams({
48
+ params: encryptedParams,
49
+ }),
50
+ });
51
+ return utils.resolve(response, (result) => {
52
+ let rawData = result.data;
53
+ if (typeof rawData === "string" && rawData.length > 0) {
54
+ try {
55
+ const parsed = JSON.parse(wsCipher.preParseJsonIds(rawData));
56
+ if (parsed && typeof parsed === "object" && "data" in parsed && parsed.data) {
57
+ rawData = parsed.data;
58
+ }
59
+ else {
60
+ rawData = parsed;
61
+ }
62
+ }
63
+ catch {
64
+ // Giữ nguyên nếu không phải chuỗi JSON lồng
65
+ }
66
+ }
67
+ if (rawData && typeof rawData === "object") {
68
+ const obj = rawData;
69
+ if (Array.isArray(obj.statusInfos)) {
70
+ return obj;
71
+ }
72
+ if (obj.data && typeof obj.data === "object" && Array.isArray(obj.data.statusInfos)) {
73
+ return obj.data;
74
+ }
75
+ }
76
+ return {
77
+ statusInfos: Array.isArray(rawData) ? rawData : [],
78
+ };
79
+ });
80
+ };
81
+ });
82
+
83
+ exports.getGroupMessageStatusFactory = getGroupMessageStatusFactory;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getMultiGroupCloudMessagesFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/mget`);
8
+ /**
9
+ * Đồng bộ nhanh tin nhắn Cloud của nhiều nhóm cùng lúc theo danh sách `groupIds` (command 12503 - `syncCloudMsgFirstLogin`)
10
+ *
11
+ * @param groupIds Danh sách ID nhóm cần tải tin nhắn Cloud
12
+ * @param nretry Số lần thử lại (mặc định: `0`)
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function getMultiGroupCloudMessages(groupIds, nretry = 0) {
16
+ if (!Array.isArray(groupIds) || groupIds.length === 0) {
17
+ throw new ZaloApiError.ZaloApiError("Missing groupIds");
18
+ }
19
+ const cleanGroupIds = groupIds.map((gid) => (gid.startsWith("g") ? gid.slice(1) : gid));
20
+ const params = {
21
+ groupIds: cleanGroupIds,
22
+ };
23
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
24
+ if (!encryptedParams) {
25
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
26
+ }
27
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams, nretry }), {
28
+ method: "GET",
29
+ });
30
+ return utils.resolve(response);
31
+ };
32
+ });
33
+
34
+ exports.getMultiGroupCloudMessagesFactory = getMultiGroupCloudMessagesFactory;
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getPersonalMediaFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/list`);
8
+ /**
9
+ * Lấy danh sách Kho Lưu Trữ Ảnh/Video (`"media"`), File (`"file"`), hoặc Link (`"link"`) trong Cloud của tôi (Send2Me) (command 12220)
10
+ *
11
+ * @param options Tùy chọn truy vấn (`mediaType`, `limit`, `lastId`, `lastFetchId`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getPersonalMedia(options = {}) {
15
+ const params = {
16
+ media_type: options.mediaType ?? "media",
17
+ limit: options.limit ?? 20,
18
+ };
19
+ if (options.lastId !== undefined) {
20
+ params.last_id = options.lastId;
21
+ }
22
+ if (options.lastFetchId !== undefined && !Number.isNaN(options.lastFetchId)) {
23
+ params.lastFetchId = options.lastFetchId;
24
+ }
25
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
26
+ if (!encryptedParams) {
27
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
28
+ }
29
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
30
+ method: "GET",
31
+ });
32
+ return utils.resolve(response);
33
+ };
34
+ });
35
+
36
+ exports.getPersonalMediaFactory = getPersonalMediaFactory;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getPersonalMediaPreviewFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/preview`);
8
+ /**
9
+ * Lấy danh sách xem trước nhanh Kho Lưu Trữ trong Cloud của tôi (Send2Me) (command 12221)
10
+ *
11
+ * @param limit Số lượng mục tối đa (mặc định: `50`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getPersonalMediaPreview(limit = 50) {
15
+ const params = {
16
+ limit,
17
+ };
18
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
19
+ if (!encryptedParams) {
20
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
21
+ }
22
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
23
+ method: "POST",
24
+ });
25
+ return utils.resolve(response);
26
+ };
27
+ });
28
+
29
+ exports.getPersonalMediaPreviewFactory = getPersonalMediaPreviewFactory;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const removePersonalMediaFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/remove`);
8
+ /**
9
+ * Xóa mục lưu trữ trong Kho Lưu Trữ Cloud của tôi (Send2Me) (command 12222)
10
+ *
11
+ * @param options Thông tin mục cần xóa (`mediaType`, `mediaId`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function removePersonalMedia(options) {
15
+ if (!options?.mediaType || options.mediaId === undefined) {
16
+ throw new ZaloApiError.ZaloApiError("Missing mediaType or mediaId");
17
+ }
18
+ const params = {
19
+ media_type: options.mediaType,
20
+ media_id: options.mediaId,
21
+ };
22
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
23
+ if (!encryptedParams) {
24
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
25
+ }
26
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
27
+ method: "POST",
28
+ });
29
+ return utils.resolve(response);
30
+ };
31
+ });
32
+
33
+ exports.removePersonalMediaFactory = removePersonalMediaFactory;