zalo-api-sdk 1.0.0

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