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