zalo-toolkit 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.
- package/dist/Errors/ZaloApiError.d.ts +4 -0
- package/dist/Errors/ZaloApiError.js +7 -0
- package/dist/Errors/ZaloApiLoginQRAborted.d.ts +4 -0
- package/dist/Errors/ZaloApiLoginQRAborted.js +7 -0
- package/dist/Errors/ZaloApiLoginQRDeclined.d.ts +4 -0
- package/dist/Errors/ZaloApiLoginQRDeclined.js +7 -0
- package/dist/Errors/ZaloApiMissingImageMetadataGetter.d.ts +4 -0
- package/dist/Errors/ZaloApiMissingImageMetadataGetter.js +7 -0
- package/dist/Errors/index.d.ts +4 -0
- package/dist/Errors/index.js +4 -0
- package/dist/apis/acceptFriendRequest.d.ts +2 -0
- package/dist/apis/acceptFriendRequest.js +28 -0
- package/dist/apis/addGroupBlockedMember.d.ts +2 -0
- package/dist/apis/addGroupBlockedMember.js +28 -0
- package/dist/apis/addGroupDeputy.d.ts +2 -0
- package/dist/apis/addGroupDeputy.js +31 -0
- package/dist/apis/addPollOptions.d.ts +14 -0
- package/dist/apis/addPollOptions.js +26 -0
- package/dist/apis/addQuickMessage.d.ts +11 -0
- package/dist/apis/addQuickMessage.js +60 -0
- package/dist/apis/addReaction.d.ts +19 -0
- package/dist/apis/addReaction.js +292 -0
- package/dist/apis/addUnreadMark.d.ts +8 -0
- package/dist/apis/addUnreadMark.js +52 -0
- package/dist/apis/addUserToGroup.d.ts +5 -0
- package/dist/apis/addUserToGroup.js +34 -0
- package/dist/apis/blockUser.d.ts +2 -0
- package/dist/apis/blockUser.js +28 -0
- package/dist/apis/blockViewFeed.d.ts +2 -0
- package/dist/apis/blockViewFeed.js +30 -0
- package/dist/apis/changeAccountAvatar.d.ts +2 -0
- package/dist/apis/changeAccountAvatar.js +51 -0
- package/dist/apis/changeFriendAlias.d.ts +2 -0
- package/dist/apis/changeFriendAlias.js +27 -0
- package/dist/apis/changeGroupAvatar.d.ts +2 -0
- package/dist/apis/changeGroupAvatar.js +42 -0
- package/dist/apis/changeGroupName.d.ts +4 -0
- package/dist/apis/changeGroupName.js +32 -0
- package/dist/apis/changeGroupOwner.d.ts +4 -0
- package/dist/apis/changeGroupOwner.js +31 -0
- package/dist/apis/createAutoReply.d.ts +14 -0
- package/dist/apis/createAutoReply.js +37 -0
- package/dist/apis/createCatalog.d.ts +7 -0
- package/dist/apis/createCatalog.js +29 -0
- package/dist/apis/createGroup.d.ts +22 -0
- package/dist/apis/createGroup.js +43 -0
- package/dist/apis/createNote.d.ts +7 -0
- package/dist/apis/createNote.js +47 -0
- package/dist/apis/createPoll.d.ts +55 -0
- package/dist/apis/createPoll.js +40 -0
- package/dist/apis/createProductCatalog.d.ts +23 -0
- package/dist/apis/createProductCatalog.js +50 -0
- package/dist/apis/createReminder.d.ts +12 -0
- package/dist/apis/createReminder.js +63 -0
- package/dist/apis/custom.d.ts +9 -0
- package/dist/apis/custom.js +15 -0
- package/dist/apis/deleteAutoReply.d.ts +5 -0
- package/dist/apis/deleteAutoReply.js +29 -0
- package/dist/apis/deleteAvatar.d.ts +9 -0
- package/dist/apis/deleteAvatar.js +27 -0
- package/dist/apis/deleteCatalog.d.ts +2 -0
- package/dist/apis/deleteCatalog.js +28 -0
- package/dist/apis/deleteChat.d.ts +19 -0
- package/dist/apis/deleteChat.js +50 -0
- package/dist/apis/deleteGroupInviteBox.d.ts +9 -0
- package/dist/apis/deleteGroupInviteBox.js +27 -0
- package/dist/apis/deleteMessage.d.ts +14 -0
- package/dist/apis/deleteMessage.js +52 -0
- package/dist/apis/deleteProductCatalog.d.ts +10 -0
- package/dist/apis/deleteProductCatalog.js +31 -0
- package/dist/apis/disableGroupLink.d.ts +2 -0
- package/dist/apis/disableGroupLink.js +24 -0
- package/dist/apis/disperseGroup.d.ts +2 -0
- package/dist/apis/disperseGroup.js +28 -0
- package/dist/apis/editNote.d.ts +17 -0
- package/dist/apis/editNote.js +46 -0
- package/dist/apis/editReminder.d.ts +13 -0
- package/dist/apis/editReminder.js +61 -0
- package/dist/apis/enableGroupLink.d.ts +6 -0
- package/dist/apis/enableGroupLink.js +25 -0
- package/dist/apis/fetchAccountInfo.d.ts +3 -0
- package/dist/apis/fetchAccountInfo.js +10 -0
- package/dist/apis/findUser.d.ts +15 -0
- package/dist/apis/findUser.js +40 -0
- package/dist/apis/forwardAttachment.d.ts +16 -0
- package/dist/apis/forwardAttachment.js +80 -0
- package/dist/apis/forwardMessage.d.ts +33 -0
- package/dist/apis/forwardMessage.js +119 -0
- package/dist/apis/getAliasList.d.ts +8 -0
- package/dist/apis/getAliasList.js +28 -0
- package/dist/apis/getAllFriends.d.ts +3 -0
- package/dist/apis/getAllFriends.js +32 -0
- package/dist/apis/getAllGroups.d.ts +7 -0
- package/dist/apis/getAllGroups.js +10 -0
- package/dist/apis/getArchivedChatList.d.ts +5 -0
- package/dist/apis/getArchivedChatList.js +23 -0
- package/dist/apis/getAutoDeleteChat.d.ts +9 -0
- package/dist/apis/getAutoDeleteChat.js +21 -0
- package/dist/apis/getAutoReplyList.d.ts +6 -0
- package/dist/apis/getAutoReplyList.js +24 -0
- package/dist/apis/getAvatarList.d.ts +12 -0
- package/dist/apis/getAvatarList.js +28 -0
- package/dist/apis/getBizAccount.d.ts +24 -0
- package/dist/apis/getBizAccount.js +27 -0
- package/dist/apis/getCatalogList.d.ts +18 -0
- package/dist/apis/getCatalogList.js +32 -0
- package/dist/apis/getContext.d.ts +1 -0
- package/dist/apis/getContext.js +4 -0
- package/dist/apis/getCookie.d.ts +1 -0
- package/dist/apis/getCookie.js +9 -0
- package/dist/apis/getFriendBoardList.d.ts +5 -0
- package/dist/apis/getFriendBoardList.js +26 -0
- package/dist/apis/getFriendOnlines.d.ts +10 -0
- package/dist/apis/getFriendOnlines.js +35 -0
- package/dist/apis/getFriendRecommendations.d.ts +42 -0
- package/dist/apis/getFriendRecommendations.js +27 -0
- package/dist/apis/getFriendRequestStatus.d.ts +8 -0
- package/dist/apis/getFriendRequestStatus.js +25 -0
- package/dist/apis/getGroupBlockedMember.d.ts +23 -0
- package/dist/apis/getGroupBlockedMember.js +29 -0
- package/dist/apis/getGroupInfo.d.ts +16 -0
- package/dist/apis/getGroupInfo.js +32 -0
- package/dist/apis/getGroupInviteBoxInfo.d.ts +32 -0
- package/dist/apis/getGroupInviteBoxInfo.js +38 -0
- package/dist/apis/getGroupInviteBoxList.d.ts +38 -0
- package/dist/apis/getGroupInviteBoxList.js +31 -0
- package/dist/apis/getGroupLinkDetail.d.ts +9 -0
- package/dist/apis/getGroupLinkDetail.js +25 -0
- package/dist/apis/getGroupLinkInfo.d.ts +34 -0
- package/dist/apis/getGroupLinkInfo.js +28 -0
- package/dist/apis/getGroupMembersInfo.d.ts +17 -0
- package/dist/apis/getGroupMembersInfo.js +24 -0
- package/dist/apis/getHiddenConversations.d.ts +11 -0
- package/dist/apis/getHiddenConversations.js +23 -0
- package/dist/apis/getLabels.d.ts +7 -0
- package/dist/apis/getLabels.js +28 -0
- package/dist/apis/getLastMessage.d.ts +9 -0
- package/dist/apis/getLastMessage.js +20 -0
- package/dist/apis/getListBoard.d.ts +21 -0
- package/dist/apis/getListBoard.js +45 -0
- package/dist/apis/getListReminder.d.ts +28 -0
- package/dist/apis/getListReminder.js +47 -0
- package/dist/apis/getMute.d.ts +13 -0
- package/dist/apis/getMute.js +22 -0
- package/dist/apis/getOwnId.d.ts +1 -0
- package/dist/apis/getOwnId.js +4 -0
- package/dist/apis/getPendingGroupMembers.d.ts +11 -0
- package/dist/apis/getPendingGroupMembers.js +27 -0
- package/dist/apis/getPinConversations.d.ts +5 -0
- package/dist/apis/getPinConversations.js +22 -0
- package/dist/apis/getPollDetail.d.ts +3 -0
- package/dist/apis/getPollDetail.js +30 -0
- package/dist/apis/getProductCatalogList.d.ts +20 -0
- package/dist/apis/getProductCatalogList.js +33 -0
- package/dist/apis/getQR.d.ts +4 -0
- package/dist/apis/getQR.js +29 -0
- package/dist/apis/getQuickMessageList.d.ts +7 -0
- package/dist/apis/getQuickMessageList.js +24 -0
- package/dist/apis/getRecommendFriends.d.ts +40 -0
- package/dist/apis/getRecommendFriends.js +20 -0
- package/dist/apis/getRelatedFriendGroup.d.ts +6 -0
- package/dist/apis/getRelatedFriendGroup.js +30 -0
- package/dist/apis/getReminder.d.ts +3 -0
- package/dist/apis/getReminder.js +25 -0
- package/dist/apis/getReminderResponses.d.ts +5 -0
- package/dist/apis/getReminderResponses.js +24 -0
- package/dist/apis/getSentFriendRequest.d.ts +18 -0
- package/dist/apis/getSentFriendRequest.js +24 -0
- package/dist/apis/getSettings.d.ts +3 -0
- package/dist/apis/getSettings.js +20 -0
- package/dist/apis/getStickers.d.ts +1 -0
- package/dist/apis/getStickers.js +40 -0
- package/dist/apis/getStickersDetail.d.ts +24 -0
- package/dist/apis/getStickersDetail.js +40 -0
- package/dist/apis/getUnreadMark.d.ts +14 -0
- package/dist/apis/getUnreadMark.js +30 -0
- package/dist/apis/getUserInfo.d.ts +8 -0
- package/dist/apis/getUserInfo.js +42 -0
- package/dist/apis/inviteUserToGroups.d.ts +10 -0
- package/dist/apis/inviteUserToGroups.js +30 -0
- package/dist/apis/joinGroupInviteBox.d.ts +2 -0
- package/dist/apis/joinGroupInviteBox.js +25 -0
- package/dist/apis/joinGroupLink.d.ts +2 -0
- package/dist/apis/joinGroupLink.js +27 -0
- package/dist/apis/keepAlive.d.ts +4 -0
- package/dist/apis/keepAlive.js +22 -0
- package/dist/apis/lastOnline.d.ts +7 -0
- package/dist/apis/lastOnline.js +26 -0
- package/dist/apis/leaveGroup.d.ts +4 -0
- package/dist/apis/leaveGroup.js +33 -0
- package/dist/apis/listen.d.ts +141 -0
- package/dist/apis/listen.js +822 -0
- package/dist/apis/lockPoll.d.ts +2 -0
- package/dist/apis/lockPoll.js +28 -0
- package/dist/apis/login.d.ts +3 -0
- package/dist/apis/login.js +96 -0
- package/dist/apis/loginQR.d.ts +42 -0
- package/dist/apis/loginQR.js +274 -0
- package/dist/apis/parseLink.d.ts +21 -0
- package/dist/apis/parseLink.js +27 -0
- package/dist/apis/rejectFriendRequest.d.ts +2 -0
- package/dist/apis/rejectFriendRequest.js +27 -0
- package/dist/apis/removeFriend.d.ts +2 -0
- package/dist/apis/removeFriend.js +28 -0
- package/dist/apis/removeFriendAlias.d.ts +2 -0
- package/dist/apis/removeFriendAlias.js +24 -0
- package/dist/apis/removeGroupBlockedMember.d.ts +2 -0
- package/dist/apis/removeGroupBlockedMember.js +28 -0
- package/dist/apis/removeGroupDeputy.d.ts +2 -0
- package/dist/apis/removeGroupDeputy.js +30 -0
- package/dist/apis/removeQuickMessage.d.ts +5 -0
- package/dist/apis/removeQuickMessage.js +27 -0
- package/dist/apis/removeReminder.d.ts +3 -0
- package/dist/apis/removeReminder.js +40 -0
- package/dist/apis/removeUnreadMark.d.ts +8 -0
- package/dist/apis/removeUnreadMark.js +50 -0
- package/dist/apis/removeUserFromGroup.d.ts +4 -0
- package/dist/apis/removeUserFromGroup.js +34 -0
- package/dist/apis/resetHiddenConversPin.d.ts +2 -0
- package/dist/apis/resetHiddenConversPin.js +20 -0
- package/dist/apis/reuseAvatar.d.ts +2 -0
- package/dist/apis/reuseAvatar.js +26 -0
- package/dist/apis/reviewPendingMemberRequest.d.ts +14 -0
- package/dist/apis/reviewPendingMemberRequest.js +38 -0
- package/dist/apis/sendBankCard.d.ts +9 -0
- package/dist/apis/sendBankCard.js +37 -0
- package/dist/apis/sendCard.d.ts +10 -0
- package/dist/apis/sendCard.js +59 -0
- package/dist/apis/sendDeliveredEvent.d.ts +16 -0
- package/dist/apis/sendDeliveredEvent.js +55 -0
- package/dist/apis/sendFriendRequest.d.ts +2 -0
- package/dist/apis/sendFriendRequest.js +39 -0
- package/dist/apis/sendLink.d.ts +10 -0
- package/dist/apis/sendLink.js +57 -0
- package/dist/apis/sendMessage.d.ts +100 -0
- package/dist/apis/sendMessage.js +437 -0
- package/dist/apis/sendReport.d.ts +17 -0
- package/dist/apis/sendReport.js +53 -0
- package/dist/apis/sendSeenEvent.d.ts +16 -0
- package/dist/apis/sendSeenEvent.js +63 -0
- package/dist/apis/sendSticker.d.ts +10 -0
- package/dist/apis/sendSticker.js +56 -0
- package/dist/apis/sendTypingEvent.d.ts +5 -0
- package/dist/apis/sendTypingEvent.js +33 -0
- package/dist/apis/sendVideo.d.ts +35 -0
- package/dist/apis/sendVideo.js +118 -0
- package/dist/apis/sendVoice.d.ts +12 -0
- package/dist/apis/sendVoice.js +73 -0
- package/dist/apis/setArchivedConversations.d.ts +10 -0
- package/dist/apis/setArchivedConversations.js +34 -0
- package/dist/apis/setHiddenConversations.d.ts +3 -0
- package/dist/apis/setHiddenConversations.js +39 -0
- package/dist/apis/setMute.d.ts +20 -0
- package/dist/apis/setMute.js +67 -0
- package/dist/apis/setPinnedConversations.d.ts +3 -0
- package/dist/apis/setPinnedConversations.js +34 -0
- package/dist/apis/sharePoll.d.ts +2 -0
- package/dist/apis/sharePoll.js +28 -0
- package/dist/apis/unblockUser.d.ts +2 -0
- package/dist/apis/unblockUser.js +28 -0
- package/dist/apis/undo.d.ts +9 -0
- package/dist/apis/undo.js +42 -0
- package/dist/apis/undoFriendRequest.d.ts +2 -0
- package/dist/apis/undoFriendRequest.js +27 -0
- package/dist/apis/updateActiveStatus.d.ts +4 -0
- package/dist/apis/updateActiveStatus.js +27 -0
- package/dist/apis/updateAutoDeleteChat.d.ts +9 -0
- package/dist/apis/updateAutoDeleteChat.js +40 -0
- package/dist/apis/updateAutoReply.d.ts +15 -0
- package/dist/apis/updateAutoReply.js +38 -0
- package/dist/apis/updateCatalog.d.ts +11 -0
- package/dist/apis/updateCatalog.js +30 -0
- package/dist/apis/updateGroupSettings.d.ts +40 -0
- package/dist/apis/updateGroupSettings.js +43 -0
- package/dist/apis/updateHiddenConversPin.d.ts +2 -0
- package/dist/apis/updateHiddenConversPin.js +30 -0
- package/dist/apis/updateLabels.d.ts +15 -0
- package/dist/apis/updateLabels.js +34 -0
- package/dist/apis/updateLang.d.ts +6 -0
- package/dist/apis/updateLang.js +30 -0
- package/dist/apis/updateProductCatalog.d.ts +25 -0
- package/dist/apis/updateProductCatalog.js +51 -0
- package/dist/apis/updateProfile.d.ts +20 -0
- package/dist/apis/updateProfile.js +43 -0
- package/dist/apis/updateQuickMessage.d.ts +11 -0
- package/dist/apis/updateQuickMessage.js +61 -0
- package/dist/apis/updateSettings.d.ts +16 -0
- package/dist/apis/updateSettings.js +90 -0
- package/dist/apis/uploadAttachment.d.ts +51 -0
- package/dist/apis/uploadAttachment.js +195 -0
- package/dist/apis/uploadProductPhoto.d.ts +13 -0
- package/dist/apis/uploadProductPhoto.js +45 -0
- package/dist/apis/votePoll.d.ts +5 -0
- package/dist/apis/votePoll.js +29 -0
- package/dist/apis.d.ts +293 -0
- package/dist/apis.js +287 -0
- package/dist/cjs/Errors/ZaloApiError.cjs +11 -0
- package/dist/cjs/Errors/ZaloApiLoginQRAborted.cjs +12 -0
- package/dist/cjs/Errors/ZaloApiLoginQRDeclined.cjs +12 -0
- package/dist/cjs/Errors/ZaloApiMissingImageMetadataGetter.cjs +12 -0
- package/dist/cjs/apis/login.cjs +102 -0
- package/dist/cjs/apis/loginQR.cjs +282 -0
- package/dist/cjs/apis/reviewPendingMemberRequest.cjs +21 -0
- package/dist/cjs/apis/sendMessage.cjs +44 -0
- package/dist/cjs/apis/sendReport.cjs +28 -0
- package/dist/cjs/apis/setMute.cjs +33 -0
- package/dist/cjs/apis/updateAutoDeleteChat.cjs +28 -0
- package/dist/cjs/apis/updateLang.cjs +19 -0
- package/dist/cjs/apis/updateSettings.cjs +29 -0
- package/dist/cjs/context.cjs +19 -0
- package/dist/cjs/index.cjs +142 -0
- package/dist/cjs/models/AutoReply.cjs +9 -0
- package/dist/cjs/models/Board.cjs +8 -0
- package/dist/cjs/models/DeliveredMessage.cjs +23 -0
- package/dist/cjs/models/Enum.cjs +253 -0
- package/dist/cjs/models/FriendEvent.cjs +87 -0
- package/dist/cjs/models/Group.cjs +13 -0
- package/dist/cjs/models/GroupEvent.cjs +94 -0
- package/dist/cjs/models/Listen.cjs +134 -0
- package/dist/cjs/models/Message.cjs +40 -0
- package/dist/cjs/models/Reaction.cjs +74 -0
- package/dist/cjs/models/Reminder.cjs +9 -0
- package/dist/cjs/models/SeenMessage.cjs +23 -0
- package/dist/cjs/models/Typing.cjs +23 -0
- package/dist/cjs/models/Undo.cjs +16 -0
- package/dist/cjs/models/ZBusiness.cjs +39 -0
- package/dist/cjs/utils.cjs +320 -0
- package/dist/cjs/zalo.cjs +127 -0
- package/dist/context.d.ts +199 -0
- package/dist/context.js +27 -0
- package/dist/core/enums/common.d.ts +11 -0
- package/dist/core/enums/common.js +12 -0
- package/dist/core/interfaces/common.d.ts +7 -0
- package/dist/core/interfaces/common.js +1 -0
- package/dist/core/utils/deserializer.d.ts +4 -0
- package/dist/core/utils/deserializer.js +25 -0
- package/dist/core/utils/index.d.ts +2 -0
- package/dist/core/utils/index.js +28 -0
- package/dist/core/utils/serializer.d.ts +9 -0
- package/dist/core/utils/serializer.js +24 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +12 -0
- package/dist/models/AutoReply.d.ts +20 -0
- package/dist/models/AutoReply.js +7 -0
- package/dist/models/Board.d.ts +60 -0
- package/dist/models/Board.js +6 -0
- package/dist/models/Catalog.d.ts +16 -0
- package/dist/models/Catalog.js +1 -0
- package/dist/models/DeliveredMessage.d.ts +27 -0
- package/dist/models/DeliveredMessage.js +17 -0
- package/dist/models/Enum.d.ts +247 -0
- package/dist/models/Enum.js +251 -0
- package/dist/models/FriendEvent.d.ts +107 -0
- package/dist/models/FriendEvent.js +83 -0
- package/dist/models/Group.d.ts +125 -0
- package/dist/models/Group.js +11 -0
- package/dist/models/GroupEvent.d.ts +178 -0
- package/dist/models/GroupEvent.js +90 -0
- package/dist/models/Label.d.ts +10 -0
- package/dist/models/Label.js +1 -0
- package/dist/models/Listen.d.ts +186 -0
- package/dist/models/Listen.js +194 -0
- package/dist/models/Message.d.ts +97 -0
- package/dist/models/Message.js +34 -0
- package/dist/models/Mute.d.ts +10 -0
- package/dist/models/Mute.js +1 -0
- package/dist/models/ProductCatalog.d.ts +17 -0
- package/dist/models/ProductCatalog.js +1 -0
- package/dist/models/QuickMessage.d.ts +25 -0
- package/dist/models/QuickMessage.js +1 -0
- package/dist/models/Reaction.d.ts +85 -0
- package/dist/models/Reaction.js +70 -0
- package/dist/models/Reminder.d.ts +51 -0
- package/dist/models/Reminder.js +7 -0
- package/dist/models/SeenMessage.d.ts +26 -0
- package/dist/models/SeenMessage.js +17 -0
- package/dist/models/Typing.d.ts +24 -0
- package/dist/models/Typing.js +17 -0
- package/dist/models/Undo.d.ts +34 -0
- package/dist/models/Undo.js +12 -0
- package/dist/models/User.d.ts +49 -0
- package/dist/models/User.js +1 -0
- package/dist/models/ZBusiness.d.ts +22 -0
- package/dist/models/ZBusiness.js +35 -0
- package/dist/models/index.d.ts +19 -0
- package/dist/models/index.js +19 -0
- package/dist/socket/config-socket.d.ts +38 -0
- package/dist/socket/config-socket.js +202 -0
- package/dist/utils.d.ts +190 -0
- package/dist/utils.js +749 -0
- package/dist/zalo.d.ts +64 -0
- package/dist/zalo.js +103 -0
- package/package.json +61 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cryptojs = require('crypto-js');
|
|
4
|
+
require('json-bigint');
|
|
5
|
+
var crypto = require('node:crypto');
|
|
6
|
+
require('node:fs');
|
|
7
|
+
require('node:path');
|
|
8
|
+
require('pako');
|
|
9
|
+
require('spark-md5');
|
|
10
|
+
var ToughCookie = require('tough-cookie');
|
|
11
|
+
require('sharp');
|
|
12
|
+
var ZaloApiError = require('./Errors/ZaloApiError.cjs');
|
|
13
|
+
require('./models/FriendEvent.cjs');
|
|
14
|
+
require('./models/GroupEvent.cjs');
|
|
15
|
+
|
|
16
|
+
// export const isBun = typeof Bun !== "undefined";
|
|
17
|
+
function hasOwn(obj, key) {
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get signed key for API requests.
|
|
22
|
+
*
|
|
23
|
+
* @param type
|
|
24
|
+
* @param params
|
|
25
|
+
* @returns MD5 hash
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
function getSignKey(type, params) {
|
|
29
|
+
const n = [];
|
|
30
|
+
for (const s in params) {
|
|
31
|
+
if (hasOwn(params, s)) {
|
|
32
|
+
n.push(s);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
n.sort();
|
|
36
|
+
let a = 'zsecure' + type;
|
|
37
|
+
for (let s = 0; s < n.length; s++)
|
|
38
|
+
a += params[n[s]];
|
|
39
|
+
return cryptojs.MD5(a).toString();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param baseURL
|
|
44
|
+
* @param params
|
|
45
|
+
* @param apiVersion automatically add zalo api version to url params
|
|
46
|
+
* @returns
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
function makeURL(ctx, baseURL, params = {}, apiVersion = true) {
|
|
50
|
+
const url = new URL(baseURL);
|
|
51
|
+
for (const key in params) {
|
|
52
|
+
if (hasOwn(params, key)) {
|
|
53
|
+
url.searchParams.append(key, params[key].toString());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (apiVersion) {
|
|
57
|
+
if (!url.searchParams.has('zpw_ver'))
|
|
58
|
+
url.searchParams.set('zpw_ver', ctx.API_VERSION.toString());
|
|
59
|
+
if (!url.searchParams.has('zpw_type'))
|
|
60
|
+
url.searchParams.set('zpw_type', ctx.API_TYPE.toString());
|
|
61
|
+
}
|
|
62
|
+
return url.toString();
|
|
63
|
+
}
|
|
64
|
+
class ParamsEncryptor {
|
|
65
|
+
constructor({ type, imei, firstLaunchTime }) {
|
|
66
|
+
this.zcid = null;
|
|
67
|
+
this.enc_ver = 'v2';
|
|
68
|
+
this.zcid = null;
|
|
69
|
+
this.encryptKey = null;
|
|
70
|
+
this.createZcid(type, imei, firstLaunchTime);
|
|
71
|
+
this.zcid_ext = ParamsEncryptor.randomString();
|
|
72
|
+
this.createEncryptKey();
|
|
73
|
+
}
|
|
74
|
+
getEncryptKey() {
|
|
75
|
+
if (!this.encryptKey)
|
|
76
|
+
throw new ZaloApiError.ZaloApiError("getEncryptKey: didn't create encryptKey yet");
|
|
77
|
+
return this.encryptKey;
|
|
78
|
+
}
|
|
79
|
+
createZcid(type, imei, firstLaunchTime) {
|
|
80
|
+
if (!type || !imei || !firstLaunchTime)
|
|
81
|
+
throw new ZaloApiError.ZaloApiError('createZcid: missing params');
|
|
82
|
+
const msg = `${type},${imei},${firstLaunchTime}`;
|
|
83
|
+
const s = ParamsEncryptor.encodeAES('3FC4F0D2AB50057BCE0D90D9187A22B1', msg, 'hex', true);
|
|
84
|
+
this.zcid = s;
|
|
85
|
+
}
|
|
86
|
+
createEncryptKey(e = 0) {
|
|
87
|
+
const t = (e, t) => {
|
|
88
|
+
const { even: n } = ParamsEncryptor.processStr(e), { even: a, odd: s } = ParamsEncryptor.processStr(t);
|
|
89
|
+
if (!n || !a || !s)
|
|
90
|
+
return false;
|
|
91
|
+
const i = n.slice(0, 8).join('') + a.slice(0, 12).join('') + s.reverse().slice(0, 12).join('');
|
|
92
|
+
return (this.encryptKey = i), true;
|
|
93
|
+
};
|
|
94
|
+
if (!this.zcid || !this.zcid_ext)
|
|
95
|
+
throw new ZaloApiError.ZaloApiError('createEncryptKey: zcid or zcid_ext is null');
|
|
96
|
+
try {
|
|
97
|
+
const n = cryptojs.MD5(this.zcid_ext).toString().toUpperCase();
|
|
98
|
+
if (t(n, this.zcid) || !(e < 3))
|
|
99
|
+
return !1;
|
|
100
|
+
this.createEncryptKey(e + 1);
|
|
101
|
+
}
|
|
102
|
+
catch (_a) {
|
|
103
|
+
if (e < 3)
|
|
104
|
+
this.createEncryptKey(e + 1);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
getParams() {
|
|
109
|
+
return this.zcid
|
|
110
|
+
? {
|
|
111
|
+
zcid: this.zcid,
|
|
112
|
+
zcid_ext: this.zcid_ext,
|
|
113
|
+
enc_ver: this.enc_ver,
|
|
114
|
+
}
|
|
115
|
+
: null;
|
|
116
|
+
}
|
|
117
|
+
static processStr(e) {
|
|
118
|
+
if (!e || 'string' != typeof e)
|
|
119
|
+
return {
|
|
120
|
+
even: null,
|
|
121
|
+
odd: null,
|
|
122
|
+
};
|
|
123
|
+
const [t, n] = [...e].reduce((e, t, n) => (e[n % 2].push(t), e), [[], []]);
|
|
124
|
+
return {
|
|
125
|
+
even: t,
|
|
126
|
+
odd: n,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
static randomString(e, t) {
|
|
130
|
+
const n = e || 6, a = t && e && t > e ? t : 12;
|
|
131
|
+
let s = Math.floor(Math.random() * (a - n + 1)) + n;
|
|
132
|
+
if (s > 12) {
|
|
133
|
+
let e = '';
|
|
134
|
+
for (; s > 0;) {
|
|
135
|
+
e += Math.random()
|
|
136
|
+
.toString(16)
|
|
137
|
+
.substr(2, s > 12 ? 12 : s);
|
|
138
|
+
s -= 12;
|
|
139
|
+
}
|
|
140
|
+
return e;
|
|
141
|
+
}
|
|
142
|
+
return Math.random().toString(16).substr(2, s);
|
|
143
|
+
}
|
|
144
|
+
static encodeAES(e, message, type, uppercase, s = 0) {
|
|
145
|
+
if (!message)
|
|
146
|
+
return null;
|
|
147
|
+
try {
|
|
148
|
+
{
|
|
149
|
+
const encoder = 'hex' == type ? cryptojs.enc.Hex : cryptojs.enc.Base64;
|
|
150
|
+
const key = cryptojs.enc.Utf8.parse(e);
|
|
151
|
+
const cfg = {
|
|
152
|
+
words: [0, 0, 0, 0],
|
|
153
|
+
sigBytes: 16,
|
|
154
|
+
};
|
|
155
|
+
const encrypted = cryptojs.AES.encrypt(message, key, {
|
|
156
|
+
iv: cfg,
|
|
157
|
+
mode: cryptojs.mode.CBC,
|
|
158
|
+
padding: cryptojs.pad.Pkcs7,
|
|
159
|
+
}).ciphertext.toString(encoder);
|
|
160
|
+
return uppercase ? encrypted.toUpperCase() : encrypted;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (_a) {
|
|
164
|
+
return s < 3 ? ParamsEncryptor.encodeAES(e, message, type, uppercase, s + 1) : null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function decryptResp(key, data) {
|
|
169
|
+
let n = null;
|
|
170
|
+
try {
|
|
171
|
+
n = decodeRespAES(key, data);
|
|
172
|
+
const parsed = JSON.parse(n);
|
|
173
|
+
return parsed;
|
|
174
|
+
}
|
|
175
|
+
catch (_a) {
|
|
176
|
+
return n;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function decodeRespAES(key, data) {
|
|
180
|
+
data = decodeURIComponent(data);
|
|
181
|
+
const parsedKey = cryptojs.enc.Utf8.parse(key);
|
|
182
|
+
const n = {
|
|
183
|
+
words: [0, 0, 0, 0],
|
|
184
|
+
sigBytes: 16,
|
|
185
|
+
};
|
|
186
|
+
return cryptojs.AES.decrypt({
|
|
187
|
+
ciphertext: cryptojs.enc.Base64.parse(data),
|
|
188
|
+
}, parsedKey, {
|
|
189
|
+
iv: n,
|
|
190
|
+
mode: cryptojs.mode.CBC,
|
|
191
|
+
padding: cryptojs.pad.Pkcs7,
|
|
192
|
+
}).toString(cryptojs.enc.Utf8);
|
|
193
|
+
}
|
|
194
|
+
async function getDefaultHeaders(ctx, origin = 'https://chat.zalo.me') {
|
|
195
|
+
if (!ctx.cookie)
|
|
196
|
+
throw new ZaloApiError.ZaloApiError('Cookie is not available');
|
|
197
|
+
if (!ctx.userAgent)
|
|
198
|
+
throw new ZaloApiError.ZaloApiError('User agent is not available');
|
|
199
|
+
return {
|
|
200
|
+
Accept: 'application/json, text/plain, */*',
|
|
201
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
202
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
203
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
204
|
+
Cookie: await ctx.cookie.getCookieString(origin),
|
|
205
|
+
Origin: 'https://chat.zalo.me',
|
|
206
|
+
Referer: 'https://chat.zalo.me/',
|
|
207
|
+
'User-Agent': ctx.userAgent,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async function request(ctx, url, options, raw = false) {
|
|
211
|
+
if (!ctx.cookie)
|
|
212
|
+
ctx.cookie = new ToughCookie.CookieJar();
|
|
213
|
+
const origin = new URL(url).origin;
|
|
214
|
+
const defaultHeaders = await getDefaultHeaders(ctx, origin);
|
|
215
|
+
if (!raw) {
|
|
216
|
+
if (options) {
|
|
217
|
+
options.headers = Object.assign(defaultHeaders, options.headers || {});
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
options = { headers: defaultHeaders };
|
|
221
|
+
}
|
|
222
|
+
const _options = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { agent: ctx.options.agent });
|
|
223
|
+
const response = await ctx.options.polyfill(url, _options);
|
|
224
|
+
const setCookieRaw = response.headers.get('set-cookie');
|
|
225
|
+
if (setCookieRaw && !raw) {
|
|
226
|
+
const splitCookies = setCookieRaw.split(', ');
|
|
227
|
+
for (const cookie of splitCookies) {
|
|
228
|
+
const parsed = ToughCookie.Cookie.parse(cookie);
|
|
229
|
+
try {
|
|
230
|
+
if (parsed)
|
|
231
|
+
await ctx.cookie.setCookie(parsed, parsed.domain != 'zalo.me' ? `https://${parsed.domain}` : origin);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
logger(ctx).error(error);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const redirectURL = response.headers.get('location');
|
|
239
|
+
if (redirectURL) {
|
|
240
|
+
const redirectOptions = Object.assign({}, options);
|
|
241
|
+
redirectOptions.method = 'GET';
|
|
242
|
+
if (!raw) {
|
|
243
|
+
redirectOptions.headers = new Headers(redirectOptions.headers);
|
|
244
|
+
redirectOptions.headers.set('Referer', 'https://id.zalo.me/');
|
|
245
|
+
}
|
|
246
|
+
return await request(ctx, redirectURL, redirectOptions);
|
|
247
|
+
}
|
|
248
|
+
return response;
|
|
249
|
+
}
|
|
250
|
+
const logger = (ctx) => ({
|
|
251
|
+
verbose: (...args) => {
|
|
252
|
+
if (ctx.options.logging)
|
|
253
|
+
console.log('\x1b[35m🚀 VERBOSE\x1b[0m', ...args);
|
|
254
|
+
},
|
|
255
|
+
info: (...args) => {
|
|
256
|
+
if (ctx.options.logging)
|
|
257
|
+
console.log('\x1b[34mINFO\x1b[0m', ...args);
|
|
258
|
+
},
|
|
259
|
+
warn: (...args) => {
|
|
260
|
+
if (ctx.options.logging)
|
|
261
|
+
console.log('\x1b[33mWARN\x1b[0m', ...args);
|
|
262
|
+
},
|
|
263
|
+
error: (...args) => {
|
|
264
|
+
if (ctx.options.logging)
|
|
265
|
+
console.log('\x1b[31mERROR\x1b[0m', ...args);
|
|
266
|
+
},
|
|
267
|
+
success: (...args) => {
|
|
268
|
+
if (ctx.options.logging)
|
|
269
|
+
console.log('\x1b[32mSUCCESS\x1b[0m', ...args);
|
|
270
|
+
},
|
|
271
|
+
timestamp: (...args) => {
|
|
272
|
+
const now = new Date().toISOString();
|
|
273
|
+
if (ctx.options.logging)
|
|
274
|
+
console.log(`\x1b[90m[${now}]\x1b[0m`, ...args);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
function generateZaloUUID(userAgent) {
|
|
278
|
+
return crypto.randomUUID() + '-' + cryptojs.MD5(userAgent).toString();
|
|
279
|
+
}
|
|
280
|
+
function getSecChUaPlatform(userAgent = '') {
|
|
281
|
+
const platformRegex = /\(([^)]+)\)/;
|
|
282
|
+
const platformMatch = userAgent.match(platformRegex);
|
|
283
|
+
// Kiểm tra và lấy nền tảng
|
|
284
|
+
if (platformMatch) {
|
|
285
|
+
const platform = platformMatch[1].toLowerCase();
|
|
286
|
+
let secChUaPlatform = '';
|
|
287
|
+
if (platform.includes('macintosh')) {
|
|
288
|
+
secChUaPlatform = '"macOS"';
|
|
289
|
+
}
|
|
290
|
+
else if (platform.includes('windows')) {
|
|
291
|
+
secChUaPlatform = '"Windows"';
|
|
292
|
+
}
|
|
293
|
+
else if (platform.includes('linux')) {
|
|
294
|
+
secChUaPlatform = '"Linux"';
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
secChUaPlatform = '"Unknown"';
|
|
298
|
+
}
|
|
299
|
+
return secChUaPlatform;
|
|
300
|
+
}
|
|
301
|
+
return '"Unknown"';
|
|
302
|
+
}
|
|
303
|
+
function handleQueueStatus(queueStatus) {
|
|
304
|
+
for (const key in queueStatus) {
|
|
305
|
+
delete queueStatus[key].ids;
|
|
306
|
+
}
|
|
307
|
+
return queueStatus;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
exports.ParamsEncryptor = ParamsEncryptor;
|
|
311
|
+
exports.decryptResp = decryptResp;
|
|
312
|
+
exports.generateZaloUUID = generateZaloUUID;
|
|
313
|
+
exports.getDefaultHeaders = getDefaultHeaders;
|
|
314
|
+
exports.getSecChUaPlatform = getSecChUaPlatform;
|
|
315
|
+
exports.getSignKey = getSignKey;
|
|
316
|
+
exports.handleQueueStatus = handleQueueStatus;
|
|
317
|
+
exports.hasOwn = hasOwn;
|
|
318
|
+
exports.logger = logger;
|
|
319
|
+
exports.makeURL = makeURL;
|
|
320
|
+
exports.request = request;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ToughCookie = require('tough-cookie');
|
|
4
|
+
var login = require('./apis/login.cjs');
|
|
5
|
+
var loginQR = require('./apis/loginQR.cjs');
|
|
6
|
+
var context = require('./context.cjs');
|
|
7
|
+
var ZaloApiError = require('./Errors/ZaloApiError.cjs');
|
|
8
|
+
var utils = require('./utils.cjs');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var ToughCookie__namespace = /*#__PURE__*/_interopNamespaceDefault(ToughCookie);
|
|
28
|
+
|
|
29
|
+
class Zalo {
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.enableEncryptParam = true;
|
|
33
|
+
}
|
|
34
|
+
parseCookies(cookie) {
|
|
35
|
+
var _a;
|
|
36
|
+
const cookieArr = Array.isArray(cookie) ? cookie : cookie.cookies;
|
|
37
|
+
cookieArr.forEach((e, i) => {
|
|
38
|
+
if (typeof e.domain == 'string' && e.domain.startsWith('.'))
|
|
39
|
+
cookieArr[i].domain = e.domain.slice(1);
|
|
40
|
+
});
|
|
41
|
+
const jar = new ToughCookie__namespace.CookieJar();
|
|
42
|
+
for (const each of cookieArr) {
|
|
43
|
+
try {
|
|
44
|
+
jar.setCookieSync((_a = ToughCookie__namespace.Cookie.fromJSON(Object.assign(Object.assign({}, each), { key: each.key || (each === null || each === void 0 ? void 0 : each.name) }))) !== null && _a !== void 0 ? _a : '', 'https://chat.zalo.me');
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
utils.logger({
|
|
48
|
+
options: {
|
|
49
|
+
logging: this.options.logging,
|
|
50
|
+
},
|
|
51
|
+
}).error('Failed to set cookie:', error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return jar;
|
|
55
|
+
}
|
|
56
|
+
validateParams(credentials) {
|
|
57
|
+
if (!credentials.imei || !credentials.cookie || !credentials.userAgent) {
|
|
58
|
+
throw new ZaloApiError.ZaloApiError('Missing required params');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async loginCookie(props) {
|
|
62
|
+
const { ctx, credentials, sessionId, imei, getPreviousImei } = props;
|
|
63
|
+
this.validateParams(credentials);
|
|
64
|
+
ctx.imei = credentials.imei;
|
|
65
|
+
ctx.cookie = this.parseCookies(credentials.cookie);
|
|
66
|
+
ctx.userAgent = credentials.userAgent;
|
|
67
|
+
ctx.language = credentials.language || 'vi';
|
|
68
|
+
if (imei) {
|
|
69
|
+
ctx.imei = imei;
|
|
70
|
+
}
|
|
71
|
+
let serverInfo = await login.getServerInfo(ctx, this.enableEncryptParam).catch(() => null);
|
|
72
|
+
if (typeof getPreviousImei === 'function') {
|
|
73
|
+
const previousImei = await getPreviousImei(serverInfo);
|
|
74
|
+
ctx.imei = previousImei;
|
|
75
|
+
serverInfo = await login.getServerInfo(ctx, this.enableEncryptParam).catch(() => null);
|
|
76
|
+
}
|
|
77
|
+
const loginData = await login.login(ctx, this.enableEncryptParam);
|
|
78
|
+
const loginInfo = loginData === null || loginData === void 0 ? void 0 : loginData.data;
|
|
79
|
+
if (!loginData || !loginInfo || !serverInfo)
|
|
80
|
+
throw new ZaloApiError.ZaloApiError('Đăng nhập thất bại');
|
|
81
|
+
ctx.secretKey = loginInfo.zpw_enk;
|
|
82
|
+
ctx.uid = loginInfo.uid;
|
|
83
|
+
ctx.settings = serverInfo.setttings || serverInfo.settings;
|
|
84
|
+
ctx.extraVer = serverInfo.extra_ver;
|
|
85
|
+
ctx.loginInfo = loginInfo;
|
|
86
|
+
if (!context.isContextSession(ctx))
|
|
87
|
+
throw new ZaloApiError.ZaloApiError('Khởi tạo ngữ cảnh thất bại.');
|
|
88
|
+
utils.logger(ctx).info('Logged in as', loginInfo.uid);
|
|
89
|
+
return { ctx: ctx, loginInfo: loginInfo };
|
|
90
|
+
}
|
|
91
|
+
async generateQR(options) {
|
|
92
|
+
if (!options)
|
|
93
|
+
options = {};
|
|
94
|
+
if (!options.userAgent)
|
|
95
|
+
options.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0';
|
|
96
|
+
if (!options.language)
|
|
97
|
+
options.language = 'vi';
|
|
98
|
+
const ctx = context.createContext(this.options.apiType, this.options.apiVersion);
|
|
99
|
+
Object.assign(ctx.options, this.options);
|
|
100
|
+
const resultQR = await loginQR.generateQR(ctx, options);
|
|
101
|
+
const serializedCookie = ctx.cookie.toJSON();
|
|
102
|
+
return { qrData: resultQR === null || resultQR === void 0 ? void 0 : resultQR.qrData, serializedCookie: serializedCookie, loginVersion: resultQR === null || resultQR === void 0 ? void 0 : resultQR.loginVersion };
|
|
103
|
+
}
|
|
104
|
+
async waitingScanQR(ctx, loginVersion, code) {
|
|
105
|
+
return await loginQR.waitingScan(ctx, loginVersion, code);
|
|
106
|
+
}
|
|
107
|
+
async waitingConfirm(props) {
|
|
108
|
+
const { ctx, loginVersion, code, sessionId, imei, getPreviousImei } = props;
|
|
109
|
+
const loginQRResult = await loginQR.handleWaitingConfirm(ctx, loginVersion, code);
|
|
110
|
+
if (!loginQRResult || !(ctx === null || ctx === void 0 ? void 0 : ctx.userAgent))
|
|
111
|
+
return null;
|
|
112
|
+
return this.loginCookie({
|
|
113
|
+
ctx: ctx,
|
|
114
|
+
credentials: {
|
|
115
|
+
cookie: loginQRResult.cookies,
|
|
116
|
+
imei: utils.generateZaloUUID(ctx.userAgent),
|
|
117
|
+
userAgent: ctx.userAgent,
|
|
118
|
+
language: ctx.language,
|
|
119
|
+
},
|
|
120
|
+
sessionId: sessionId,
|
|
121
|
+
imei: imei,
|
|
122
|
+
getPreviousImei: getPreviousImei,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
exports.Zalo = Zalo;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { Agent } from 'http';
|
|
2
|
+
import type { CookieJar } from 'tough-cookie';
|
|
3
|
+
type UploadEventData = {
|
|
4
|
+
fileUrl: string;
|
|
5
|
+
fileId: string;
|
|
6
|
+
};
|
|
7
|
+
export type UploadCallback = (data: UploadEventData) => unknown;
|
|
8
|
+
export type ShareFileSettings = {
|
|
9
|
+
big_file_domain_list: string[];
|
|
10
|
+
max_size_share_file_v2: number;
|
|
11
|
+
max_size_share_file_v3: number;
|
|
12
|
+
file_upload_show_icon_1GB: boolean;
|
|
13
|
+
restricted_ext: string;
|
|
14
|
+
next_file_time: number;
|
|
15
|
+
max_file: number;
|
|
16
|
+
max_size_photo: number;
|
|
17
|
+
max_size_share_file: number;
|
|
18
|
+
max_size_resize_photo: number;
|
|
19
|
+
max_size_gif: number;
|
|
20
|
+
max_size_original_photo: number;
|
|
21
|
+
chunk_size_file: number;
|
|
22
|
+
restricted_ext_file: string[];
|
|
23
|
+
};
|
|
24
|
+
export type SocketSettings = {
|
|
25
|
+
rotate_error_codes: (number | string)[];
|
|
26
|
+
retries: {
|
|
27
|
+
[key: string]: {
|
|
28
|
+
max?: number;
|
|
29
|
+
times: number[] | number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
debug: {
|
|
33
|
+
enable: boolean;
|
|
34
|
+
skip_ping: boolean;
|
|
35
|
+
skip_msg: boolean;
|
|
36
|
+
};
|
|
37
|
+
ping_interval: number;
|
|
38
|
+
reset_endpoint: number;
|
|
39
|
+
queue_ctrl_actionid_map: {
|
|
40
|
+
'611_0': string;
|
|
41
|
+
'610_1': string;
|
|
42
|
+
'610_0': string;
|
|
43
|
+
'603_0': string;
|
|
44
|
+
'611_1': string;
|
|
45
|
+
};
|
|
46
|
+
close_and_retry_codes: number[];
|
|
47
|
+
max_msg_size: number;
|
|
48
|
+
enable_ctrl_socket: boolean;
|
|
49
|
+
reconnect_after_fallback: boolean;
|
|
50
|
+
enable_chat_socket: boolean;
|
|
51
|
+
submit_wss_log: boolean;
|
|
52
|
+
disable_lp: boolean;
|
|
53
|
+
offline_monitor: {
|
|
54
|
+
enable: boolean;
|
|
55
|
+
};
|
|
56
|
+
none_ids_queue?: string[];
|
|
57
|
+
ping_http_level?: number;
|
|
58
|
+
close_timeout?: number;
|
|
59
|
+
enable_fallback_lp: boolean;
|
|
60
|
+
retries_round_2: Record<string, any>;
|
|
61
|
+
};
|
|
62
|
+
export interface OnlineConfigs {
|
|
63
|
+
update_action_interval: number;
|
|
64
|
+
user_active_time: number;
|
|
65
|
+
enable_lost_focus: boolean;
|
|
66
|
+
is_enable_new: number;
|
|
67
|
+
enable_active_deactive_v2: boolean;
|
|
68
|
+
send_active_to_keep_live: boolean;
|
|
69
|
+
}
|
|
70
|
+
export type LoginInfo = {
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
haspcclient: number;
|
|
73
|
+
public_ip: string;
|
|
74
|
+
language: string;
|
|
75
|
+
send2me_id: string;
|
|
76
|
+
zpw_service_map_v3: {
|
|
77
|
+
other_contact: string[];
|
|
78
|
+
chat_e2e: string[];
|
|
79
|
+
workspace: string[];
|
|
80
|
+
catalog: string[];
|
|
81
|
+
boards: string[];
|
|
82
|
+
downloadStickerUrl: string[];
|
|
83
|
+
sp_contact: string[];
|
|
84
|
+
zcloud_up_file: string[];
|
|
85
|
+
media_store_send2me: string[];
|
|
86
|
+
push_act: string[];
|
|
87
|
+
aext: string[];
|
|
88
|
+
zfamily: string[];
|
|
89
|
+
group_poll: string[];
|
|
90
|
+
group_cloud_message: string[];
|
|
91
|
+
media_store: string[];
|
|
92
|
+
file: string[];
|
|
93
|
+
auto_reply: string[];
|
|
94
|
+
sync_action: string[];
|
|
95
|
+
friendLan: string[];
|
|
96
|
+
friend: string[];
|
|
97
|
+
alias: string[];
|
|
98
|
+
zimsg: string[];
|
|
99
|
+
group_board: string[];
|
|
100
|
+
conversation: string[];
|
|
101
|
+
group: string[];
|
|
102
|
+
fallback_LP: string[];
|
|
103
|
+
friend_board: string[];
|
|
104
|
+
up_file: string[];
|
|
105
|
+
zavi: string[];
|
|
106
|
+
reaction: string[];
|
|
107
|
+
voice_call: string[];
|
|
108
|
+
profile: string[];
|
|
109
|
+
sticker: string[];
|
|
110
|
+
label: string[];
|
|
111
|
+
consent: string[];
|
|
112
|
+
zcloud: string[];
|
|
113
|
+
chat: string[];
|
|
114
|
+
todoUrl: string[];
|
|
115
|
+
recent_search: string[];
|
|
116
|
+
group_e2e: string[];
|
|
117
|
+
quick_message: string[];
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
export type ServerInfo = {
|
|
121
|
+
config_pages: {
|
|
122
|
+
zalo_page: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export type ExtraVer = {
|
|
126
|
+
phonebook: number;
|
|
127
|
+
conv_label: string;
|
|
128
|
+
friend: string;
|
|
129
|
+
ver_sticker_giphy_suggest: number;
|
|
130
|
+
ver_giphy_cate: number;
|
|
131
|
+
alias: string;
|
|
132
|
+
ver_sticker_cate_list: number;
|
|
133
|
+
block_friend: string;
|
|
134
|
+
};
|
|
135
|
+
export type ZPWServiceMap = LoginInfo['zpw_service_map_v3'];
|
|
136
|
+
export type AppContextBase = {
|
|
137
|
+
uid: string;
|
|
138
|
+
imei: string;
|
|
139
|
+
cookie: CookieJar;
|
|
140
|
+
userAgent: string;
|
|
141
|
+
language: string;
|
|
142
|
+
secretKey: string | null;
|
|
143
|
+
zpwServiceMap: ZPWServiceMap;
|
|
144
|
+
settings: {
|
|
145
|
+
[key: string]: any;
|
|
146
|
+
features: {
|
|
147
|
+
[key: string]: any;
|
|
148
|
+
sharefile: ShareFileSettings;
|
|
149
|
+
socket: SocketSettings;
|
|
150
|
+
online_configs: OnlineConfigs;
|
|
151
|
+
};
|
|
152
|
+
keepalive: {
|
|
153
|
+
alway_keepalive: number;
|
|
154
|
+
keepalive_duration: number;
|
|
155
|
+
time_deactive: number;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
loginInfo: LoginInfo;
|
|
159
|
+
extraVer: ExtraVer;
|
|
160
|
+
};
|
|
161
|
+
export type ImageMetadataGetterResponse = {
|
|
162
|
+
width: number;
|
|
163
|
+
height: number;
|
|
164
|
+
size: number;
|
|
165
|
+
} | null;
|
|
166
|
+
export type ImageMetadataGetter = (filePath: string) => Promise<ImageMetadataGetterResponse>;
|
|
167
|
+
export type Options = {
|
|
168
|
+
selfListen: boolean;
|
|
169
|
+
checkUpdate: boolean;
|
|
170
|
+
logging: boolean;
|
|
171
|
+
apiType: number;
|
|
172
|
+
apiVersion: number;
|
|
173
|
+
agent?: Agent;
|
|
174
|
+
/**
|
|
175
|
+
* Optional fetch implementation for polyfills in non-standard environments.
|
|
176
|
+
* If using proxy, `node-fetch` is highly recommended.
|
|
177
|
+
*/
|
|
178
|
+
polyfill: typeof fetch;
|
|
179
|
+
imageMetadataGetter?: ImageMetadataGetter;
|
|
180
|
+
};
|
|
181
|
+
export declare class CallbacksMap extends Map<string, UploadCallback> {
|
|
182
|
+
/**
|
|
183
|
+
* @param ttl Time to live in milliseconds. Default is 5 minutes.
|
|
184
|
+
*/
|
|
185
|
+
set(key: string, value: UploadCallback, ttl?: number): this;
|
|
186
|
+
}
|
|
187
|
+
export type AppContextExtended = {
|
|
188
|
+
options: Options;
|
|
189
|
+
readonly API_TYPE: number;
|
|
190
|
+
readonly API_VERSION: number;
|
|
191
|
+
};
|
|
192
|
+
export type ContextBase = Partial<AppContextBase> & AppContextExtended;
|
|
193
|
+
export declare const createContext: (apiType?: number, apiVersion?: number) => ContextBase;
|
|
194
|
+
export type ContextSession = AppContextBase & AppContextExtended & {
|
|
195
|
+
secretKey: string;
|
|
196
|
+
};
|
|
197
|
+
export declare function isContextSession(ctx: ContextBase): ctx is ContextSession;
|
|
198
|
+
export declare const MAX_MESSAGES_PER_SEND = 50;
|
|
199
|
+
export {};
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const _5_MINUTES = 5 * 60 * 1000;
|
|
2
|
+
export class CallbacksMap extends Map {
|
|
3
|
+
/**
|
|
4
|
+
* @param ttl Time to live in milliseconds. Default is 5 minutes.
|
|
5
|
+
*/
|
|
6
|
+
set(key, value, ttl = _5_MINUTES) {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
this.delete(key);
|
|
9
|
+
}, ttl);
|
|
10
|
+
return super.set(key, value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const createContext = (apiType = 30, apiVersion = 665) => ({
|
|
14
|
+
API_TYPE: apiType,
|
|
15
|
+
API_VERSION: apiVersion,
|
|
16
|
+
options: {
|
|
17
|
+
selfListen: false,
|
|
18
|
+
checkUpdate: true,
|
|
19
|
+
logging: true,
|
|
20
|
+
polyfill: global.fetch,
|
|
21
|
+
},
|
|
22
|
+
secretKey: null,
|
|
23
|
+
});
|
|
24
|
+
export function isContextSession(ctx) {
|
|
25
|
+
return !!ctx.secretKey;
|
|
26
|
+
}
|
|
27
|
+
export const MAX_MESSAGES_PER_SEND = 50;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var AttachmentType;
|
|
2
|
+
(function (AttachmentType) {
|
|
3
|
+
AttachmentType["FILE"] = "file";
|
|
4
|
+
AttachmentType["IMAGE"] = "image";
|
|
5
|
+
AttachmentType["GIF"] = "gif";
|
|
6
|
+
AttachmentType["VIDEO"] = "video";
|
|
7
|
+
AttachmentType["AUDIO"] = "audio";
|
|
8
|
+
AttachmentType["STICKER"] = "sticker";
|
|
9
|
+
AttachmentType["CALL"] = "call";
|
|
10
|
+
AttachmentType["CARD"] = "card";
|
|
11
|
+
AttachmentType["LINK"] = "link";
|
|
12
|
+
})(AttachmentType || (AttachmentType = {}));
|