@softtynet/zca-js 2.1.3

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 (547) hide show
  1. package/.prettierrc +5 -0
  2. package/CODE_OF_CONDUCT.md +163 -0
  3. package/CONTRIBUTING.md +470 -0
  4. package/LICENSE +21 -0
  5. package/README.md +225 -0
  6. package/SECURITY.md +83 -0
  7. package/dist/Errors/ZaloApiError.d.ts +4 -0
  8. package/dist/Errors/ZaloApiError.js +7 -0
  9. package/dist/Errors/ZaloApiLoginQRAborted.d.ts +4 -0
  10. package/dist/Errors/ZaloApiLoginQRAborted.js +7 -0
  11. package/dist/Errors/ZaloApiLoginQRDeclined.d.ts +4 -0
  12. package/dist/Errors/ZaloApiLoginQRDeclined.js +7 -0
  13. package/dist/Errors/ZaloApiMissingImageMetadataGetter.d.ts +4 -0
  14. package/dist/Errors/ZaloApiMissingImageMetadataGetter.js +7 -0
  15. package/dist/Errors/index.d.ts +4 -0
  16. package/dist/Errors/index.js +4 -0
  17. package/dist/apis/acceptFriendRequest.d.ts +2 -0
  18. package/dist/apis/acceptFriendRequest.js +28 -0
  19. package/dist/apis/addGroupBlockedMember.d.ts +2 -0
  20. package/dist/apis/addGroupBlockedMember.js +28 -0
  21. package/dist/apis/addGroupDeputy.d.ts +2 -0
  22. package/dist/apis/addGroupDeputy.js +30 -0
  23. package/dist/apis/addPollOptions.d.ts +14 -0
  24. package/dist/apis/addPollOptions.js +26 -0
  25. package/dist/apis/addQuickMessage.d.ts +11 -0
  26. package/dist/apis/addQuickMessage.js +60 -0
  27. package/dist/apis/addReaction.d.ts +18 -0
  28. package/dist/apis/addReaction.js +294 -0
  29. package/dist/apis/addUnreadMark.d.ts +8 -0
  30. package/dist/apis/addUnreadMark.js +52 -0
  31. package/dist/apis/addUserToGroup.d.ts +5 -0
  32. package/dist/apis/addUserToGroup.js +34 -0
  33. package/dist/apis/blockUser.d.ts +2 -0
  34. package/dist/apis/blockUser.js +28 -0
  35. package/dist/apis/blockViewFeed.d.ts +2 -0
  36. package/dist/apis/blockViewFeed.js +30 -0
  37. package/dist/apis/changeAccountAvatar.d.ts +3 -0
  38. package/dist/apis/changeAccountAvatar.js +52 -0
  39. package/dist/apis/changeFriendAlias.d.ts +2 -0
  40. package/dist/apis/changeFriendAlias.js +27 -0
  41. package/dist/apis/changeGroupAvatar.d.ts +3 -0
  42. package/dist/apis/changeGroupAvatar.js +44 -0
  43. package/dist/apis/changeGroupName.d.ts +4 -0
  44. package/dist/apis/changeGroupName.js +32 -0
  45. package/dist/apis/changeGroupOwner.d.ts +4 -0
  46. package/dist/apis/changeGroupOwner.js +30 -0
  47. package/dist/apis/createAutoReply.d.ts +14 -0
  48. package/dist/apis/createAutoReply.js +37 -0
  49. package/dist/apis/createCatalog.d.ts +7 -0
  50. package/dist/apis/createCatalog.js +29 -0
  51. package/dist/apis/createGroup.d.ts +28 -0
  52. package/dist/apis/createGroup.js +43 -0
  53. package/dist/apis/createNote.d.ts +7 -0
  54. package/dist/apis/createNote.js +47 -0
  55. package/dist/apis/createPoll.d.ts +36 -0
  56. package/dist/apis/createPoll.js +40 -0
  57. package/dist/apis/createProductCatalog.d.ts +23 -0
  58. package/dist/apis/createProductCatalog.js +50 -0
  59. package/dist/apis/createReminder.d.ts +12 -0
  60. package/dist/apis/createReminder.js +63 -0
  61. package/dist/apis/custom.d.ts +9 -0
  62. package/dist/apis/custom.js +15 -0
  63. package/dist/apis/deleteAutoReply.d.ts +5 -0
  64. package/dist/apis/deleteAutoReply.js +29 -0
  65. package/dist/apis/deleteAvatar.d.ts +9 -0
  66. package/dist/apis/deleteAvatar.js +27 -0
  67. package/dist/apis/deleteCatalog.d.ts +2 -0
  68. package/dist/apis/deleteCatalog.js +28 -0
  69. package/dist/apis/deleteChat.d.ts +19 -0
  70. package/dist/apis/deleteChat.js +50 -0
  71. package/dist/apis/deleteGroupInviteBox.d.ts +9 -0
  72. package/dist/apis/deleteGroupInviteBox.js +27 -0
  73. package/dist/apis/deleteMessage.d.ts +14 -0
  74. package/dist/apis/deleteMessage.js +52 -0
  75. package/dist/apis/deleteProductCatalog.d.ts +10 -0
  76. package/dist/apis/deleteProductCatalog.js +31 -0
  77. package/dist/apis/disableGroupLink.d.ts +2 -0
  78. package/dist/apis/disableGroupLink.js +24 -0
  79. package/dist/apis/disperseGroup.d.ts +2 -0
  80. package/dist/apis/disperseGroup.js +28 -0
  81. package/dist/apis/editNote.d.ts +17 -0
  82. package/dist/apis/editNote.js +46 -0
  83. package/dist/apis/editReminder.d.ts +13 -0
  84. package/dist/apis/editReminder.js +61 -0
  85. package/dist/apis/enableGroupLink.d.ts +6 -0
  86. package/dist/apis/enableGroupLink.js +25 -0
  87. package/dist/apis/fetchAccountInfo.d.ts +5 -0
  88. package/dist/apis/fetchAccountInfo.js +10 -0
  89. package/dist/apis/findUser.d.ts +3 -0
  90. package/dist/apis/findUser.js +42 -0
  91. package/dist/apis/findUserByUsername.d.ts +3 -0
  92. package/dist/apis/findUserByUsername.js +27 -0
  93. package/dist/apis/forwardMessage.d.ts +24 -0
  94. package/dist/apis/forwardMessage.js +99 -0
  95. package/dist/apis/getAliasList.d.ts +8 -0
  96. package/dist/apis/getAliasList.js +27 -0
  97. package/dist/apis/getAllFriends.d.ts +3 -0
  98. package/dist/apis/getAllFriends.js +34 -0
  99. package/dist/apis/getAllGroups.d.ts +7 -0
  100. package/dist/apis/getAllGroups.js +10 -0
  101. package/dist/apis/getArchivedChatList.d.ts +5 -0
  102. package/dist/apis/getArchivedChatList.js +23 -0
  103. package/dist/apis/getAutoDeleteChat.d.ts +9 -0
  104. package/dist/apis/getAutoDeleteChat.js +21 -0
  105. package/dist/apis/getAutoReplyList.d.ts +6 -0
  106. package/dist/apis/getAutoReplyList.js +24 -0
  107. package/dist/apis/getAvatarList.d.ts +12 -0
  108. package/dist/apis/getAvatarList.js +28 -0
  109. package/dist/apis/getAvatarUrlProfile.d.ts +7 -0
  110. package/dist/apis/getAvatarUrlProfile.js +30 -0
  111. package/dist/apis/getBizAccount.d.ts +24 -0
  112. package/dist/apis/getBizAccount.js +27 -0
  113. package/dist/apis/getCatalogList.d.ts +18 -0
  114. package/dist/apis/getCatalogList.js +32 -0
  115. package/dist/apis/getCloseFriends.d.ts +3 -0
  116. package/dist/apis/getCloseFriends.js +20 -0
  117. package/dist/apis/getContext.d.ts +1 -0
  118. package/dist/apis/getContext.js +4 -0
  119. package/dist/apis/getCookie.d.ts +1 -0
  120. package/dist/apis/getCookie.js +9 -0
  121. package/dist/apis/getFriendBoardList.d.ts +5 -0
  122. package/dist/apis/getFriendBoardList.js +26 -0
  123. package/dist/apis/getFriendOnlines.d.ts +10 -0
  124. package/dist/apis/getFriendOnlines.js +35 -0
  125. package/dist/apis/getFriendRecommendations.d.ts +42 -0
  126. package/dist/apis/getFriendRecommendations.js +27 -0
  127. package/dist/apis/getFriendRequestStatus.d.ts +8 -0
  128. package/dist/apis/getFriendRequestStatus.js +25 -0
  129. package/dist/apis/getFullAvatar.d.ts +5 -0
  130. package/dist/apis/getFullAvatar.js +25 -0
  131. package/dist/apis/getGroupBlockedMember.d.ts +23 -0
  132. package/dist/apis/getGroupBlockedMember.js +29 -0
  133. package/dist/apis/getGroupChatHistory.d.ts +8 -0
  134. package/dist/apis/getGroupChatHistory.js +36 -0
  135. package/dist/apis/getGroupInfo.d.ts +16 -0
  136. package/dist/apis/getGroupInfo.js +32 -0
  137. package/dist/apis/getGroupInviteBoxInfo.d.ts +32 -0
  138. package/dist/apis/getGroupInviteBoxInfo.js +38 -0
  139. package/dist/apis/getGroupInviteBoxList.d.ts +38 -0
  140. package/dist/apis/getGroupInviteBoxList.js +31 -0
  141. package/dist/apis/getGroupLinkDetail.d.ts +9 -0
  142. package/dist/apis/getGroupLinkDetail.js +25 -0
  143. package/dist/apis/getGroupLinkInfo.d.ts +34 -0
  144. package/dist/apis/getGroupLinkInfo.js +28 -0
  145. package/dist/apis/getGroupMembersInfo.d.ts +17 -0
  146. package/dist/apis/getGroupMembersInfo.js +24 -0
  147. package/dist/apis/getHiddenConversations.d.ts +11 -0
  148. package/dist/apis/getHiddenConversations.js +23 -0
  149. package/dist/apis/getLabels.d.ts +7 -0
  150. package/dist/apis/getLabels.js +28 -0
  151. package/dist/apis/getListBoard.d.ts +21 -0
  152. package/dist/apis/getListBoard.js +45 -0
  153. package/dist/apis/getListReminder.d.ts +28 -0
  154. package/dist/apis/getListReminder.js +47 -0
  155. package/dist/apis/getMultiUsersByPhones.d.ts +5 -0
  156. package/dist/apis/getMultiUsersByPhones.js +39 -0
  157. package/dist/apis/getMute.d.ts +13 -0
  158. package/dist/apis/getMute.js +22 -0
  159. package/dist/apis/getOwnId.d.ts +1 -0
  160. package/dist/apis/getOwnId.js +4 -0
  161. package/dist/apis/getPendingGroupMembers.d.ts +11 -0
  162. package/dist/apis/getPendingGroupMembers.js +27 -0
  163. package/dist/apis/getPinConversations.d.ts +5 -0
  164. package/dist/apis/getPinConversations.js +22 -0
  165. package/dist/apis/getPollDetail.d.ts +3 -0
  166. package/dist/apis/getPollDetail.js +30 -0
  167. package/dist/apis/getProductCatalogList.d.ts +20 -0
  168. package/dist/apis/getProductCatalogList.js +33 -0
  169. package/dist/apis/getQR.d.ts +4 -0
  170. package/dist/apis/getQR.js +29 -0
  171. package/dist/apis/getQuickMessageList.d.ts +7 -0
  172. package/dist/apis/getQuickMessageList.js +24 -0
  173. package/dist/apis/getRelatedFriendGroup.d.ts +6 -0
  174. package/dist/apis/getRelatedFriendGroup.js +30 -0
  175. package/dist/apis/getReminder.d.ts +3 -0
  176. package/dist/apis/getReminder.js +25 -0
  177. package/dist/apis/getReminderResponses.d.ts +5 -0
  178. package/dist/apis/getReminderResponses.js +24 -0
  179. package/dist/apis/getSentFriendRequest.d.ts +18 -0
  180. package/dist/apis/getSentFriendRequest.js +24 -0
  181. package/dist/apis/getSettings.d.ts +3 -0
  182. package/dist/apis/getSettings.js +20 -0
  183. package/dist/apis/getStickerCategoryDetail.d.ts +3 -0
  184. package/dist/apis/getStickerCategoryDetail.js +24 -0
  185. package/dist/apis/getStickers.d.ts +1 -0
  186. package/dist/apis/getStickers.js +40 -0
  187. package/dist/apis/getStickersDetail.d.ts +3 -0
  188. package/dist/apis/getStickersDetail.js +40 -0
  189. package/dist/apis/getUnreadMark.d.ts +14 -0
  190. package/dist/apis/getUnreadMark.js +30 -0
  191. package/dist/apis/getUserInfo.d.ts +8 -0
  192. package/dist/apis/getUserInfo.js +44 -0
  193. package/dist/apis/inviteUserToGroups.d.ts +10 -0
  194. package/dist/apis/inviteUserToGroups.js +30 -0
  195. package/dist/apis/joinGroupInviteBox.d.ts +2 -0
  196. package/dist/apis/joinGroupInviteBox.js +25 -0
  197. package/dist/apis/joinGroupLink.d.ts +2 -0
  198. package/dist/apis/joinGroupLink.js +27 -0
  199. package/dist/apis/keepAlive.d.ts +4 -0
  200. package/dist/apis/keepAlive.js +22 -0
  201. package/dist/apis/lastOnline.d.ts +7 -0
  202. package/dist/apis/lastOnline.js +26 -0
  203. package/dist/apis/leaveGroup.d.ts +4 -0
  204. package/dist/apis/leaveGroup.js +33 -0
  205. package/dist/apis/listen.d.ts +102 -0
  206. package/dist/apis/listen.js +425 -0
  207. package/dist/apis/lockPoll.d.ts +2 -0
  208. package/dist/apis/lockPoll.js +28 -0
  209. package/dist/apis/login.d.ts +3 -0
  210. package/dist/apis/login.js +96 -0
  211. package/dist/apis/loginQR.d.ts +71 -0
  212. package/dist/apis/loginQR.js +338 -0
  213. package/dist/apis/parseLink.d.ts +21 -0
  214. package/dist/apis/parseLink.js +27 -0
  215. package/dist/apis/rejectFriendRequest.d.ts +2 -0
  216. package/dist/apis/rejectFriendRequest.js +27 -0
  217. package/dist/apis/removeFriend.d.ts +2 -0
  218. package/dist/apis/removeFriend.js +28 -0
  219. package/dist/apis/removeFriendAlias.d.ts +2 -0
  220. package/dist/apis/removeFriendAlias.js +24 -0
  221. package/dist/apis/removeGroupBlockedMember.d.ts +2 -0
  222. package/dist/apis/removeGroupBlockedMember.js +28 -0
  223. package/dist/apis/removeGroupDeputy.d.ts +2 -0
  224. package/dist/apis/removeGroupDeputy.js +30 -0
  225. package/dist/apis/removeQuickMessage.d.ts +5 -0
  226. package/dist/apis/removeQuickMessage.js +27 -0
  227. package/dist/apis/removeReminder.d.ts +3 -0
  228. package/dist/apis/removeReminder.js +40 -0
  229. package/dist/apis/removeUnreadMark.d.ts +8 -0
  230. package/dist/apis/removeUnreadMark.js +50 -0
  231. package/dist/apis/removeUserFromGroup.d.ts +4 -0
  232. package/dist/apis/removeUserFromGroup.js +34 -0
  233. package/dist/apis/resetHiddenConversPin.d.ts +2 -0
  234. package/dist/apis/resetHiddenConversPin.js +20 -0
  235. package/dist/apis/reuseAvatar.d.ts +2 -0
  236. package/dist/apis/reuseAvatar.js +26 -0
  237. package/dist/apis/reviewPendingMemberRequest.d.ts +14 -0
  238. package/dist/apis/reviewPendingMemberRequest.js +38 -0
  239. package/dist/apis/searchSticker.d.ts +3 -0
  240. package/dist/apis/searchSticker.js +28 -0
  241. package/dist/apis/sendBankCard.d.ts +9 -0
  242. package/dist/apis/sendBankCard.js +37 -0
  243. package/dist/apis/sendCard.d.ts +10 -0
  244. package/dist/apis/sendCard.js +59 -0
  245. package/dist/apis/sendDeliveredEvent.d.ts +16 -0
  246. package/dist/apis/sendDeliveredEvent.js +55 -0
  247. package/dist/apis/sendFriendRequest.d.ts +2 -0
  248. package/dist/apis/sendFriendRequest.js +39 -0
  249. package/dist/apis/sendLink.d.ts +10 -0
  250. package/dist/apis/sendLink.js +61 -0
  251. package/dist/apis/sendMessage.d.ts +99 -0
  252. package/dist/apis/sendMessage.js +452 -0
  253. package/dist/apis/sendReport.d.ts +17 -0
  254. package/dist/apis/sendReport.js +53 -0
  255. package/dist/apis/sendSeenEvent.d.ts +16 -0
  256. package/dist/apis/sendSeenEvent.js +63 -0
  257. package/dist/apis/sendSticker.d.ts +10 -0
  258. package/dist/apis/sendSticker.js +57 -0
  259. package/dist/apis/sendTypingEvent.d.ts +5 -0
  260. package/dist/apis/sendTypingEvent.js +33 -0
  261. package/dist/apis/sendVideo.d.ts +35 -0
  262. package/dist/apis/sendVideo.js +118 -0
  263. package/dist/apis/sendVoice.d.ts +12 -0
  264. package/dist/apis/sendVoice.js +73 -0
  265. package/dist/apis/setHiddenConversations.d.ts +3 -0
  266. package/dist/apis/setHiddenConversations.js +39 -0
  267. package/dist/apis/setMute.d.ts +20 -0
  268. package/dist/apis/setMute.js +67 -0
  269. package/dist/apis/setPinnedConversations.d.ts +3 -0
  270. package/dist/apis/setPinnedConversations.js +34 -0
  271. package/dist/apis/sharePoll.d.ts +2 -0
  272. package/dist/apis/sharePoll.js +28 -0
  273. package/dist/apis/unblockUser.d.ts +2 -0
  274. package/dist/apis/unblockUser.js +28 -0
  275. package/dist/apis/undo.d.ts +9 -0
  276. package/dist/apis/undo.js +42 -0
  277. package/dist/apis/undoFriendRequest.d.ts +2 -0
  278. package/dist/apis/undoFriendRequest.js +27 -0
  279. package/dist/apis/updateActiveStatus.d.ts +4 -0
  280. package/dist/apis/updateActiveStatus.js +27 -0
  281. package/dist/apis/updateArchivedChatList.d.ts +10 -0
  282. package/dist/apis/updateArchivedChatList.js +34 -0
  283. package/dist/apis/updateAutoDeleteChat.d.ts +9 -0
  284. package/dist/apis/updateAutoDeleteChat.js +40 -0
  285. package/dist/apis/updateAutoReply.d.ts +15 -0
  286. package/dist/apis/updateAutoReply.js +38 -0
  287. package/dist/apis/updateCatalog.d.ts +11 -0
  288. package/dist/apis/updateCatalog.js +30 -0
  289. package/dist/apis/updateGroupSettings.d.ts +40 -0
  290. package/dist/apis/updateGroupSettings.js +43 -0
  291. package/dist/apis/updateHiddenConversPin.d.ts +2 -0
  292. package/dist/apis/updateHiddenConversPin.js +30 -0
  293. package/dist/apis/updateLabels.d.ts +15 -0
  294. package/dist/apis/updateLabels.js +34 -0
  295. package/dist/apis/updateLang.d.ts +6 -0
  296. package/dist/apis/updateLang.js +30 -0
  297. package/dist/apis/updateProductCatalog.d.ts +25 -0
  298. package/dist/apis/updateProductCatalog.js +51 -0
  299. package/dist/apis/updateProfile.d.ts +20 -0
  300. package/dist/apis/updateProfile.js +43 -0
  301. package/dist/apis/updateProfileBio.d.ts +2 -0
  302. package/dist/apis/updateProfileBio.js +27 -0
  303. package/dist/apis/updateQuickMessage.d.ts +11 -0
  304. package/dist/apis/updateQuickMessage.js +61 -0
  305. package/dist/apis/updateSettings.d.ts +16 -0
  306. package/dist/apis/updateSettings.js +90 -0
  307. package/dist/apis/upgradeGroupToCommunity.d.ts +2 -0
  308. package/dist/apis/upgradeGroupToCommunity.js +27 -0
  309. package/dist/apis/uploadAttachment.d.ts +50 -0
  310. package/dist/apis/uploadAttachment.js +197 -0
  311. package/dist/apis/uploadProductPhoto.d.ts +14 -0
  312. package/dist/apis/uploadProductPhoto.js +50 -0
  313. package/dist/apis/votePoll.d.ts +5 -0
  314. package/dist/apis/votePoll.js +29 -0
  315. package/dist/apis.d.ts +299 -0
  316. package/dist/apis.js +299 -0
  317. package/dist/cjs/Errors/ZaloApiError.cjs +11 -0
  318. package/dist/cjs/Errors/ZaloApiLoginQRAborted.cjs +12 -0
  319. package/dist/cjs/Errors/ZaloApiLoginQRDeclined.cjs +12 -0
  320. package/dist/cjs/Errors/ZaloApiMissingImageMetadataGetter.cjs +12 -0
  321. package/dist/cjs/apis/acceptFriendRequest.cjs +33 -0
  322. package/dist/cjs/apis/addGroupBlockedMember.cjs +33 -0
  323. package/dist/cjs/apis/addGroupDeputy.cjs +35 -0
  324. package/dist/cjs/apis/addPollOptions.cjs +31 -0
  325. package/dist/cjs/apis/addQuickMessage.cjs +65 -0
  326. package/dist/cjs/apis/addReaction.cjs +307 -0
  327. package/dist/cjs/apis/addUnreadMark.cjs +65 -0
  328. package/dist/cjs/apis/addUserToGroup.cjs +39 -0
  329. package/dist/cjs/apis/blockUser.cjs +33 -0
  330. package/dist/cjs/apis/blockViewFeed.cjs +35 -0
  331. package/dist/cjs/apis/changeAccountAvatar.cjs +57 -0
  332. package/dist/cjs/apis/changeFriendAlias.cjs +32 -0
  333. package/dist/cjs/apis/changeGroupAvatar.cjs +49 -0
  334. package/dist/cjs/apis/changeGroupName.cjs +37 -0
  335. package/dist/cjs/apis/changeGroupOwner.cjs +35 -0
  336. package/dist/cjs/apis/createAutoReply.cjs +42 -0
  337. package/dist/cjs/apis/createCatalog.cjs +34 -0
  338. package/dist/cjs/apis/createGroup.cjs +48 -0
  339. package/dist/cjs/apis/createNote.cjs +52 -0
  340. package/dist/cjs/apis/createPoll.cjs +45 -0
  341. package/dist/cjs/apis/createProductCatalog.cjs +55 -0
  342. package/dist/cjs/apis/createReminder.cjs +76 -0
  343. package/dist/cjs/apis/custom.cjs +19 -0
  344. package/dist/cjs/apis/deleteAutoReply.cjs +34 -0
  345. package/dist/cjs/apis/deleteAvatar.cjs +32 -0
  346. package/dist/cjs/apis/deleteCatalog.cjs +33 -0
  347. package/dist/cjs/apis/deleteChat.cjs +63 -0
  348. package/dist/cjs/apis/deleteGroupInviteBox.cjs +32 -0
  349. package/dist/cjs/apis/deleteMessage.cjs +65 -0
  350. package/dist/cjs/apis/deleteProductCatalog.cjs +36 -0
  351. package/dist/cjs/apis/disableGroupLink.cjs +29 -0
  352. package/dist/cjs/apis/disperseGroup.cjs +33 -0
  353. package/dist/cjs/apis/editNote.cjs +51 -0
  354. package/dist/cjs/apis/editReminder.cjs +74 -0
  355. package/dist/cjs/apis/enableGroupLink.cjs +30 -0
  356. package/dist/cjs/apis/fetchAccountInfo.cjs +15 -0
  357. package/dist/cjs/apis/findUser.cjs +55 -0
  358. package/dist/cjs/apis/findUserByUsername.cjs +40 -0
  359. package/dist/cjs/apis/forwardMessage.cjs +112 -0
  360. package/dist/cjs/apis/getAliasList.cjs +32 -0
  361. package/dist/cjs/apis/getAllFriends.cjs +47 -0
  362. package/dist/cjs/apis/getAllGroups.cjs +15 -0
  363. package/dist/cjs/apis/getArchivedChatList.cjs +28 -0
  364. package/dist/cjs/apis/getAutoDeleteChat.cjs +26 -0
  365. package/dist/cjs/apis/getAutoReplyList.cjs +29 -0
  366. package/dist/cjs/apis/getAvatarList.cjs +33 -0
  367. package/dist/cjs/apis/getAvatarUrlProfile.cjs +43 -0
  368. package/dist/cjs/apis/getBizAccount.cjs +32 -0
  369. package/dist/cjs/apis/getCatalogList.cjs +37 -0
  370. package/dist/cjs/apis/getCloseFriends.cjs +25 -0
  371. package/dist/cjs/apis/getContext.cjs +9 -0
  372. package/dist/cjs/apis/getCookie.cjs +14 -0
  373. package/dist/cjs/apis/getFriendBoardList.cjs +31 -0
  374. package/dist/cjs/apis/getFriendOnlines.cjs +40 -0
  375. package/dist/cjs/apis/getFriendRecommendations.cjs +32 -0
  376. package/dist/cjs/apis/getFriendRequestStatus.cjs +30 -0
  377. package/dist/cjs/apis/getFullAvatar.cjs +30 -0
  378. package/dist/cjs/apis/getGroupBlockedMember.cjs +34 -0
  379. package/dist/cjs/apis/getGroupChatHistory.cjs +50 -0
  380. package/dist/cjs/apis/getGroupInfo.cjs +37 -0
  381. package/dist/cjs/apis/getGroupInviteBoxInfo.cjs +43 -0
  382. package/dist/cjs/apis/getGroupInviteBoxList.cjs +36 -0
  383. package/dist/cjs/apis/getGroupLinkDetail.cjs +30 -0
  384. package/dist/cjs/apis/getGroupLinkInfo.cjs +33 -0
  385. package/dist/cjs/apis/getGroupMembersInfo.cjs +29 -0
  386. package/dist/cjs/apis/getHiddenConversations.cjs +28 -0
  387. package/dist/cjs/apis/getLabels.cjs +33 -0
  388. package/dist/cjs/apis/getListBoard.cjs +58 -0
  389. package/dist/cjs/apis/getListReminder.cjs +60 -0
  390. package/dist/cjs/apis/getMultiUsersByPhones.cjs +52 -0
  391. package/dist/cjs/apis/getMute.cjs +27 -0
  392. package/dist/cjs/apis/getOwnId.cjs +9 -0
  393. package/dist/cjs/apis/getPendingGroupMembers.cjs +32 -0
  394. package/dist/cjs/apis/getPinConversations.cjs +27 -0
  395. package/dist/cjs/apis/getPollDetail.cjs +35 -0
  396. package/dist/cjs/apis/getProductCatalogList.cjs +38 -0
  397. package/dist/cjs/apis/getQR.cjs +34 -0
  398. package/dist/cjs/apis/getQuickMessageList.cjs +29 -0
  399. package/dist/cjs/apis/getRelatedFriendGroup.cjs +35 -0
  400. package/dist/cjs/apis/getReminder.cjs +30 -0
  401. package/dist/cjs/apis/getReminderResponses.cjs +29 -0
  402. package/dist/cjs/apis/getSentFriendRequest.cjs +29 -0
  403. package/dist/cjs/apis/getSettings.cjs +25 -0
  404. package/dist/cjs/apis/getStickerCategoryDetail.cjs +29 -0
  405. package/dist/cjs/apis/getStickers.cjs +45 -0
  406. package/dist/cjs/apis/getStickersDetail.cjs +45 -0
  407. package/dist/cjs/apis/getUnreadMark.cjs +35 -0
  408. package/dist/cjs/apis/getUserInfo.cjs +57 -0
  409. package/dist/cjs/apis/inviteUserToGroups.cjs +35 -0
  410. package/dist/cjs/apis/joinGroupInviteBox.cjs +30 -0
  411. package/dist/cjs/apis/joinGroupLink.cjs +32 -0
  412. package/dist/cjs/apis/keepAlive.cjs +27 -0
  413. package/dist/cjs/apis/lastOnline.cjs +31 -0
  414. package/dist/cjs/apis/leaveGroup.cjs +38 -0
  415. package/dist/cjs/apis/listen.cjs +439 -0
  416. package/dist/cjs/apis/lockPoll.cjs +33 -0
  417. package/dist/cjs/apis/login.cjs +102 -0
  418. package/dist/cjs/apis/loginQR.cjs +343 -0
  419. package/dist/cjs/apis/parseLink.cjs +32 -0
  420. package/dist/cjs/apis/rejectFriendRequest.cjs +32 -0
  421. package/dist/cjs/apis/removeFriend.cjs +33 -0
  422. package/dist/cjs/apis/removeFriendAlias.cjs +29 -0
  423. package/dist/cjs/apis/removeGroupBlockedMember.cjs +33 -0
  424. package/dist/cjs/apis/removeGroupDeputy.cjs +35 -0
  425. package/dist/cjs/apis/removeQuickMessage.cjs +32 -0
  426. package/dist/cjs/apis/removeReminder.cjs +53 -0
  427. package/dist/cjs/apis/removeUnreadMark.cjs +63 -0
  428. package/dist/cjs/apis/removeUserFromGroup.cjs +39 -0
  429. package/dist/cjs/apis/resetHiddenConversPin.cjs +25 -0
  430. package/dist/cjs/apis/reuseAvatar.cjs +31 -0
  431. package/dist/cjs/apis/reviewPendingMemberRequest.cjs +43 -0
  432. package/dist/cjs/apis/searchSticker.cjs +33 -0
  433. package/dist/cjs/apis/sendBankCard.cjs +50 -0
  434. package/dist/cjs/apis/sendCard.cjs +72 -0
  435. package/dist/cjs/apis/sendDeliveredEvent.cjs +68 -0
  436. package/dist/cjs/apis/sendFriendRequest.cjs +44 -0
  437. package/dist/cjs/apis/sendLink.cjs +74 -0
  438. package/dist/cjs/apis/sendMessage.cjs +465 -0
  439. package/dist/cjs/apis/sendReport.cjs +66 -0
  440. package/dist/cjs/apis/sendSeenEvent.cjs +76 -0
  441. package/dist/cjs/apis/sendSticker.cjs +70 -0
  442. package/dist/cjs/apis/sendTypingEvent.cjs +46 -0
  443. package/dist/cjs/apis/sendVideo.cjs +131 -0
  444. package/dist/cjs/apis/sendVoice.cjs +86 -0
  445. package/dist/cjs/apis/setHiddenConversations.cjs +52 -0
  446. package/dist/cjs/apis/setMute.cjs +80 -0
  447. package/dist/cjs/apis/setPinnedConversations.cjs +47 -0
  448. package/dist/cjs/apis/sharePoll.cjs +33 -0
  449. package/dist/cjs/apis/unblockUser.cjs +33 -0
  450. package/dist/cjs/apis/undo.cjs +55 -0
  451. package/dist/cjs/apis/undoFriendRequest.cjs +32 -0
  452. package/dist/cjs/apis/updateActiveStatus.cjs +32 -0
  453. package/dist/cjs/apis/updateArchivedChatList.cjs +39 -0
  454. package/dist/cjs/apis/updateAutoDeleteChat.cjs +53 -0
  455. package/dist/cjs/apis/updateAutoReply.cjs +43 -0
  456. package/dist/cjs/apis/updateCatalog.cjs +35 -0
  457. package/dist/cjs/apis/updateGroupSettings.cjs +48 -0
  458. package/dist/cjs/apis/updateHiddenConversPin.cjs +35 -0
  459. package/dist/cjs/apis/updateLabels.cjs +39 -0
  460. package/dist/cjs/apis/updateLang.cjs +35 -0
  461. package/dist/cjs/apis/updateProductCatalog.cjs +56 -0
  462. package/dist/cjs/apis/updateProfile.cjs +48 -0
  463. package/dist/cjs/apis/updateProfileBio.cjs +32 -0
  464. package/dist/cjs/apis/updateQuickMessage.cjs +66 -0
  465. package/dist/cjs/apis/updateSettings.cjs +95 -0
  466. package/dist/cjs/apis/upgradeGroupToCommunity.cjs +32 -0
  467. package/dist/cjs/apis/uploadAttachment.cjs +210 -0
  468. package/dist/cjs/apis/uploadProductPhoto.cjs +55 -0
  469. package/dist/cjs/apis/votePoll.cjs +34 -0
  470. package/dist/cjs/apis.cjs +304 -0
  471. package/dist/cjs/context.cjs +34 -0
  472. package/dist/cjs/index.cjs +158 -0
  473. package/dist/cjs/models/AutoReply.cjs +9 -0
  474. package/dist/cjs/models/Board.cjs +8 -0
  475. package/dist/cjs/models/DeliveredMessage.cjs +23 -0
  476. package/dist/cjs/models/Enum.cjs +258 -0
  477. package/dist/cjs/models/FriendEvent.cjs +87 -0
  478. package/dist/cjs/models/Group.cjs +13 -0
  479. package/dist/cjs/models/GroupEvent.cjs +94 -0
  480. package/dist/cjs/models/Message.cjs +35 -0
  481. package/dist/cjs/models/Reaction.cjs +74 -0
  482. package/dist/cjs/models/Reminder.cjs +9 -0
  483. package/dist/cjs/models/SeenMessage.cjs +23 -0
  484. package/dist/cjs/models/Typing.cjs +23 -0
  485. package/dist/cjs/models/Undo.cjs +16 -0
  486. package/dist/cjs/models/ZBusiness.cjs +39 -0
  487. package/dist/cjs/update.cjs +34 -0
  488. package/dist/cjs/utils.cjs +731 -0
  489. package/dist/cjs/zalo.cjs +112 -0
  490. package/dist/context.d.ts +179 -0
  491. package/dist/context.js +28 -0
  492. package/dist/index.d.ts +157 -0
  493. package/dist/index.js +14 -0
  494. package/dist/models/Attachment.d.ts +9 -0
  495. package/dist/models/Attachment.js +1 -0
  496. package/dist/models/AutoReply.d.ts +20 -0
  497. package/dist/models/AutoReply.js +7 -0
  498. package/dist/models/Board.d.ts +60 -0
  499. package/dist/models/Board.js +6 -0
  500. package/dist/models/Catalog.d.ts +16 -0
  501. package/dist/models/Catalog.js +1 -0
  502. package/dist/models/DeliveredMessage.d.ts +27 -0
  503. package/dist/models/DeliveredMessage.js +17 -0
  504. package/dist/models/Enum.d.ts +251 -0
  505. package/dist/models/Enum.js +256 -0
  506. package/dist/models/FriendEvent.d.ts +107 -0
  507. package/dist/models/FriendEvent.js +83 -0
  508. package/dist/models/Group.d.ts +125 -0
  509. package/dist/models/Group.js +11 -0
  510. package/dist/models/GroupEvent.d.ts +178 -0
  511. package/dist/models/GroupEvent.js +90 -0
  512. package/dist/models/Label.d.ts +10 -0
  513. package/dist/models/Label.js +1 -0
  514. package/dist/models/Message.d.ts +91 -0
  515. package/dist/models/Message.js +29 -0
  516. package/dist/models/ProductCatalog.d.ts +17 -0
  517. package/dist/models/ProductCatalog.js +1 -0
  518. package/dist/models/QuickMessage.d.ts +25 -0
  519. package/dist/models/QuickMessage.js +1 -0
  520. package/dist/models/Reaction.d.ts +85 -0
  521. package/dist/models/Reaction.js +70 -0
  522. package/dist/models/Reminder.d.ts +51 -0
  523. package/dist/models/Reminder.js +7 -0
  524. package/dist/models/SeenMessage.d.ts +26 -0
  525. package/dist/models/SeenMessage.js +17 -0
  526. package/dist/models/Sticker.d.ts +27 -0
  527. package/dist/models/Sticker.js +1 -0
  528. package/dist/models/Typing.d.ts +24 -0
  529. package/dist/models/Typing.js +17 -0
  530. package/dist/models/Undo.d.ts +34 -0
  531. package/dist/models/Undo.js +12 -0
  532. package/dist/models/User.d.ts +62 -0
  533. package/dist/models/User.js +1 -0
  534. package/dist/models/ZBusiness.d.ts +22 -0
  535. package/dist/models/ZBusiness.js +35 -0
  536. package/dist/models/index.d.ts +21 -0
  537. package/dist/models/index.js +21 -0
  538. package/dist/update.d.ts +2 -0
  539. package/dist/update.js +29 -0
  540. package/dist/utils.d.ts +190 -0
  541. package/dist/utils.js +746 -0
  542. package/dist/zalo.d.ts +41 -0
  543. package/dist/zalo.js +107 -0
  544. package/eslint.config.js +21 -0
  545. package/index.d.ts +2 -0
  546. package/package.json +78 -0
  547. package/rollup.config.js +28 -0
package/dist/utils.js ADDED
@@ -0,0 +1,746 @@
1
+ import cryptojs from "crypto-js";
2
+ import crypto from "node:crypto";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import pako from "pako";
6
+ import SparkMD5 from "spark-md5";
7
+ import toughCookie from "tough-cookie";
8
+ import JSONBig from "json-bigint";
9
+ import { isContextSession } from "./context.js";
10
+ import { ZaloApiError, ZaloApiMissingImageMetadataGetter } from "./Errors/index.js";
11
+ import { FriendEventType } from "./models/FriendEvent.js";
12
+ import { GroupEventType } from "./models/GroupEvent.js";
13
+ export const isBun = typeof Bun !== "undefined";
14
+ export function hasOwn(obj, key) {
15
+ return Object.prototype.hasOwnProperty.call(obj, key);
16
+ }
17
+ /**
18
+ * Get signed key for API requests.
19
+ *
20
+ * @param type
21
+ * @param params
22
+ * @returns MD5 hash
23
+ *
24
+ */
25
+ export function getSignKey(type, params) {
26
+ const n = [];
27
+ for (const s in params) {
28
+ if (hasOwn(params, s)) {
29
+ n.push(s);
30
+ }
31
+ }
32
+ n.sort();
33
+ let a = "zsecure" + type;
34
+ for (let s = 0; s < n.length; s++)
35
+ a += params[n[s]];
36
+ return cryptojs.MD5(a).toString();
37
+ }
38
+ /**
39
+ *
40
+ * @param baseURL
41
+ * @param params
42
+ * @param apiVersion automatically add zalo api version to url params
43
+ * @returns
44
+ *
45
+ */
46
+ export function makeURL(ctx, baseURL, params = {}, apiVersion = true) {
47
+ const url = new URL(baseURL);
48
+ for (const key in params) {
49
+ if (hasOwn(params, key)) {
50
+ url.searchParams.append(key, params[key].toString());
51
+ }
52
+ }
53
+ if (apiVersion) {
54
+ if (!url.searchParams.has("zpw_ver"))
55
+ url.searchParams.set("zpw_ver", ctx.API_VERSION.toString());
56
+ if (!url.searchParams.has("zpw_type"))
57
+ url.searchParams.set("zpw_type", ctx.API_TYPE.toString());
58
+ }
59
+ return url.toString();
60
+ }
61
+ export class ParamsEncryptor {
62
+ constructor({ type, imei, firstLaunchTime }) {
63
+ this.zcid = null;
64
+ this.enc_ver = "v2";
65
+ this.zcid = null;
66
+ this.encryptKey = null;
67
+ this.createZcid(type, imei, firstLaunchTime);
68
+ this.zcid_ext = ParamsEncryptor.randomString();
69
+ this.createEncryptKey();
70
+ }
71
+ getEncryptKey() {
72
+ if (!this.encryptKey)
73
+ throw new ZaloApiError("getEncryptKey: didn't create encryptKey yet");
74
+ return this.encryptKey;
75
+ }
76
+ createZcid(type, imei, firstLaunchTime) {
77
+ if (!type || !imei || !firstLaunchTime)
78
+ throw new ZaloApiError("createZcid: missing params");
79
+ const msg = `${type},${imei},${firstLaunchTime}`;
80
+ const s = ParamsEncryptor.encodeAES("3FC4F0D2AB50057BCE0D90D9187A22B1", msg, "hex", true);
81
+ this.zcid = s;
82
+ }
83
+ createEncryptKey(e = 0) {
84
+ const t = (e, t) => {
85
+ const { even: n } = ParamsEncryptor.processStr(e), { even: a, odd: s } = ParamsEncryptor.processStr(t);
86
+ if (!n || !a || !s)
87
+ return !1;
88
+ const i = n.slice(0, 8).join("") + a.slice(0, 12).join("") + s.reverse().slice(0, 12).join("");
89
+ return (this.encryptKey = i), !0;
90
+ };
91
+ if (!this.zcid || !this.zcid_ext)
92
+ throw new ZaloApiError("createEncryptKey: zcid or zcid_ext is null");
93
+ try {
94
+ const n = cryptojs.MD5(this.zcid_ext).toString().toUpperCase();
95
+ if (t(n, this.zcid) || !(e < 3))
96
+ return !1;
97
+ this.createEncryptKey(e + 1);
98
+ }
99
+ catch (_a) {
100
+ if (e < 3)
101
+ this.createEncryptKey(e + 1);
102
+ }
103
+ return !0;
104
+ }
105
+ getParams() {
106
+ return this.zcid
107
+ ? {
108
+ zcid: this.zcid,
109
+ zcid_ext: this.zcid_ext,
110
+ enc_ver: this.enc_ver,
111
+ }
112
+ : null;
113
+ }
114
+ static processStr(e) {
115
+ if (!e || "string" != typeof e)
116
+ return {
117
+ even: null,
118
+ odd: null,
119
+ };
120
+ const [t, n] = [...e].reduce((e, t, n) => (e[n % 2].push(t), e), [[], []]);
121
+ return {
122
+ even: t,
123
+ odd: n,
124
+ };
125
+ }
126
+ static randomString(e, t) {
127
+ const n = e || 6, a = t && e && t > e ? t : 12;
128
+ let s = Math.floor(Math.random() * (a - n + 1)) + n;
129
+ if (s > 12) {
130
+ let e = "";
131
+ for (; s > 0;) {
132
+ e += Math.random()
133
+ .toString(16)
134
+ .substr(2, s > 12 ? 12 : s);
135
+ s -= 12;
136
+ }
137
+ return e;
138
+ }
139
+ return Math.random().toString(16).substr(2, s);
140
+ }
141
+ static encodeAES(e, message, type, uppercase, s = 0) {
142
+ if (!message)
143
+ return null;
144
+ try {
145
+ {
146
+ const encoder = "hex" == type ? cryptojs.enc.Hex : cryptojs.enc.Base64;
147
+ const key = cryptojs.enc.Utf8.parse(e);
148
+ const cfg = {
149
+ words: [0, 0, 0, 0],
150
+ sigBytes: 16,
151
+ };
152
+ const encrypted = cryptojs.AES.encrypt(message, key, {
153
+ iv: cfg,
154
+ mode: cryptojs.mode.CBC,
155
+ padding: cryptojs.pad.Pkcs7,
156
+ }).ciphertext.toString(encoder);
157
+ return uppercase ? encrypted.toUpperCase() : encrypted;
158
+ }
159
+ }
160
+ catch (_a) {
161
+ return s < 3 ? ParamsEncryptor.encodeAES(e, message, type, uppercase, s + 1) : null;
162
+ }
163
+ }
164
+ }
165
+ export function decryptResp(key, data) {
166
+ let n = null;
167
+ try {
168
+ n = decodeRespAES(key, data);
169
+ const parsed = JSON.parse(n);
170
+ return parsed;
171
+ }
172
+ catch (_a) {
173
+ return n;
174
+ }
175
+ }
176
+ function decodeRespAES(key, data) {
177
+ data = decodeURIComponent(data);
178
+ const parsedKey = cryptojs.enc.Utf8.parse(key);
179
+ const n = {
180
+ words: [0, 0, 0, 0],
181
+ sigBytes: 16,
182
+ };
183
+ return cryptojs.AES.decrypt({
184
+ ciphertext: cryptojs.enc.Base64.parse(data),
185
+ }, parsedKey, {
186
+ iv: n,
187
+ mode: cryptojs.mode.CBC,
188
+ padding: cryptojs.pad.Pkcs7,
189
+ }).toString(cryptojs.enc.Utf8);
190
+ }
191
+ export function decodeBase64ToBuffer(data) {
192
+ return Buffer.from(data, "base64");
193
+ }
194
+ export function decodeUnit8Array(data) {
195
+ try {
196
+ return new TextDecoder().decode(data);
197
+ }
198
+ catch (_a) {
199
+ return null;
200
+ }
201
+ }
202
+ export function encodeAES(secretKey, data, t = 0) {
203
+ try {
204
+ const key = cryptojs.enc.Base64.parse(secretKey);
205
+ return cryptojs.AES.encrypt(data, key, {
206
+ iv: cryptojs.enc.Hex.parse("00000000000000000000000000000000"),
207
+ mode: cryptojs.mode.CBC,
208
+ padding: cryptojs.pad.Pkcs7,
209
+ }).ciphertext.toString(cryptojs.enc.Base64);
210
+ }
211
+ catch (_a) {
212
+ return t < 3 ? encodeAES(secretKey, data, t + 1) : null;
213
+ }
214
+ }
215
+ export function decodeAES(secretKey, data, t = 0) {
216
+ try {
217
+ data = decodeURIComponent(data);
218
+ const key = cryptojs.enc.Base64.parse(secretKey);
219
+ return cryptojs.AES.decrypt({
220
+ ciphertext: cryptojs.enc.Base64.parse(data),
221
+ }, key, {
222
+ iv: cryptojs.enc.Hex.parse("00000000000000000000000000000000"),
223
+ mode: cryptojs.mode.CBC,
224
+ padding: cryptojs.pad.Pkcs7,
225
+ }).toString(cryptojs.enc.Utf8);
226
+ }
227
+ catch (_a) {
228
+ return t < 3 ? decodeAES(secretKey, data, t + 1) : null;
229
+ }
230
+ }
231
+ /**
232
+ * Suy luận nền tảng hệ điều hành (OS) từ chuỗi User-Agent.
233
+ *
234
+ * Hàm này được sinh ra để giải quyết vấn đề cốt lõi: thư viện zca-js trước đây
235
+ * hardcode `sec-ch-ua-platform: "Windows"` ở 8 chỗ trong loginQR, trong khi
236
+ * User-Agent có thể là Mac/Linux — tạo ra Browser Mismatch khiến Zalo ban session.
237
+ *
238
+ * Thứ tự ưu tiên nhận diện: Windows → macOS → Linux → mặc định Windows (an toàn nhất)
239
+ *
240
+ * @returns Chuỗi platform theo định dạng Sec-CH-UA-Platform, ví dụ: "Windows", "macOS", "Linux"
241
+ */
242
+ export function getPlatformFromUA(userAgent) {
243
+ if (!userAgent)
244
+ return "Windows"; // Không có UA → mặc định Windows
245
+ if (/Windows/i.test(userAgent))
246
+ return "Windows";
247
+ if (/Macintosh|Mac OS X/i.test(userAgent))
248
+ return "macOS";
249
+ if (/Linux|X11/i.test(userAgent))
250
+ return "Linux";
251
+ return "Windows"; // Không nhận diện được → fallback an toàn về Windows
252
+ }
253
+ /**
254
+ * Trích xuất phiên bản Chrome major từ chuỗi User-Agent.
255
+ *
256
+ * Dùng để điền vào header `sec-ch-ua` một cách động, đảm bảo Chrome version
257
+ * trong header khớp với Chrome version trong User-Agent (tránh fingerprint anomaly).
258
+ *
259
+ * Lưu ý: Nếu UA không phải Chrome/Chromium (ví dụ Firefox, Safari thuần),
260
+ * hàm trả về "130" làm giá trị mặc định an toàn thay vì throw error.
261
+ *
262
+ * @returns Phiên bản Chrome major dạng string, ví dụ: "130", "133"
263
+ */
264
+ export function getChromeVersionFromUA(userAgent) {
265
+ if (!userAgent)
266
+ return "130"; // Không có UA → dùng version ổn định
267
+ const match = userAgent.match(/Chrome\/(\d+)/);
268
+ return match ? match[1] : "130"; // Không phải Chrome → fallback về "130"
269
+ }
270
+ export async function getDefaultHeaders(ctx, origin = "https://chat.zalo.me") {
271
+ if (!ctx.cookie)
272
+ throw new ZaloApiError("Cookie is not available");
273
+ if (!ctx.userAgent)
274
+ throw new ZaloApiError("User agent is not available");
275
+ return {
276
+ Accept: "application/json, text/plain, */*",
277
+ "Accept-Encoding": "gzip, deflate, br, zstd",
278
+ "Accept-Language": "en-US,en;q=0.9",
279
+ "content-type": "application/x-www-form-urlencoded",
280
+ Cookie: await ctx.cookie.getCookieString(origin),
281
+ Origin: "https://chat.zalo.me",
282
+ Referer: "https://chat.zalo.me/",
283
+ "User-Agent": ctx.userAgent,
284
+ };
285
+ }
286
+ export async function request(ctx, url, options, raw = false) {
287
+ var _a, _b;
288
+ if (!ctx.cookie)
289
+ ctx.cookie = new toughCookie.CookieJar();
290
+ const origin = new URL(url).origin;
291
+ const defaultHeaders = await getDefaultHeaders(ctx, origin);
292
+ if (!raw) {
293
+ if (options) {
294
+ options.headers = Object.assign(defaultHeaders, options.headers || {});
295
+ }
296
+ else
297
+ options = { headers: defaultHeaders };
298
+ }
299
+ const _options = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), (isBun ? {
300
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
301
+ // @ts-ignore
302
+ proxy: (_b = (_a = ctx.options.agent) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.href
303
+ } : { agent: ctx.options.agent }));
304
+ const response = await ctx.options.polyfill(url, _options);
305
+ const setCookieRaw = response.headers.get("set-cookie");
306
+ if (setCookieRaw && !raw) {
307
+ // Use getSetCookie() (Node.js 18+) to properly parse multi-cookie headers.
308
+ // The split(", ") method breaks cookies containing Expires dates with commas
309
+ // (e.g., "Expires=Wed, 18 Mar 2026..."), causing critical cookies like
310
+ // zpsid and zpw_sek to be lost during QR login flow.
311
+ let cookieStrings;
312
+ if (typeof response.headers.getSetCookie === "function") {
313
+ cookieStrings = response.headers.getSetCookie();
314
+ }
315
+ else {
316
+ cookieStrings = setCookieRaw.split(", ");
317
+ }
318
+ for (const cookie of cookieStrings) {
319
+ const parsed = toughCookie.Cookie.parse(cookie);
320
+ try {
321
+ if (parsed)
322
+ await ctx.cookie.setCookie(parsed, parsed.domain != "zalo.me" ? `https://${parsed.domain}` : origin);
323
+ }
324
+ catch (error) {
325
+ logger(ctx).error(error);
326
+ }
327
+ }
328
+ }
329
+ const redirectURL = response.headers.get("location");
330
+ if (redirectURL) {
331
+ const redirectOptions = Object.assign({}, options);
332
+ redirectOptions.method = "GET";
333
+ if (!raw) {
334
+ redirectOptions.headers = new Headers(redirectOptions.headers);
335
+ redirectOptions.headers.set("Referer", "https://id.zalo.me/");
336
+ }
337
+ return await request(ctx, redirectURL, redirectOptions);
338
+ }
339
+ return response;
340
+ }
341
+ export async function getImageMetaData(ctx, filePath) {
342
+ if (!ctx.options.imageMetadataGetter) {
343
+ throw new ZaloApiMissingImageMetadataGetter();
344
+ }
345
+ const imageData = await ctx.options.imageMetadataGetter(filePath);
346
+ if (!imageData) {
347
+ throw new ZaloApiError("Failed to get image metadata");
348
+ }
349
+ const fileName = filePath.split("/").pop();
350
+ return {
351
+ fileName,
352
+ totalSize: imageData.size,
353
+ width: imageData.width,
354
+ height: imageData.height,
355
+ };
356
+ }
357
+ export async function getFileSize(filePath) {
358
+ return fs.promises.stat(filePath).then((s) => s.size);
359
+ }
360
+ export async function getGifMetaData(ctx, filePath) {
361
+ if (!ctx.options.imageMetadataGetter) {
362
+ throw new ZaloApiMissingImageMetadataGetter();
363
+ }
364
+ const gifData = await ctx.options.imageMetadataGetter(filePath);
365
+ if (!gifData) {
366
+ throw new ZaloApiError("Failed to get gif metadata");
367
+ }
368
+ const fileName = path.basename(filePath);
369
+ return {
370
+ fileName,
371
+ totalSize: gifData.size,
372
+ width: gifData.width,
373
+ height: gifData.height,
374
+ };
375
+ }
376
+ export async function decodeEventData(parsed, cipherKey) {
377
+ if (typeof parsed.data !== "string")
378
+ throw new ZaloApiError(`Invalid data, expected string but got ${typeof parsed.data}`);
379
+ if (typeof parsed.encrypt !== "number")
380
+ throw new ZaloApiError(`Invalid encrypt type, expected number but got ${typeof parsed.encrypt}`);
381
+ if (parsed.encrypt < 0 || parsed.encrypt > 3)
382
+ throw new ZaloApiError(`Invalid encrypt type, expected 0-3 but got ${parsed.encrypt}`);
383
+ const rawData = parsed.data;
384
+ const encryptType = parsed.encrypt;
385
+ if (encryptType === 0)
386
+ return JSON.parse(rawData);
387
+ const decodedBuffer = decodeBase64ToBuffer(encryptType === 1 ? rawData : decodeURIComponent(rawData));
388
+ let decryptedBuffer = decodedBuffer;
389
+ if (encryptType !== 1) {
390
+ if (cipherKey && decodedBuffer.length >= 48) {
391
+ const algorithm = {
392
+ name: "AES-GCM",
393
+ iv: decodedBuffer.subarray(0, 16),
394
+ tagLength: 128,
395
+ additionalData: decodedBuffer.subarray(16, 32),
396
+ };
397
+ const dataSource = decodedBuffer.subarray(32);
398
+ const cryptoKey = await crypto.subtle.importKey("raw", decodeBase64ToBuffer(cipherKey), algorithm, false, [
399
+ "decrypt",
400
+ ]);
401
+ decryptedBuffer = await crypto.subtle.decrypt(algorithm, cryptoKey, dataSource);
402
+ }
403
+ else {
404
+ throw new ZaloApiError("Invalid data length or missing cipher key");
405
+ }
406
+ }
407
+ const decompressedBuffer = encryptType === 3 ? new Uint8Array(decryptedBuffer) : pako.inflate(decryptedBuffer);
408
+ const decodedData = decodeUnit8Array(decompressedBuffer);
409
+ if (!decodedData)
410
+ return;
411
+ return JSONBig.parse(decodedData);
412
+ }
413
+ export async function getMd5LargeFileObject(source, fileSize) {
414
+ const buffer = typeof source == "string" ? await fs.promises.readFile(source) : source.data;
415
+ return new Promise((resolve) => {
416
+ let currentChunk = 0;
417
+ const chunkSize = 2097152, // Read in chunks of 2MB
418
+ chunks = Math.ceil(fileSize / chunkSize), spark = new SparkMD5.ArrayBuffer();
419
+ function loadNext() {
420
+ const start = currentChunk * chunkSize, end = start + chunkSize >= fileSize ? fileSize : start + chunkSize;
421
+ spark.append(new Uint8Array(buffer.subarray(start, end)).buffer);
422
+ currentChunk++;
423
+ if (currentChunk < chunks) {
424
+ loadNext();
425
+ }
426
+ else {
427
+ resolve({
428
+ currentChunk,
429
+ data: spark.end(),
430
+ });
431
+ }
432
+ }
433
+ loadNext();
434
+ });
435
+ }
436
+ export const logger = (ctx) => ({
437
+ verbose: (...args) => {
438
+ if (ctx.options.logging)
439
+ console.log("\x1b[35m🚀 VERBOSE\x1b[0m", ...args);
440
+ },
441
+ info: (...args) => {
442
+ if (ctx.options.logging)
443
+ console.log("\x1b[34mINFO\x1b[0m", ...args);
444
+ },
445
+ warn: (...args) => {
446
+ if (ctx.options.logging)
447
+ console.log("\x1b[33mWARN\x1b[0m", ...args);
448
+ },
449
+ error: (...args) => {
450
+ if (ctx.options.logging)
451
+ console.log("\x1b[31mERROR\x1b[0m", ...args);
452
+ },
453
+ success: (...args) => {
454
+ if (ctx.options.logging)
455
+ console.log("\x1b[32mSUCCESS\x1b[0m", ...args);
456
+ },
457
+ timestamp: (...args) => {
458
+ const now = new Date().toISOString();
459
+ if (ctx.options.logging)
460
+ console.log(`\x1b[90m[${now}]\x1b[0m`, ...args);
461
+ },
462
+ });
463
+ export function getClientMessageType(msgType) {
464
+ if (msgType === "webchat")
465
+ return 1;
466
+ if (msgType === "chat.voice")
467
+ return 31;
468
+ if (msgType === "chat.photo")
469
+ return 32;
470
+ if (msgType === "chat.sticker")
471
+ return 36;
472
+ if (msgType === "chat.doodle")
473
+ return 37;
474
+ if (msgType === "chat.recommended")
475
+ return 38;
476
+ if (msgType === "chat.link")
477
+ return 38; // don't know || if (msgType === "chat.link") return 1;
478
+ if (msgType === "chat.video.msg")
479
+ return 44; // not sure
480
+ if (msgType === "share.file")
481
+ return 46;
482
+ if (msgType === "chat.gif")
483
+ return 49;
484
+ if (msgType === "chat.location.new")
485
+ return 43;
486
+ return 1;
487
+ }
488
+ export function strPadLeft(e, t, n) {
489
+ const a = (e = "" + e).length;
490
+ return a === n ? e : a > n ? e.slice(-n) : t.repeat(n - a) + e;
491
+ }
492
+ export function formatTime(format, timestamp = Date.now()) {
493
+ const date = new Date(timestamp);
494
+ // using lib Intl
495
+ const options = {
496
+ year: "numeric",
497
+ month: "2-digit",
498
+ day: "2-digit",
499
+ hour: "2-digit",
500
+ minute: "2-digit",
501
+ second: "2-digit",
502
+ // hour12: false, // true or false is same <(")
503
+ };
504
+ const formatted = new Intl.DateTimeFormat("vi-VN", options).format(date);
505
+ if (format.includes("%H") || format.includes("%d")) {
506
+ return format
507
+ .replace("%H", date.getHours().toString().padStart(2, "0"))
508
+ .replace("%M", date.getMinutes().toString().padStart(2, "0"))
509
+ .replace("%S", date.getSeconds().toString().padStart(2, "0"))
510
+ .replace("%d", date.getDate().toString().padStart(2, "0"))
511
+ .replace("%m", (date.getMonth() + 1).toString().padStart(2, "0"))
512
+ .replace("%Y", date.getFullYear().toString());
513
+ }
514
+ return formatted;
515
+ }
516
+ export function getFullTimeFromMillisecond(e) {
517
+ const t = new Date(e);
518
+ return (strPadLeft(t.getHours(), "0", 2) +
519
+ ":" +
520
+ strPadLeft(t.getMinutes(), "0", 2) +
521
+ " " +
522
+ strPadLeft(t.getDate(), "0", 2) +
523
+ "/" +
524
+ strPadLeft(t.getMonth() + 1, "0", 2) +
525
+ "/" +
526
+ t.getFullYear());
527
+ }
528
+ export function getFileExtension(e) {
529
+ return path.extname(e).slice(1);
530
+ }
531
+ export function getFileName(e) {
532
+ return path.basename(e);
533
+ }
534
+ export function removeUndefinedKeys(e) {
535
+ for (const t in e)
536
+ if (e[t] === undefined)
537
+ delete e[t];
538
+ return e;
539
+ }
540
+ export function getGroupEventType(act) {
541
+ if (act == "join_request")
542
+ return GroupEventType.JOIN_REQUEST;
543
+ if (act == "join")
544
+ return GroupEventType.JOIN;
545
+ if (act == "leave")
546
+ return GroupEventType.LEAVE;
547
+ if (act == "remove_member")
548
+ return GroupEventType.REMOVE_MEMBER;
549
+ if (act == "block_member")
550
+ return GroupEventType.BLOCK_MEMBER;
551
+ if (act == "update_setting")
552
+ return GroupEventType.UPDATE_SETTING;
553
+ if (act == "update_avatar")
554
+ return GroupEventType.UPDATE_AVATAR;
555
+ if (act == "update")
556
+ return GroupEventType.UPDATE;
557
+ if (act == "new_link")
558
+ return GroupEventType.NEW_LINK;
559
+ if (act == "add_admin")
560
+ return GroupEventType.ADD_ADMIN;
561
+ if (act == "remove_admin")
562
+ return GroupEventType.REMOVE_ADMIN;
563
+ if (act == "new_pin_topic")
564
+ return GroupEventType.NEW_PIN_TOPIC;
565
+ if (act == "update_pin_topic")
566
+ return GroupEventType.UPDATE_PIN_TOPIC;
567
+ if (act == "update_topic")
568
+ return GroupEventType.UPDATE_TOPIC;
569
+ if (act == "update_board")
570
+ return GroupEventType.UPDATE_BOARD;
571
+ if (act == "remove_board")
572
+ return GroupEventType.REMOVE_BOARD;
573
+ if (act == "reorder_pin_topic")
574
+ return GroupEventType.REORDER_PIN_TOPIC;
575
+ if (act == "unpin_topic")
576
+ return GroupEventType.UNPIN_TOPIC;
577
+ if (act == "remove_topic")
578
+ return GroupEventType.REMOVE_TOPIC;
579
+ if (act == "accept_remind")
580
+ return GroupEventType.ACCEPT_REMIND;
581
+ if (act == "reject_remind")
582
+ return GroupEventType.REJECT_REMIND;
583
+ if (act == "remind_topic")
584
+ return GroupEventType.REMIND_TOPIC;
585
+ return GroupEventType.UNKNOWN;
586
+ }
587
+ export function getFriendEventType(act) {
588
+ if (act == "add")
589
+ return FriendEventType.ADD;
590
+ if (act == "remove")
591
+ return FriendEventType.REMOVE;
592
+ if (act == "block")
593
+ return FriendEventType.BLOCK;
594
+ if (act == "unblock")
595
+ return FriendEventType.UNBLOCK;
596
+ if (act == "block_call")
597
+ return FriendEventType.BLOCK_CALL;
598
+ if (act == "unblock_call")
599
+ return FriendEventType.UNBLOCK_CALL;
600
+ if (act == "req_v2")
601
+ return FriendEventType.REQUEST;
602
+ if (act == "reject")
603
+ return FriendEventType.REJECT_REQUEST;
604
+ if (act == "undo_req")
605
+ return FriendEventType.UNDO_REQUEST;
606
+ if (act == "seen_fr_req")
607
+ return FriendEventType.SEEN_FRIEND_REQUEST;
608
+ if (act == "pin_unpin")
609
+ return FriendEventType.PIN_UNPIN;
610
+ if (act == "pin_create")
611
+ return FriendEventType.PIN_CREATE;
612
+ return FriendEventType.UNKNOWN;
613
+ }
614
+ export async function handleZaloResponse(ctx, response, isEncrypted = true) {
615
+ const result = {
616
+ data: null,
617
+ error: null,
618
+ };
619
+ if (!response.ok) {
620
+ result.error = {
621
+ message: "Request failed with status code " + response.status,
622
+ };
623
+ return result;
624
+ }
625
+ try {
626
+ const jsonData = await response.json();
627
+ if (jsonData.error_code != 0) {
628
+ result.error = {
629
+ message: jsonData.error_message,
630
+ code: jsonData.error_code,
631
+ };
632
+ return result;
633
+ }
634
+ const decodedData = isEncrypted ? JSON.parse(decodeAES(ctx.secretKey, jsonData.data)) : jsonData;
635
+ if (decodedData.error_code != 0) {
636
+ result.error = {
637
+ message: decodedData.error_message,
638
+ code: decodedData.error_code,
639
+ };
640
+ return result;
641
+ }
642
+ result.data = decodedData.data;
643
+ }
644
+ catch (error) {
645
+ logger(ctx).error("Failed to parse response data:", error);
646
+ result.error = {
647
+ message: "Failed to parse response data",
648
+ };
649
+ }
650
+ return result;
651
+ }
652
+ export async function resolveResponse(ctx, res, cb, isEncrypted) {
653
+ const result = await handleZaloResponse(ctx, res, isEncrypted);
654
+ if (result.error)
655
+ throw new ZaloApiError(result.error.message, result.error.code);
656
+ if (cb)
657
+ return cb(result);
658
+ return result.data;
659
+ }
660
+ export function apiFactory() {
661
+ return (callback) => {
662
+ return (ctx, api) => {
663
+ if (!isContextSession(ctx))
664
+ throw new ZaloApiError("Invalid context " + JSON.stringify(ctx, null, 2));
665
+ const utils = {
666
+ makeURL(baseURL, params, apiVersion) {
667
+ return makeURL(ctx, baseURL, params, apiVersion);
668
+ },
669
+ encodeAES(data, t) {
670
+ return encodeAES(ctx.secretKey, data, t);
671
+ },
672
+ request(url, options, raw) {
673
+ return request(ctx, url, options, raw);
674
+ },
675
+ logger: logger(ctx),
676
+ resolve: (res, cb, isEncrypted) => resolveResponse(ctx, res, cb, isEncrypted),
677
+ };
678
+ return callback(api, ctx, utils);
679
+ };
680
+ };
681
+ }
682
+ export function generateZaloUUID(userAgent) {
683
+ return crypto.randomUUID() + "-" + cryptojs.MD5(userAgent).toString();
684
+ }
685
+ /**
686
+ * Encrypts a 4-digit PIN to a 32-character hex string
687
+ * @param pin 4-digit PIN number
688
+ * @returns 32-character hex string
689
+ */
690
+ export function encryptPin(pin) {
691
+ return crypto.createHash("md5").update(pin).digest("hex");
692
+ }
693
+ /**
694
+ * Decrypts a 32-character hex string back to 4-digit PIN
695
+ * Note: This is a one-way hash, so we can only verify if a PIN matches the hash
696
+ * @param encryptedPin 32-character hex string
697
+ * @param pin 4-digit PIN to verify
698
+ * @returns true if the PIN matches the hash
699
+ *
700
+ * @example
701
+ * const encryptedPin = (await api.getHiddenConversations()).pin;
702
+ * checking pin created..
703
+ * const isValid = validatePin(encryptedPin, "1234"); // true if pin created is 1234
704
+ * const isInvalid = validatePin(encryptedPin, "5678"); // false if not pin created is 5678
705
+ */
706
+ export function validatePin(encryptedPin, pin) {
707
+ const hash = crypto.createHash("md5").update(pin).digest("hex");
708
+ return hash === encryptedPin;
709
+ }
710
+ /**
711
+ * Converts a hex color code to a negative color number used by Zalo API
712
+ * @param hex Hex color code (e.g. '#00FF00' or '00FF00')
713
+ * @returns Negative color number (e.g. -16711936)
714
+ *
715
+ * @example
716
+ * const negativeColor = hexToNegativeColor('#00FF00'); // Result: -16711936
717
+ */
718
+ export function hexToNegativeColor(hex) {
719
+ if (!hex.startsWith("#")) {
720
+ hex = "#" + hex;
721
+ }
722
+ // rgb no alpha
723
+ // const decimal = parseInt(hex.slice(1), 16);
724
+ // return decimal - 4294967296;
725
+ // rgb with alpha
726
+ let hexValue = hex.slice(1);
727
+ if (hexValue.length === 6) {
728
+ hexValue = "FF" + hexValue;
729
+ }
730
+ const decimal = parseInt(hexValue, 16);
731
+ return decimal > 0x7fffffff ? decimal - 4294967296 : decimal;
732
+ }
733
+ /**
734
+ * Converts a negative color number from Zalo API to hex color code
735
+ * @param negativeColor Negative color number (e.g. -16711936)
736
+ * @returns Hex color code (e.g. '#00FF00')
737
+ *
738
+ * @example
739
+ * const hexColor = negativeColorToHex(-16711936); // Result: '#00FF00'
740
+ */
741
+ export function negativeColorToHex(negativeColor) {
742
+ // Add 2^32 to get positive number
743
+ const positiveColor = negativeColor + 4294967296;
744
+ // return "#" + positiveColor.toString(16).padStart(6, "0"); // rgb no alpha
745
+ return "#" + positiveColor.toString(16).slice(-6).padStart(6, "0"); // rgb with alpha
746
+ }