zalo-toolkit 1.0.0 → 1.0.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 (155) hide show
  1. package/dist/apis/sendMessage.d.ts +5 -0
  2. package/dist/apis/sendMessage.js +31 -11
  3. package/dist/cjs/apis/acceptFriendRequest.cjs +33 -0
  4. package/dist/cjs/apis/addGroupBlockedMember.cjs +33 -0
  5. package/dist/cjs/apis/addGroupDeputy.cjs +36 -0
  6. package/dist/cjs/apis/addPollOptions.cjs +31 -0
  7. package/dist/cjs/apis/addQuickMessage.cjs +65 -0
  8. package/dist/cjs/apis/addReaction.cjs +297 -0
  9. package/dist/cjs/apis/addUnreadMark.cjs +65 -0
  10. package/dist/cjs/apis/addUserToGroup.cjs +39 -0
  11. package/dist/cjs/apis/blockUser.cjs +33 -0
  12. package/dist/cjs/apis/blockViewFeed.cjs +35 -0
  13. package/dist/cjs/apis/changeAccountAvatar.cjs +56 -0
  14. package/dist/cjs/apis/changeFriendAlias.cjs +32 -0
  15. package/dist/cjs/apis/changeGroupAvatar.cjs +47 -0
  16. package/dist/cjs/apis/changeGroupName.cjs +37 -0
  17. package/dist/cjs/apis/changeGroupOwner.cjs +36 -0
  18. package/dist/cjs/apis/createAutoReply.cjs +42 -0
  19. package/dist/cjs/apis/createCatalog.cjs +34 -0
  20. package/dist/cjs/apis/createGroup.cjs +48 -0
  21. package/dist/cjs/apis/createNote.cjs +52 -0
  22. package/dist/cjs/apis/createPoll.cjs +45 -0
  23. package/dist/cjs/apis/createProductCatalog.cjs +55 -0
  24. package/dist/cjs/apis/createReminder.cjs +76 -0
  25. package/dist/cjs/apis/custom.cjs +19 -0
  26. package/dist/cjs/apis/deleteAutoReply.cjs +34 -0
  27. package/dist/cjs/apis/deleteAvatar.cjs +32 -0
  28. package/dist/cjs/apis/deleteCatalog.cjs +33 -0
  29. package/dist/cjs/apis/deleteChat.cjs +63 -0
  30. package/dist/cjs/apis/deleteGroupInviteBox.cjs +32 -0
  31. package/dist/cjs/apis/deleteMessage.cjs +65 -0
  32. package/dist/cjs/apis/deleteProductCatalog.cjs +36 -0
  33. package/dist/cjs/apis/disableGroupLink.cjs +29 -0
  34. package/dist/cjs/apis/disperseGroup.cjs +33 -0
  35. package/dist/cjs/apis/editNote.cjs +51 -0
  36. package/dist/cjs/apis/editReminder.cjs +74 -0
  37. package/dist/cjs/apis/enableGroupLink.cjs +30 -0
  38. package/dist/cjs/apis/fetchAccountInfo.cjs +15 -0
  39. package/dist/cjs/apis/findUser.cjs +45 -0
  40. package/dist/cjs/apis/forwardAttachment.cjs +85 -0
  41. package/dist/cjs/apis/forwardMessage.cjs +122 -0
  42. package/dist/cjs/apis/getAliasList.cjs +33 -0
  43. package/dist/cjs/apis/getAllFriends.cjs +37 -0
  44. package/dist/cjs/apis/getAllGroups.cjs +15 -0
  45. package/dist/cjs/apis/getArchivedChatList.cjs +28 -0
  46. package/dist/cjs/apis/getAutoDeleteChat.cjs +26 -0
  47. package/dist/cjs/apis/getAutoReplyList.cjs +29 -0
  48. package/dist/cjs/apis/getAvatarList.cjs +33 -0
  49. package/dist/cjs/apis/getBizAccount.cjs +32 -0
  50. package/dist/cjs/apis/getCatalogList.cjs +37 -0
  51. package/dist/cjs/apis/getContext.cjs +9 -0
  52. package/dist/cjs/apis/getCookie.cjs +14 -0
  53. package/dist/cjs/apis/getFriendBoardList.cjs +31 -0
  54. package/dist/cjs/apis/getFriendOnlines.cjs +40 -0
  55. package/dist/cjs/apis/getFriendRecommendations.cjs +32 -0
  56. package/dist/cjs/apis/getFriendRequestStatus.cjs +30 -0
  57. package/dist/cjs/apis/getGroupBlockedMember.cjs +34 -0
  58. package/dist/cjs/apis/getGroupInfo.cjs +37 -0
  59. package/dist/cjs/apis/getGroupInviteBoxInfo.cjs +43 -0
  60. package/dist/cjs/apis/getGroupInviteBoxList.cjs +36 -0
  61. package/dist/cjs/apis/getGroupLinkDetail.cjs +30 -0
  62. package/dist/cjs/apis/getGroupLinkInfo.cjs +33 -0
  63. package/dist/cjs/apis/getGroupMembersInfo.cjs +29 -0
  64. package/dist/cjs/apis/getHiddenConversations.cjs +28 -0
  65. package/dist/cjs/apis/getLabels.cjs +33 -0
  66. package/dist/cjs/apis/getLastMessage.cjs +25 -0
  67. package/dist/cjs/apis/getListBoard.cjs +58 -0
  68. package/dist/cjs/apis/getListReminder.cjs +60 -0
  69. package/dist/cjs/apis/getMute.cjs +27 -0
  70. package/dist/cjs/apis/getOwnId.cjs +9 -0
  71. package/dist/cjs/apis/getPendingGroupMembers.cjs +32 -0
  72. package/dist/cjs/apis/getPinConversations.cjs +27 -0
  73. package/dist/cjs/apis/getPollDetail.cjs +35 -0
  74. package/dist/cjs/apis/getProductCatalogList.cjs +38 -0
  75. package/dist/cjs/apis/getQR.cjs +34 -0
  76. package/dist/cjs/apis/getQuickMessageList.cjs +29 -0
  77. package/dist/cjs/apis/getRecommendFriends.cjs +25 -0
  78. package/dist/cjs/apis/getRelatedFriendGroup.cjs +35 -0
  79. package/dist/cjs/apis/getReminder.cjs +30 -0
  80. package/dist/cjs/apis/getReminderResponses.cjs +29 -0
  81. package/dist/cjs/apis/getSentFriendRequest.cjs +29 -0
  82. package/dist/cjs/apis/getSettings.cjs +25 -0
  83. package/dist/cjs/apis/getStickers.cjs +45 -0
  84. package/dist/cjs/apis/getStickersDetail.cjs +45 -0
  85. package/dist/cjs/apis/getUnreadMark.cjs +35 -0
  86. package/dist/cjs/apis/getUserInfo.cjs +47 -0
  87. package/dist/cjs/apis/inviteUserToGroups.cjs +35 -0
  88. package/dist/cjs/apis/joinGroupInviteBox.cjs +30 -0
  89. package/dist/cjs/apis/joinGroupLink.cjs +32 -0
  90. package/dist/cjs/apis/keepAlive.cjs +27 -0
  91. package/dist/cjs/apis/lastOnline.cjs +31 -0
  92. package/dist/cjs/apis/leaveGroup.cjs +38 -0
  93. package/dist/cjs/apis/lockPoll.cjs +33 -0
  94. package/dist/cjs/apis/parseLink.cjs +32 -0
  95. package/dist/cjs/apis/rejectFriendRequest.cjs +32 -0
  96. package/dist/cjs/apis/removeFriend.cjs +33 -0
  97. package/dist/cjs/apis/removeFriendAlias.cjs +29 -0
  98. package/dist/cjs/apis/removeGroupBlockedMember.cjs +33 -0
  99. package/dist/cjs/apis/removeGroupDeputy.cjs +35 -0
  100. package/dist/cjs/apis/removeQuickMessage.cjs +32 -0
  101. package/dist/cjs/apis/removeReminder.cjs +53 -0
  102. package/dist/cjs/apis/removeUnreadMark.cjs +63 -0
  103. package/dist/cjs/apis/removeUserFromGroup.cjs +39 -0
  104. package/dist/cjs/apis/resetHiddenConversPin.cjs +25 -0
  105. package/dist/cjs/apis/reuseAvatar.cjs +31 -0
  106. package/dist/cjs/apis/reviewPendingMemberRequest.cjs +33 -11
  107. package/dist/cjs/apis/sendBankCard.cjs +50 -0
  108. package/dist/cjs/apis/sendCard.cjs +72 -0
  109. package/dist/cjs/apis/sendDeliveredEvent.cjs +68 -0
  110. package/dist/cjs/apis/sendFriendRequest.cjs +44 -0
  111. package/dist/cjs/apis/sendLink.cjs +70 -0
  112. package/dist/cjs/apis/sendMessage.cjs +437 -11
  113. package/dist/cjs/apis/sendReport.cjs +48 -10
  114. package/dist/cjs/apis/sendSeenEvent.cjs +76 -0
  115. package/dist/cjs/apis/sendSticker.cjs +69 -0
  116. package/dist/cjs/apis/sendTypingEvent.cjs +46 -0
  117. package/dist/cjs/apis/sendVideo.cjs +131 -0
  118. package/dist/cjs/apis/sendVoice.cjs +86 -0
  119. package/dist/cjs/apis/setArchivedConversations.cjs +39 -0
  120. package/dist/cjs/apis/setHiddenConversations.cjs +52 -0
  121. package/dist/cjs/apis/setMute.cjs +57 -10
  122. package/dist/cjs/apis/setPinnedConversations.cjs +47 -0
  123. package/dist/cjs/apis/sharePoll.cjs +33 -0
  124. package/dist/cjs/apis/unblockUser.cjs +33 -0
  125. package/dist/cjs/apis/undo.cjs +55 -0
  126. package/dist/cjs/apis/undoFriendRequest.cjs +32 -0
  127. package/dist/cjs/apis/updateActiveStatus.cjs +32 -0
  128. package/dist/cjs/apis/updateAutoDeleteChat.cjs +35 -10
  129. package/dist/cjs/apis/updateAutoReply.cjs +43 -0
  130. package/dist/cjs/apis/updateCatalog.cjs +35 -0
  131. package/dist/cjs/apis/updateGroupSettings.cjs +48 -0
  132. package/dist/cjs/apis/updateHiddenConversPin.cjs +35 -0
  133. package/dist/cjs/apis/updateLabels.cjs +39 -0
  134. package/dist/cjs/apis/updateLang.cjs +27 -11
  135. package/dist/cjs/apis/updateProductCatalog.cjs +56 -0
  136. package/dist/cjs/apis/updateProfile.cjs +48 -0
  137. package/dist/cjs/apis/updateQuickMessage.cjs +66 -0
  138. package/dist/cjs/apis/updateSettings.cjs +77 -11
  139. package/dist/cjs/apis/uploadAttachment.cjs +208 -0
  140. package/dist/cjs/apis/uploadProductPhoto.cjs +50 -0
  141. package/dist/cjs/apis/votePoll.cjs +34 -0
  142. package/dist/cjs/apis.cjs +292 -0
  143. package/dist/cjs/context.cjs +15 -0
  144. package/dist/cjs/core/enums/common.cjs +14 -0
  145. package/dist/cjs/core/utils/index.cjs +33 -0
  146. package/dist/cjs/models/GroupEvent.cjs +2 -4
  147. package/dist/cjs/utils.cjs +229 -3
  148. package/dist/cjs/zalo.cjs +18 -7
  149. package/dist/index.d.ts +1 -0
  150. package/dist/models/GroupEvent.d.ts +2 -2
  151. package/dist/models/GroupEvent.js +2 -4
  152. package/dist/models/Message.d.ts +6 -0
  153. package/dist/zalo.d.ts +17 -10
  154. package/dist/zalo.js +19 -8
  155. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const deleteAutoReplyFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.auto_reply[0]}/api/autoreply/delete`);
8
+ /**
9
+ * Delete auto reply
10
+ *
11
+ * @param id id of auto reply
12
+ *
13
+ * @note this API used for zBusiness
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function deleteAutoReply(id) {
17
+ const params = {
18
+ cliLang: ctx.language,
19
+ id: id,
20
+ };
21
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
22
+ if (!encryptedParams)
23
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
24
+ const response = await utils.request(serviceURL, {
25
+ method: 'POST',
26
+ body: new URLSearchParams({
27
+ params: encryptedParams,
28
+ }),
29
+ });
30
+ return utils.resolve(response);
31
+ };
32
+ });
33
+
34
+ exports.deleteAutoReplyFactory = deleteAutoReplyFactory;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const deleteAvatarFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/del-avatars`);
8
+ /**
9
+ * Delete avatar from avatar list
10
+ *
11
+ * @param photoId avatar photo ID(s) to delete - can be a single string or array of strings
12
+ *
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function deleteAvatar(photoId) {
16
+ const photoIds = Array.isArray(photoId) ? photoId : [photoId];
17
+ const delPhotos = photoIds.map((id) => ({ photoId: id }));
18
+ const params = {
19
+ delPhotos: JSON.stringify(delPhotos),
20
+ imei: ctx.imei,
21
+ };
22
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
23
+ if (!encryptedParams)
24
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
25
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
26
+ method: 'GET',
27
+ });
28
+ return utils.resolve(response);
29
+ };
30
+ });
31
+
32
+ exports.deleteAvatarFactory = deleteAvatarFactory;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const deleteCatalogFactory = utils.apiFactory()((api, _, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/catalog/delete`);
8
+ /**
9
+ * Delete catalog?
10
+ *
11
+ * @param catalogId catalog id
12
+ *
13
+ * @note this API is used for zBusiness
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function deleteCatalog(catalogId) {
17
+ const params = {
18
+ catalog_id: catalogId,
19
+ };
20
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
21
+ if (!encryptedParams)
22
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
23
+ const response = await utils.request(serviceURL, {
24
+ method: 'POST',
25
+ body: new URLSearchParams({
26
+ params: encryptedParams,
27
+ }),
28
+ });
29
+ return utils.resolve(response);
30
+ };
31
+ });
32
+
33
+ exports.deleteCatalogFactory = deleteCatalogFactory;
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ require('../models/AutoReply.cjs');
5
+ require('../models/Board.cjs');
6
+ var Enum = require('../models/Enum.cjs');
7
+ require('../models/FriendEvent.cjs');
8
+ require('../models/Group.cjs');
9
+ require('../models/GroupEvent.cjs');
10
+ var utils = require('../utils.cjs');
11
+ require('../models/Reaction.cjs');
12
+ require('../models/Reminder.cjs');
13
+ require('../models/ZBusiness.cjs');
14
+
15
+ const deleteChatFactory = utils.apiFactory()((api, ctx, utils) => {
16
+ const serviceURL = {
17
+ [Enum.ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.chat[0]}/api/message/deleteconver`, {
18
+ nretry: 0,
19
+ }),
20
+ [Enum.ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/deleteconver`, {
21
+ nretry: 0,
22
+ }),
23
+ };
24
+ /**
25
+ * Delete chat
26
+ *
27
+ * @param lastMessage Last message info
28
+ * @param threadId Thread ID
29
+ * @param type Thread type
30
+ *
31
+ * @throws {ZaloApiError}
32
+ */
33
+ return async function deleteChat(lastMessage, threadId, type = Enum.ThreadType.User) {
34
+ const timestampString = Date.now().toString();
35
+ const params = type === Enum.ThreadType.User
36
+ ? {
37
+ toid: threadId,
38
+ cliMsgId: timestampString,
39
+ conver: lastMessage,
40
+ onlyMe: 1,
41
+ imei: ctx.imei,
42
+ }
43
+ : {
44
+ grid: threadId,
45
+ cliMsgId: timestampString,
46
+ conver: lastMessage,
47
+ onlyMe: 1,
48
+ imei: ctx.imei,
49
+ };
50
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
51
+ if (!encryptedParams)
52
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
53
+ const response = await utils.request(serviceURL[type], {
54
+ method: 'POST',
55
+ body: new URLSearchParams({
56
+ params: encryptedParams,
57
+ }),
58
+ });
59
+ return utils.resolve(response);
60
+ };
61
+ });
62
+
63
+ exports.deleteChatFactory = deleteChatFactory;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const deleteGroupInviteBoxFactory = utils.apiFactory()((api, _, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/inv-box/mdel-inv`);
8
+ /**
9
+ * Delete group invite box
10
+ *
11
+ * @param groupId - The group id
12
+ * @param blockFutureInvite - Whether to block future invites from this group
13
+ *
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function deleteGroupInviteBox(groupId, blockFutureInvite = false) {
17
+ const grids = Array.isArray(groupId) ? groupId : [groupId];
18
+ const params = {
19
+ invitations: JSON.stringify(grids.map((grid) => ({ grid }))),
20
+ block: blockFutureInvite ? 1 : 0,
21
+ };
22
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
23
+ if (!encryptedParams)
24
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
25
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
26
+ method: 'GET',
27
+ });
28
+ return utils.resolve(response);
29
+ };
30
+ });
31
+
32
+ exports.deleteGroupInviteBoxFactory = deleteGroupInviteBoxFactory;
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ require('../models/AutoReply.cjs');
5
+ require('../models/Board.cjs');
6
+ var Enum = require('../models/Enum.cjs');
7
+ require('../models/FriendEvent.cjs');
8
+ require('../models/Group.cjs');
9
+ require('../models/GroupEvent.cjs');
10
+ var utils = require('../utils.cjs');
11
+ require('../models/Reaction.cjs');
12
+ require('../models/Reminder.cjs');
13
+ require('../models/ZBusiness.cjs');
14
+
15
+ const deleteMessageFactory = utils.apiFactory()((api, ctx, utils) => {
16
+ const serviceURL = {
17
+ [Enum.ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.chat[0]}/api/message/delete`),
18
+ [Enum.ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/deletemsg`),
19
+ };
20
+ /**
21
+ * Delete a message
22
+ *
23
+ * @param dest Delete target
24
+ * @param onlyMe Delete message for only you
25
+ *
26
+ * @throws {ZaloApiError}
27
+ */
28
+ return async function deleteMessage(dest, onlyMe = false) {
29
+ const { threadId, type = Enum.ThreadType.User, data } = dest;
30
+ const isGroup = type === Enum.ThreadType.Group;
31
+ const isSelf = ctx.uid == data.uidFrom;
32
+ if (isSelf && onlyMe === false)
33
+ throw new ZaloApiError.ZaloApiError('To delete your message for everyone, use undo api instead');
34
+ if (!isGroup && onlyMe === false)
35
+ throw new ZaloApiError.ZaloApiError("Can't delete message for everyone in a private chat");
36
+ const params = {
37
+ [isGroup ? 'grid' : 'toid']: threadId,
38
+ cliMsgId: Date.now(),
39
+ msgs: [
40
+ {
41
+ cliMsgId: data.cliMsgId,
42
+ globalMsgId: data.msgId,
43
+ ownerId: data.uidFrom,
44
+ destId: threadId,
45
+ },
46
+ ],
47
+ onlyMe: onlyMe ? 1 : 0,
48
+ };
49
+ if (!isGroup) {
50
+ params.imei = ctx.imei;
51
+ }
52
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
53
+ if (!encryptedParams)
54
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt message');
55
+ const response = await utils.request(serviceURL[type], {
56
+ method: 'POST',
57
+ body: new URLSearchParams({
58
+ params: encryptedParams,
59
+ }),
60
+ });
61
+ return utils.resolve(response);
62
+ };
63
+ });
64
+
65
+ exports.deleteMessageFactory = deleteMessageFactory;
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const deleteProductCatalogFactory = utils.apiFactory()((api, _, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/product/mdelete`);
8
+ /**
9
+ * Delete product catalog?
10
+ *
11
+ * @param payload payload
12
+ *
13
+ * @note this API is used for zBusiness
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function deleteProductCatalog(payload) {
17
+ if (!Array.isArray(payload.productIds))
18
+ payload.productIds = [payload.productIds];
19
+ const params = {
20
+ product_ids: payload.productIds,
21
+ catalog_id: payload.catalogId,
22
+ };
23
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
24
+ if (!encryptedParams)
25
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
26
+ const response = await utils.request(serviceURL, {
27
+ method: "POST",
28
+ body: new URLSearchParams({
29
+ params: encryptedParams,
30
+ }),
31
+ });
32
+ return utils.resolve(response);
33
+ };
34
+ });
35
+
36
+ exports.deleteProductCatalogFactory = deleteProductCatalogFactory;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const disableGroupLinkFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/link/disable`);
8
+ /**
9
+ * Disable group link
10
+ *
11
+ * @param groupId The group id
12
+ *
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function disableGroupLink(groupId) {
16
+ const params = {
17
+ grid: groupId,
18
+ };
19
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
20
+ if (!encryptedParams)
21
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
22
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
23
+ method: "GET",
24
+ });
25
+ return utils.resolve(response);
26
+ };
27
+ });
28
+
29
+ exports.disableGroupLinkFactory = disableGroupLinkFactory;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const disperseGroupFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/disperse`);
8
+ /**
9
+ * Disperse Group
10
+ *
11
+ * @param groupId Group ID to disperse Group from
12
+ *
13
+ * @throws ZaloApiError
14
+ */
15
+ return async function disperseGroup(threadId) {
16
+ const params = {
17
+ grid: threadId,
18
+ imei: ctx.imei,
19
+ };
20
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
21
+ if (!encryptedParams)
22
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
23
+ const response = await utils.request(serviceURL, {
24
+ method: 'POST',
25
+ body: new URLSearchParams({
26
+ params: encryptedParams,
27
+ }),
28
+ });
29
+ return utils.resolve(response);
30
+ };
31
+ });
32
+
33
+ exports.disperseGroupFactory = disperseGroupFactory;
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const editNoteFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/updatev2`);
8
+ /**
9
+ * Edit an existing note in a group
10
+ *
11
+ * @param options Options for editing the note
12
+ * @param groupId Group ID to create note from
13
+ *
14
+ * @throws {ZaloApiError}
15
+ */
16
+ return async function editNote(options, groupId) {
17
+ const params = {
18
+ grid: groupId,
19
+ type: 0,
20
+ color: -16777216,
21
+ emoji: '',
22
+ startTime: -1,
23
+ duration: -1,
24
+ params: JSON.stringify({
25
+ title: options.title,
26
+ }),
27
+ topicId: options.topicId,
28
+ repeat: 0,
29
+ imei: ctx.imei,
30
+ pinAct: options.pinAct ? 1 : 2,
31
+ };
32
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
33
+ if (!encryptedParams)
34
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
35
+ const response = await utils.request(serviceURL, {
36
+ method: 'POST',
37
+ body: new URLSearchParams({
38
+ params: encryptedParams,
39
+ }),
40
+ });
41
+ return utils.resolve(response, (result) => {
42
+ const data = result.data;
43
+ if (typeof data.params == 'string') {
44
+ data.params = JSON.parse(data.params);
45
+ }
46
+ return data;
47
+ });
48
+ };
49
+ });
50
+
51
+ exports.editNoteFactory = editNoteFactory;
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ require('../models/AutoReply.cjs');
5
+ require('../models/Board.cjs');
6
+ var Enum = require('../models/Enum.cjs');
7
+ require('../models/FriendEvent.cjs');
8
+ require('../models/Group.cjs');
9
+ require('../models/GroupEvent.cjs');
10
+ var utils = require('../utils.cjs');
11
+ require('../models/Reaction.cjs');
12
+ require('../models/Reminder.cjs');
13
+ require('../models/ZBusiness.cjs');
14
+
15
+ const editReminderFactory = utils.apiFactory()((api, ctx, utils) => {
16
+ const serviceURL = {
17
+ [Enum.ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/oneone/update`),
18
+ [Enum.ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/updatev2`),
19
+ };
20
+ /**
21
+ * Edit an existing reminder
22
+ *
23
+ * @param options Reminder parameters
24
+ * @param threadId Thread ID
25
+ * @param type Thread type (User/Group)
26
+ *
27
+ * @throws {ZaloApiError}
28
+ */
29
+ return async function editReminder(options, threadId, type = Enum.ThreadType.User) {
30
+ var _a, _b, _c, _d, _e, _f;
31
+ const requestParams = type === Enum.ThreadType.User
32
+ ? {
33
+ objectData: JSON.stringify({
34
+ toUid: threadId,
35
+ type: 0,
36
+ color: -16777216,
37
+ emoji: (_a = options.emoji) !== null && _a !== void 0 ? _a : '',
38
+ startTime: (_b = options.startTime) !== null && _b !== void 0 ? _b : Date.now(),
39
+ duration: -1,
40
+ params: { title: options.title },
41
+ needPin: false,
42
+ reminderId: options.topicId,
43
+ repeat: (_c = options.repeat) !== null && _c !== void 0 ? _c : 0,
44
+ }),
45
+ }
46
+ : {
47
+ grid: threadId,
48
+ type: 0,
49
+ color: -16777216,
50
+ emoji: (_d = options.emoji) !== null && _d !== void 0 ? _d : '',
51
+ startTime: (_e = options.startTime) !== null && _e !== void 0 ? _e : Date.now(),
52
+ duration: -1,
53
+ params: JSON.stringify({
54
+ title: options.title,
55
+ }),
56
+ topicId: options.topicId,
57
+ repeat: (_f = options.repeat) !== null && _f !== void 0 ? _f : 0,
58
+ imei: ctx.imei,
59
+ pinAct: 2,
60
+ };
61
+ const encryptedParams = utils.encodeAES(JSON.stringify(requestParams));
62
+ if (!encryptedParams)
63
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
64
+ const response = await utils.request(serviceURL[type], {
65
+ method: 'POST',
66
+ body: new URLSearchParams({
67
+ params: encryptedParams,
68
+ }),
69
+ });
70
+ return utils.resolve(response);
71
+ };
72
+ });
73
+
74
+ exports.editReminderFactory = editReminderFactory;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const enableGroupLinkFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/link/new`);
8
+ /**
9
+ * Enable and create new group link
10
+ *
11
+ * @param groupId The group id
12
+ *
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function enableGroupLink(groupId) {
16
+ const params = {
17
+ grid: groupId,
18
+ imei: ctx.imei,
19
+ };
20
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
21
+ if (!encryptedParams)
22
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
23
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
24
+ method: 'GET',
25
+ });
26
+ return utils.resolve(response);
27
+ };
28
+ });
29
+
30
+ exports.enableGroupLinkFactory = enableGroupLinkFactory;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils.cjs');
4
+
5
+ const fetchAccountInfoFactory = utils.apiFactory()((api, _, utils) => {
6
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/profile/me-v2`);
7
+ return async function fetchAccountInfo() {
8
+ const response = await utils.request(serviceURL, {
9
+ method: 'GET',
10
+ });
11
+ return utils.resolve(response);
12
+ };
13
+ });
14
+
15
+ exports.fetchAccountInfoFactory = fetchAccountInfoFactory;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
4
+ var utils = require('../utils.cjs');
5
+
6
+ const findUserFactory = utils.apiFactory()((api, ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/profile/get`);
8
+ /**
9
+ * Find user by phone number
10
+ *
11
+ * @param phoneNumber Phone number
12
+ *
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function findUser(phoneNumber) {
16
+ if (!phoneNumber)
17
+ throw new ZaloApiError.ZaloApiError('Missing phoneNumber');
18
+ if (phoneNumber.startsWith('0')) {
19
+ if (ctx.language == 'vi')
20
+ phoneNumber = '84' + phoneNumber.slice(1);
21
+ }
22
+ const params = {
23
+ phone: phoneNumber,
24
+ avatar_size: 240,
25
+ language: ctx.language,
26
+ imei: ctx.imei,
27
+ reqSrc: 40,
28
+ };
29
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
30
+ if (!encryptedParams)
31
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt message');
32
+ const finalServiceUrl = new URL(serviceURL);
33
+ finalServiceUrl.searchParams.append('params', encryptedParams);
34
+ const response = await utils.request(utils.makeURL(finalServiceUrl.toString(), {
35
+ params: encryptedParams,
36
+ }));
37
+ return utils.resolve(response, (result) => {
38
+ if (result.error && result.error.code != 216)
39
+ throw new ZaloApiError.ZaloApiError(result.error.message, result.error.code);
40
+ return result.data;
41
+ });
42
+ };
43
+ });
44
+
45
+ exports.findUserFactory = findUserFactory;
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var common = require('../core/enums/common.cjs');
4
+ var index = require('../core/utils/index.cjs');
5
+ var ZaloApiError = require('../Errors/ZaloApiError.cjs');
6
+ var Enum = require('../models/Enum.cjs');
7
+ var utils = require('../utils.cjs');
8
+
9
+ const forwardAttachmentFactory = utils.apiFactory()((api, ctx, utils$1) => {
10
+ const serviceURL = {
11
+ [Enum.ThreadType.User]: utils$1.makeURL(`${api.zpwServiceMap.file[0]}/api/message/forward`),
12
+ [Enum.ThreadType.Group]: utils$1.makeURL(`${api.zpwServiceMap.file[0]}/api/group/forward`),
13
+ };
14
+ return async function forwardAttachment(options, threadId, type = Enum.ThreadType.User, messageType) {
15
+ var _a;
16
+ const timestamp = Date.now();
17
+ const fileAttachment = await index.getFileUpload(options.url);
18
+ const checksum = await utils.getMd5LargeFileObject(fileAttachment);
19
+ let params = {
20
+ clientId: String(timestamp),
21
+ ttl: 0,
22
+ zsource: 703,
23
+ imei: ctx.imei,
24
+ msgInfo: {
25
+ reference: JSON.stringify({
26
+ type: 3,
27
+ data: JSON.stringify({
28
+ ts: timestamp,
29
+ logSrcType: 1,
30
+ fwLvl: 1,
31
+ rootMsgRef: {
32
+ ts: timestamp,
33
+ logSrcType: 1,
34
+ },
35
+ }),
36
+ }),
37
+ },
38
+ decorLog: JSON.stringify({
39
+ fw: {
40
+ pmsg: {
41
+ st: 1,
42
+ ts: timestamp,
43
+ },
44
+ rmsg: {
45
+ st: 1,
46
+ ts: timestamp,
47
+ },
48
+ fwLvl: 1,
49
+ },
50
+ }),
51
+ };
52
+ switch (messageType) {
53
+ case common.AttachmentType.IMAGE:
54
+ const imageOptions = options;
55
+ const fileImage = await index.getFileUpload(imageOptions.url);
56
+ params = Object.assign(Object.assign({}, params), { msgType: 2, msgInfo: Object.assign(Object.assign({}, params.msgInfo), { title: '', oriUrl: imageOptions.url, url: imageOptions.url, thumbUrl: imageOptions.url, width: 720, height: 1280, properties: null, hdSize: fileImage.size, normalUrl: '' }), jcp: {
57
+ convertible: 'jxl',
58
+ } });
59
+ break;
60
+ case common.AttachmentType.FILE:
61
+ const fileOptions = options;
62
+ params = Object.assign(Object.assign({}, params), { msgType: 1, msgInfo: Object.assign(Object.assign({}, params.msgInfo), { url: fileOptions.url, size: fileAttachment.size, checksum: checksum.data, extension: fileAttachment.ext || '', fileName: fileOptions.fileName, title: (_a = fileOptions.msg) !== null && _a !== void 0 ? _a : undefined }) });
63
+ break;
64
+ }
65
+ if (type === Enum.ThreadType.User) {
66
+ params.toId = threadId;
67
+ }
68
+ else if (type === Enum.ThreadType.Group) {
69
+ params.grid = threadId;
70
+ }
71
+ params = Object.assign(Object.assign({}, params), { msgInfo: JSON.stringify(params.msgInfo) });
72
+ const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
73
+ if (!encryptedParams)
74
+ throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
75
+ const response = await utils$1.request(serviceURL[type], {
76
+ method: 'POST',
77
+ body: new URLSearchParams({
78
+ params: encryptedParams,
79
+ }),
80
+ });
81
+ return utils$1.resolve(response);
82
+ };
83
+ });
84
+
85
+ exports.forwardAttachmentFactory = forwardAttachmentFactory;