@softtynet/zca-js 2.1.21 → 2.2.2

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 (94) hide show
  1. package/README.md +47 -21
  2. package/dist/apis/cancelPullMobile.d.ts +11 -0
  3. package/dist/apis/cancelPullMobile.js +33 -0
  4. package/dist/apis/cancelVoiceCall.d.ts +7 -0
  5. package/dist/apis/cancelVoiceCall.js +43 -0
  6. package/dist/apis/decryptGids.d.ts +2 -1
  7. package/dist/apis/decryptGids.js +2 -0
  8. package/dist/apis/endVoiceCall.d.ts +5 -0
  9. package/dist/apis/endVoiceCall.js +41 -0
  10. package/dist/apis/getNoisedIds.d.ts +9 -0
  11. package/dist/apis/getNoisedIds.js +67 -0
  12. package/dist/apis/getSyncData.d.ts +13 -0
  13. package/dist/apis/getSyncData.js +103 -0
  14. package/dist/apis/listen.d.ts +11 -3
  15. package/dist/apis/listen.js +71 -14
  16. package/dist/apis/preloadConversations.d.ts +20 -2
  17. package/dist/apis/preloadConversations.js +56 -3
  18. package/dist/apis/pullMobile.d.ts +15 -0
  19. package/dist/apis/pullMobile.js +38 -0
  20. package/dist/apis/requestSyncFromPhone.d.ts +17 -1
  21. package/dist/apis/requestSyncFromPhone.js +34 -20
  22. package/dist/apis/sendVoiceCall.d.ts +29 -0
  23. package/dist/apis/sendVoiceCall.js +105 -0
  24. package/dist/apis/uploadAttachment.js +6 -1
  25. package/dist/apis.d.ts +14 -0
  26. package/dist/apis.js +14 -0
  27. package/dist/cjs/apis/addReaction.cjs +2 -0
  28. package/dist/cjs/apis/addUnreadMark.cjs +2 -0
  29. package/dist/cjs/apis/cancelPullMobile.cjs +38 -0
  30. package/dist/cjs/apis/cancelVoiceCall.cjs +48 -0
  31. package/dist/cjs/apis/createReminder.cjs +2 -0
  32. package/dist/cjs/apis/decryptGids.cjs +2 -0
  33. package/dist/cjs/apis/deleteChat.cjs +2 -0
  34. package/dist/cjs/apis/deleteMessage.cjs +2 -0
  35. package/dist/cjs/apis/editReminder.cjs +2 -0
  36. package/dist/cjs/apis/endVoiceCall.cjs +46 -0
  37. package/dist/cjs/apis/findUser.cjs +2 -0
  38. package/dist/cjs/apis/findUserByUsername.cjs +2 -0
  39. package/dist/cjs/apis/forwardMessage.cjs +2 -0
  40. package/dist/cjs/apis/getAllFriends.cjs +2 -0
  41. package/dist/cjs/apis/getAvatarUrlProfile.cjs +2 -0
  42. package/dist/cjs/apis/getGroupChatHistory.cjs +2 -0
  43. package/dist/cjs/apis/getListBoard.cjs +2 -0
  44. package/dist/cjs/apis/getListReminder.cjs +2 -0
  45. package/dist/cjs/apis/getMultiUsersByPhones.cjs +2 -0
  46. package/dist/cjs/apis/getNoisedIds.cjs +72 -0
  47. package/dist/cjs/apis/getSyncData.cjs +108 -0
  48. package/dist/cjs/apis/getUserInfo.cjs +2 -0
  49. package/dist/cjs/apis/listen.cjs +71 -14
  50. package/dist/cjs/apis/preloadConversations.cjs +69 -3
  51. package/dist/cjs/apis/pullMobile.cjs +43 -0
  52. package/dist/cjs/apis/removeReminder.cjs +2 -0
  53. package/dist/cjs/apis/removeUnreadMark.cjs +2 -0
  54. package/dist/cjs/apis/requestSyncFromPhone.cjs +33 -19
  55. package/dist/cjs/apis/sendBankCard.cjs +2 -0
  56. package/dist/cjs/apis/sendCard.cjs +2 -0
  57. package/dist/cjs/apis/sendDeliveredEvent.cjs +2 -0
  58. package/dist/cjs/apis/sendLink.cjs +2 -0
  59. package/dist/cjs/apis/sendMessage.cjs +2 -0
  60. package/dist/cjs/apis/sendReport.cjs +2 -0
  61. package/dist/cjs/apis/sendSeenEvent.cjs +2 -0
  62. package/dist/cjs/apis/sendSticker.cjs +2 -0
  63. package/dist/cjs/apis/sendTypingEvent.cjs +2 -0
  64. package/dist/cjs/apis/sendVideo.cjs +2 -0
  65. package/dist/cjs/apis/sendVoice.cjs +2 -0
  66. package/dist/cjs/apis/sendVoiceCall.cjs +110 -0
  67. package/dist/cjs/apis/setHiddenConversations.cjs +2 -0
  68. package/dist/cjs/apis/setMute.cjs +2 -0
  69. package/dist/cjs/apis/setPinnedConversations.cjs +2 -0
  70. package/dist/cjs/apis/undo.cjs +2 -0
  71. package/dist/cjs/apis/updateAutoDeleteChat.cjs +2 -0
  72. package/dist/cjs/apis/uploadAttachment.cjs +8 -1
  73. package/dist/cjs/apis.cjs +14 -0
  74. package/dist/cjs/index.cjs +24 -0
  75. package/dist/cjs/models/CallEvent.cjs +51 -0
  76. package/dist/cjs/models/ClearUnread.cjs +17 -0
  77. package/dist/cjs/models/SyncEvent.cjs +54 -0
  78. package/dist/cjs/utils.cjs +153 -1
  79. package/dist/index.d.ts +11 -1
  80. package/dist/index.js +2 -0
  81. package/dist/models/CallEvent.d.ts +30 -0
  82. package/dist/models/CallEvent.js +47 -0
  83. package/dist/models/ClearUnread.d.ts +22 -0
  84. package/dist/models/ClearUnread.js +12 -0
  85. package/dist/models/SyncData.d.ts +35 -0
  86. package/dist/models/SyncData.js +1 -0
  87. package/dist/models/SyncEvent.d.ts +83 -0
  88. package/dist/models/SyncEvent.js +50 -0
  89. package/dist/models/index.d.ts +4 -0
  90. package/dist/models/index.js +4 -0
  91. package/dist/utils.d.ts +34 -0
  92. package/dist/utils.js +148 -1
  93. package/docs/REA_REVERSE_ENGINEERING_PLAN.md +140 -0
  94. package/package.json +1 -1
@@ -1,18 +1,34 @@
1
1
  'use strict';
2
2
 
3
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
+ var ClearUnread = require('../models/ClearUnread.cjs');
16
+ require('../models/SyncEvent.cjs');
17
+ require('../models/CallEvent.cjs');
4
18
  var utils = require('../utils.cjs');
5
19
 
6
20
  const preloadConversationsFactory = utils.apiFactory()((api, ctx, utils) => {
7
21
  const serviceURL = utils.makeURL(`${api.zpwServiceMap.conversation[0]}/api/preloadconvers/get-last-msgs`);
8
22
  /**
9
- * Preload last messages across all active conversations.
23
+ * Preload last messages and unread-cleared states across active conversations.
10
24
  * Useful for initial state loading and catching up missed messages after reconnect.
11
25
  *
26
+ * @param threadIdLocalMsgId Optional map of `{ [threadId]: lastLocalMsgId }` (defaults to `{}`)
12
27
  * @throws {ZaloApiError}
13
28
  */
14
- return async function preloadConversations() {
29
+ return async function preloadConversations(threadIdLocalMsgId = {}) {
15
30
  const params = {
31
+ threadIdLocalMsgId: JSON.stringify(threadIdLocalMsgId !== null && threadIdLocalMsgId !== void 0 ? threadIdLocalMsgId : {}),
16
32
  imei: ctx.imei,
17
33
  };
18
34
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
@@ -21,7 +37,57 @@ const preloadConversationsFactory = utils.apiFactory()((api, ctx, utils) => {
21
37
  const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
22
38
  method: "GET",
23
39
  });
24
- return utils.resolve(response);
40
+ return utils.resolve(response, (result) => {
41
+ var _a, _b, _c, _d;
42
+ let data = ((_a = result.data) !== null && _a !== void 0 ? _a : {});
43
+ if (typeof data === "string") {
44
+ data = JSON.parse(data);
45
+ }
46
+ const messages = [];
47
+ const seenMsgIds = new Set();
48
+ if (Array.isArray(data.msgs)) {
49
+ for (const msg of data.msgs) {
50
+ const id = String((_b = msg.msgId) !== null && _b !== void 0 ? _b : "");
51
+ if (id && seenMsgIds.has(id))
52
+ continue;
53
+ if (id)
54
+ seenMsgIds.add(id);
55
+ messages.push(new Message.UserMessage(ctx.uid, msg));
56
+ }
57
+ }
58
+ if (Array.isArray(data.groupMsgs)) {
59
+ for (const msg of data.groupMsgs) {
60
+ const id = String((_c = msg.msgId) !== null && _c !== void 0 ? _c : "");
61
+ if (id && seenMsgIds.has(id))
62
+ continue;
63
+ if (id)
64
+ seenMsgIds.add(id);
65
+ messages.push(new Message.GroupMessage(ctx.uid, msg));
66
+ }
67
+ }
68
+ if (Array.isArray(data.allmsgs)) {
69
+ for (const msg of data.allmsgs) {
70
+ const id = String((_d = msg.msgId) !== null && _d !== void 0 ? _d : "");
71
+ if (id && seenMsgIds.has(id))
72
+ continue;
73
+ if (id)
74
+ seenMsgIds.add(id);
75
+ const isGroup = ("isGroup" in msg && Boolean(msg.isGroup)) ||
76
+ (typeof msg.idTo === "string" && msg.idTo.startsWith("g"));
77
+ if (isGroup) {
78
+ messages.push(new Message.GroupMessage(ctx.uid, msg));
79
+ }
80
+ else {
81
+ messages.push(new Message.UserMessage(ctx.uid, msg));
82
+ }
83
+ }
84
+ }
85
+ const unreadCleared = Array.isArray(data.clearUnreads)
86
+ ? data.clearUnreads.map((item) => new ClearUnread.ClearUnread(item))
87
+ : [];
88
+ return Object.assign(Object.assign({}, data), { messages,
89
+ unreadCleared });
90
+ });
25
91
  };
26
92
  });
27
93
 
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const pullMobileFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const baseURL = utils.makeURL(`${api.zpwServiceMap.file[0]}/api/message/pull_mobile_msg`);
8
+ /**
9
+ * Yêu cầu thiết bị di động Zalo đóng gói và tải lên bản sao lưu tin nhắn (`pull_mobile_msg`, command `12000`).
10
+ * Sự kiện tiến trình (`user_confirm`, `syncmsg_info`, `transfer_error`) sẽ được đẩy về qua `api.listener.on("sync_event")`.
11
+ *
12
+ * @param params Tham số khởi tạo đồng bộ (bao gồm `public_key` RSA SPKI DER Base64)
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function pullMobile({ public_key, pc_name = "Web", from_seq_id = 0, is_retry = 0, min_seq_id = 0, temp_key = "", }) {
16
+ if (!public_key)
17
+ throw new ZaloApiError.ZaloApiError("Missing public_key");
18
+ const payload = {
19
+ pc_name,
20
+ public_key,
21
+ from_seq_id,
22
+ is_retry,
23
+ min_seq_id,
24
+ temp_key,
25
+ imei: ctx.imei,
26
+ };
27
+ const encryptedParams = utils.encodeAES(JSON.stringify(payload));
28
+ if (!encryptedParams)
29
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
30
+ const serviceURL = utils.makeURL(baseURL, {
31
+ zpw_ver: ctx.API_VERSION,
32
+ zpw_type: ctx.API_TYPE,
33
+ params: encryptedParams,
34
+ nretry: 0,
35
+ }, false);
36
+ const response = await utils.request(serviceURL, {
37
+ method: "GET",
38
+ });
39
+ return utils.resolve(response);
40
+ };
41
+ });
42
+
43
+ exports.pullMobileFactory = pullMobileFactory;
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const removeReminderFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const removeUnreadMarkFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -1,31 +1,45 @@
1
1
  'use strict';
2
2
 
3
- var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
3
  var utils = require('../utils.cjs');
5
4
 
6
- const requestSyncFromPhoneFactory = utils.apiFactory()((api, ctx) => {
5
+ const requestSyncFromPhoneFactory = utils.apiFactory()((api) => {
7
6
  /**
8
- * Gửi tín hiệu kích hoạt yêu cầu đồng bộ tin nhắn từ xa sang app điện thoại (Trường hợp 2)
7
+ * Phát tín hiệu yêu cầu đồng bộ tin nhắn từ ứng dụng Zalo trên điện thoại (`pull_mobile_msg`, command `12000`).
9
8
  *
9
+ * Tự động sinh cặp khoá RSA 2048-bit (nếu chưa truyền vào) và gọi `api.pullMobile(...)`.
10
+ * Điện thoại của người dùng sẽ hiển thị thông báo yêu cầu xác nhận đồng bộ (hoặc tự động đồng bộ nếu có `tempKey` từ `transfer_after_login`).
11
+ * Lắng nghe sự kiện `api.listener.on("sync_event", ...)` để nhận tiến trình xác nhận (`user_confirm`) và thông tin file sao lưu (`syncmsg_info`).
12
+ *
13
+ * @param options Tuỳ chọn đồng bộ (`pcName`, `tempKey`, hoặc cặp khoá RSA tự quản lý)
10
14
  * @throws {ZaloApiError}
11
15
  */
12
- return async function requestSyncFromPhone() {
13
- if (!api.listener) {
14
- throw new ZaloApiError.ZaloApiError("WebSocket listener is not initialized. Please call api.listener.start() first.");
15
- }
16
- // Gửi frame yêu cầu đồng bộ qua WebSocket
17
- const syncPayload = {
18
- version: 1,
19
- cmd: 510,
20
- subCmd: 0,
21
- data: {
22
- act: "sync_request",
23
- imei: ctx.imei,
24
- ts: Date.now(),
25
- },
16
+ return async function requestSyncFromPhone(options = {}) {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ const generated = options.publicKeyBase64 && options.privateKey
19
+ ? {
20
+ publicKeyBase64: options.publicKeyBase64,
21
+ privateKeyBase64: (_a = options.privateKeyBase64) !== null && _a !== void 0 ? _a : "",
22
+ publicKey: (_b = options.publicKey) !== null && _b !== void 0 ? _b : options.publicKeyBase64,
23
+ privateKey: options.privateKey,
24
+ }
25
+ : utils.generateRSAKeyPair();
26
+ const pcName = (_c = options.pcName) !== null && _c !== void 0 ? _c : "Web";
27
+ await api.pullMobile({
28
+ pc_name: pcName,
29
+ public_key: generated.publicKeyBase64,
30
+ from_seq_id: (_d = options.fromSeqId) !== null && _d !== void 0 ? _d : 0,
31
+ is_retry: (_e = options.isRetry) !== null && _e !== void 0 ? _e : 0,
32
+ min_seq_id: (_f = options.minSeqId) !== null && _f !== void 0 ? _f : 0,
33
+ temp_key: (_g = options.tempKey) !== null && _g !== void 0 ? _g : "",
34
+ });
35
+ return {
36
+ success: true,
37
+ pcName,
38
+ publicKeyBase64: generated.publicKeyBase64,
39
+ privateKeyBase64: generated.privateKeyBase64,
40
+ publicKey: generated.publicKey,
41
+ privateKey: generated.privateKey,
26
42
  };
27
- api.listener.sendWs(syncPayload, true);
28
- return { success: true };
29
43
  };
30
44
  });
31
45
 
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendBankCardFactory = utils.apiFactory()((api, _, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendCardFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -12,6 +12,8 @@ require('../models/GroupEvent.cjs');
12
12
  require('../models/Reaction.cjs');
13
13
  require('../models/Reminder.cjs');
14
14
  require('../models/ZBusiness.cjs');
15
+ require('../models/SyncEvent.cjs');
16
+ require('../models/CallEvent.cjs');
15
17
  var utils = require('../utils.cjs');
16
18
 
17
19
  const sendDeliveredEventFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendLinkFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -13,6 +13,8 @@ require('../models/GroupEvent.cjs');
13
13
  require('../models/Reaction.cjs');
14
14
  require('../models/Reminder.cjs');
15
15
  require('../models/ZBusiness.cjs');
16
+ require('../models/SyncEvent.cjs');
17
+ require('../models/CallEvent.cjs');
16
18
  var utils = require('../utils.cjs');
17
19
 
18
20
  const attachmentUrlType = {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  exports.ReportReason = void 0;
@@ -12,6 +12,8 @@ require('../models/GroupEvent.cjs');
12
12
  require('../models/Reaction.cjs');
13
13
  require('../models/Reminder.cjs');
14
14
  require('../models/ZBusiness.cjs');
15
+ require('../models/SyncEvent.cjs');
16
+ require('../models/CallEvent.cjs');
15
17
  var utils = require('../utils.cjs');
16
18
 
17
19
  const sendSeenEventFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendStickerFactory = utils.apiFactory()((api, ctx, utils$1) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendTypingEventFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendVideoFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const sendVoiceFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ exports.CallType = void 0;
7
+ (function (CallType) {
8
+ CallType[CallType["Audio"] = 1] = "Audio";
9
+ CallType[CallType["Video"] = 2] = "Video";
10
+ })(exports.CallType || (exports.CallType = {}));
11
+ function parseServerEndpoint(addr) {
12
+ if (!addr)
13
+ return { host: "", ip: "0.0.0.0", port: 0 };
14
+ const idx = addr.lastIndexOf(":");
15
+ if (idx === -1)
16
+ return { host: addr, ip: addr, port: 0 };
17
+ const ip = addr.slice(0, idx);
18
+ const port = Number.parseInt(addr.slice(idx + 1), 10) || 0;
19
+ return { host: addr, ip, port };
20
+ }
21
+ const sendVoiceCallFactory = utils.apiFactory()((api, ctx, utils$1) => {
22
+ var _a;
23
+ const voiceCallService = (_a = api.zpwServiceMap.voice_call) === null || _a === void 0 ? void 0 : _a[0];
24
+ /**
25
+ * Khởi tạo cuộc gọi thoại / video (Signaling 2 bước: `/api/voicecall/requestcall` command `11300`
26
+ * + `/api/voicecall/request` command `11301`) giúp đổ chuông trực tiếp trên thiết bị của người nhận.
27
+ *
28
+ * @param calleeId User ID của người nhận cuộc gọi
29
+ * @param options Tuỳ chọn loại cuộc gọi (`CallType.Audio` hoặc `CallType.Video`) và `callId`
30
+ * @throws {ZaloApiError}
31
+ */
32
+ return async function sendVoiceCall(calleeId, options = {}) {
33
+ var _a, _b, _c, _d, _e, _f, _g;
34
+ if (!calleeId)
35
+ throw new ZaloApiError.ZaloApiError("Missing calleeId");
36
+ if (!voiceCallService)
37
+ throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
38
+ const callType = (_a = options.callType) !== null && _a !== void 0 ? _a : exports.CallType.Audio;
39
+ const callId = (_b = options.callId) !== null && _b !== void 0 ? _b : Math.floor(Math.random() * 2000000000);
40
+ const codec = (_c = options.codec) !== null && _c !== void 0 ? _c : "[]";
41
+ const numericCalleeId = Number.isNaN(Number(calleeId)) ? calleeId : Number(calleeId);
42
+ // Step 1: Allocate call session & RTP/RTCP relay endpoints (/api/voicecall/requestcall, command 11300)
43
+ const step1Params = {
44
+ calleeId: numericCalleeId,
45
+ callId,
46
+ codec,
47
+ typeRequest: callType,
48
+ imei: ctx.imei,
49
+ };
50
+ const encryptedStep1 = utils$1.encodeAES(JSON.stringify(step1Params));
51
+ if (!encryptedStep1)
52
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt requestcall params");
53
+ const requestCallURL = utils$1.makeURL(`${voiceCallService}/api/voicecall/requestcall`, {
54
+ zpw_type: 24,
55
+ params: encryptedStep1,
56
+ });
57
+ const step1Res = await utils$1.request(requestCallURL, {
58
+ method: "GET",
59
+ });
60
+ const serverInfo = await utils.resolveResponse(ctx, step1Res, (result) => {
61
+ const raw = result.data;
62
+ return typeof raw === "string" ? JSON.parse(raw) : raw;
63
+ });
64
+ const rtp = parseServerEndpoint(serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.rtpServer);
65
+ const rtcp = parseServerEndpoint(serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.rtcpServer);
66
+ const sessId = (_d = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.sessId) !== null && _d !== void 0 ? _d : `${numericCalleeId}_${callId}_401`;
67
+ const resolvedCodec = (_e = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.codec) !== null && _e !== void 0 ? _e : codec;
68
+ // Step 2: Send ringing signaling request (/api/voicecall/request, command 11301)
69
+ const extendData = JSON.stringify({
70
+ rtcpDiff: 0,
71
+ rtcp: [{ ip: rtcp.ip, port: rtcp.port }],
72
+ rtp: [{ ip: rtp.ip, port: rtp.port }],
73
+ status: 0,
74
+ });
75
+ const step2Params = {
76
+ calleeId: numericCalleeId,
77
+ rtcpAddress: rtcp.host,
78
+ rtpAddress: rtp.host,
79
+ codec: resolvedCodec,
80
+ session: sessId,
81
+ callId,
82
+ imei: ctx.imei,
83
+ subCommand: 3,
84
+ extendData,
85
+ };
86
+ const encryptedStep2 = utils$1.encodeAES(JSON.stringify(step2Params));
87
+ if (!encryptedStep2)
88
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt voicecall request params");
89
+ const requestURL = utils$1.makeURL(`${voiceCallService}/api/voicecall/request`, {
90
+ zpw_type: 24,
91
+ params: encryptedStep2,
92
+ });
93
+ const step2Res = await utils$1.request(requestURL, {
94
+ method: "GET",
95
+ });
96
+ const requestResult = await utils$1.resolve(step2Res);
97
+ return {
98
+ callId,
99
+ sessId,
100
+ rtpServer: (_f = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.rtpServer) !== null && _f !== void 0 ? _f : "",
101
+ rtcpServer: (_g = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.rtcpServer) !== null && _g !== void 0 ? _g : "",
102
+ zrtpKey: serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.zrtpKey,
103
+ expiredTime: serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.expiredTime,
104
+ codec: resolvedCodec,
105
+ requestResult,
106
+ };
107
+ };
108
+ });
109
+
110
+ exports.sendVoiceCallFactory = sendVoiceCallFactory;
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const setHiddenConversationsFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  exports.MuteDuration = void 0;
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const setPinnedConversationsFactory = utils.apiFactory()((api, _, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  const undoFactory = utils.apiFactory()((api, ctx, utils) => {
@@ -11,6 +11,8 @@ require('../models/GroupEvent.cjs');
11
11
  require('../models/Reaction.cjs');
12
12
  require('../models/Reminder.cjs');
13
13
  require('../models/ZBusiness.cjs');
14
+ require('../models/SyncEvent.cjs');
15
+ require('../models/CallEvent.cjs');
14
16
  var utils = require('../utils.cjs');
15
17
 
16
18
  exports.ChatTTL = void 0;
@@ -13,6 +13,8 @@ require('../models/GroupEvent.cjs');
13
13
  require('../models/Reaction.cjs');
14
14
  require('../models/Reminder.cjs');
15
15
  require('../models/ZBusiness.cjs');
16
+ require('../models/SyncEvent.cjs');
17
+ require('../models/CallEvent.cjs');
16
18
  var utils = require('../utils.cjs');
17
19
 
18
20
  const urlType = {
@@ -171,9 +173,14 @@ const uploadAttachmentFactory = utils.apiFactory()((api, ctx, utils$1) => {
171
173
  */
172
174
  const resData = await utils.resolveResponse(ctx, response);
173
175
  if (resData && resData.fileId != "-1" && resData.photoId != "-1")
174
- await new Promise((resolve) => {
176
+ await new Promise((resolve, reject) => {
175
177
  if (data.fileType == "video" || data.fileType == "others") {
178
+ const timeoutId = setTimeout(() => {
179
+ ctx.uploadCallbacks.delete(resData.fileId.toString());
180
+ reject(new ZaloApiError.ZaloApiError("Upload attachment timed out after 5 minutes"));
181
+ }, 5 * 60 * 1000);
176
182
  const uploadCallback = async (wsData) => {
183
+ clearTimeout(timeoutId);
177
184
  const result = Object.assign(Object.assign(Object.assign({ fileType: data.fileType }, resData), wsData), { totalSize: data.fileData.totalSize, fileName: data.fileData.fileName, checksum: (await utils.getMd5LargeFileObject(data.source, data.fileData.totalSize)).data });
178
185
  results[atmIndex] = result;
179
186
  resolve();
package/dist/cjs/apis.cjs CHANGED
@@ -11,6 +11,8 @@ var addUnreadMark = require('./apis/addUnreadMark.cjs');
11
11
  var addUserToGroup = require('./apis/addUserToGroup.cjs');
12
12
  var blockUser = require('./apis/blockUser.cjs');
13
13
  var blockViewFeed = require('./apis/blockViewFeed.cjs');
14
+ var cancelPullMobile = require('./apis/cancelPullMobile.cjs');
15
+ var cancelVoiceCall = require('./apis/cancelVoiceCall.cjs');
14
16
  var changeAccountAvatar = require('./apis/changeAccountAvatar.cjs');
15
17
  var changeFriendAlias = require('./apis/changeFriendAlias.cjs');
16
18
  var changeGroupAvatar = require('./apis/changeGroupAvatar.cjs');
@@ -39,6 +41,7 @@ var downloadTransferSync = require('./apis/downloadTransferSync.cjs');
39
41
  var editNote = require('./apis/editNote.cjs');
40
42
  var editReminder = require('./apis/editReminder.cjs');
41
43
  var enableGroupLink = require('./apis/enableGroupLink.cjs');
44
+ var endVoiceCall = require('./apis/endVoiceCall.cjs');
42
45
  var fetchAccountInfo = require('./apis/fetchAccountInfo.cjs');
43
46
  var findUser = require('./apis/findUser.cjs');
44
47
  var findUserByUsername = require('./apis/findUserByUsername.cjs');
@@ -78,6 +81,7 @@ var getListDevice = require('./apis/getListDevice.cjs');
78
81
  var getListReminder = require('./apis/getListReminder.cjs');
79
82
  var getMultiUsersByPhones = require('./apis/getMultiUsersByPhones.cjs');
80
83
  var getMute = require('./apis/getMute.cjs');
84
+ var getNoisedIds = require('./apis/getNoisedIds.cjs');
81
85
  var getOwnId = require('./apis/getOwnId.cjs');
82
86
  var getPendingGroupMembers = require('./apis/getPendingGroupMembers.cjs');
83
87
  var getPinConversations = require('./apis/getPinConversations.cjs');
@@ -93,6 +97,7 @@ var getSettings = require('./apis/getSettings.cjs');
93
97
  var getStickerCategoryDetail = require('./apis/getStickerCategoryDetail.cjs');
94
98
  var getStickers = require('./apis/getStickers.cjs');
95
99
  var getStickersDetail = require('./apis/getStickersDetail.cjs');
100
+ var getSyncData = require('./apis/getSyncData.cjs');
96
101
  var getUnreadMark = require('./apis/getUnreadMark.cjs');
97
102
  var getUserInfo = require('./apis/getUserInfo.cjs');
98
103
  var inviteUserToGroups = require('./apis/inviteUserToGroups.cjs');
@@ -105,6 +110,7 @@ var lockPoll = require('./apis/lockPoll.cjs');
105
110
  var lostFocus = require('./apis/lostFocus.cjs');
106
111
  var parseLink = require('./apis/parseLink.cjs');
107
112
  var preloadConversations = require('./apis/preloadConversations.cjs');
113
+ var pullMobile = require('./apis/pullMobile.cjs');
108
114
  var registerCatalog = require('./apis/registerCatalog.cjs');
109
115
  var rejectFriendRequest = require('./apis/rejectFriendRequest.cjs');
110
116
  var removeFriend = require('./apis/removeFriend.cjs');
@@ -133,6 +139,7 @@ var sendSticker = require('./apis/sendSticker.cjs');
133
139
  var sendTypingEvent = require('./apis/sendTypingEvent.cjs');
134
140
  var sendVideo = require('./apis/sendVideo.cjs');
135
141
  var sendVoice = require('./apis/sendVoice.cjs');
142
+ var sendVoiceCall = require('./apis/sendVoiceCall.cjs');
136
143
  var setHiddenConversations = require('./apis/setHiddenConversations.cjs');
137
144
  var setMute = require('./apis/setMute.cjs');
138
145
  var setPinnedConversations = require('./apis/setPinnedConversations.cjs');
@@ -175,6 +182,8 @@ class API {
175
182
  this.addUserToGroup = addUserToGroup.addUserToGroupFactory(ctx, this);
176
183
  this.blockUser = blockUser.blockUserFactory(ctx, this);
177
184
  this.blockViewFeed = blockViewFeed.blockViewFeedFactory(ctx, this);
185
+ this.cancelPullMobile = cancelPullMobile.cancelPullMobileFactory(ctx, this);
186
+ this.cancelVoiceCall = cancelVoiceCall.cancelVoiceCallFactory(ctx, this);
178
187
  this.changeAccountAvatar = changeAccountAvatar.changeAccountAvatarFactory(ctx, this);
179
188
  this.changeFriendAlias = changeFriendAlias.changeFriendAliasFactory(ctx, this);
180
189
  this.changeGroupAvatar = changeGroupAvatar.changeGroupAvatarFactory(ctx, this);
@@ -203,6 +212,7 @@ class API {
203
212
  this.editNote = editNote.editNoteFactory(ctx, this);
204
213
  this.editReminder = editReminder.editReminderFactory(ctx, this);
205
214
  this.enableGroupLink = enableGroupLink.enableGroupLinkFactory(ctx, this);
215
+ this.endVoiceCall = endVoiceCall.endVoiceCallFactory(ctx, this);
206
216
  this.fetchAccountInfo = fetchAccountInfo.fetchAccountInfoFactory(ctx, this);
207
217
  this.findUser = findUser.findUserFactory(ctx, this);
208
218
  this.findUserByUsername = findUserByUsername.findUserByUsernameFactory(ctx, this);
@@ -242,6 +252,7 @@ class API {
242
252
  this.getListReminder = getListReminder.getListReminderFactory(ctx, this);
243
253
  this.getMultiUsersByPhones = getMultiUsersByPhones.getMultiUsersByPhonesFactory(ctx, this);
244
254
  this.getMute = getMute.getMuteFactory(ctx, this);
255
+ this.getNoisedIds = getNoisedIds.getNoisedIdsFactory(ctx, this);
245
256
  this.getOwnId = getOwnId.getOwnIdFactory(ctx, this);
246
257
  this.getPendingGroupMembers = getPendingGroupMembers.getPendingGroupMembersFactory(ctx, this);
247
258
  this.getPinConversations = getPinConversations.getPinConversationsFactory(ctx, this);
@@ -257,6 +268,7 @@ class API {
257
268
  this.getStickerCategoryDetail = getStickerCategoryDetail.getStickerCategoryDetailFactory(ctx, this);
258
269
  this.getStickers = getStickers.getStickersFactory(ctx, this);
259
270
  this.getStickersDetail = getStickersDetail.getStickersDetailFactory(ctx, this);
271
+ this.getSyncData = getSyncData.getSyncDataFactory(ctx, this);
260
272
  this.getUnreadMark = getUnreadMark.getUnreadMarkFactory(ctx, this);
261
273
  this.getUserInfo = getUserInfo.getUserInfoFactory(ctx, this);
262
274
  this.inviteUserToGroups = inviteUserToGroups.inviteUserToGroupsFactory(ctx, this);
@@ -269,6 +281,7 @@ class API {
269
281
  this.lostFocus = lostFocus.lostFocusFactory(ctx, this);
270
282
  this.parseLink = parseLink.parseLinkFactory(ctx, this);
271
283
  this.preloadConversations = preloadConversations.preloadConversationsFactory(ctx, this);
284
+ this.pullMobile = pullMobile.pullMobileFactory(ctx, this);
272
285
  this.registerCatalog = registerCatalog.registerCatalogFactory(ctx, this);
273
286
  this.rejectFriendRequest = rejectFriendRequest.rejectFriendRequestFactory(ctx, this);
274
287
  this.removeFriend = removeFriend.removeFriendFactory(ctx, this);
@@ -297,6 +310,7 @@ class API {
297
310
  this.sendTypingEvent = sendTypingEvent.sendTypingEventFactory(ctx, this);
298
311
  this.sendVideo = sendVideo.sendVideoFactory(ctx, this);
299
312
  this.sendVoice = sendVoice.sendVoiceFactory(ctx, this);
313
+ this.sendVoiceCall = sendVoiceCall.sendVoiceCallFactory(ctx, this);
300
314
  this.setHiddenConversations = setHiddenConversations.setHiddenConversationsFactory(ctx, this);
301
315
  this.setMute = setMute.setMuteFactory(ctx, this);
302
316
  this.setPinnedConversations = setPinnedConversations.setPinnedConversationsFactory(ctx, this);