zalo-toolkit 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/sendMessage.d.ts +5 -0
- package/dist/apis/sendMessage.js +31 -11
- package/dist/cjs/apis/acceptFriendRequest.cjs +33 -0
- package/dist/cjs/apis/addGroupBlockedMember.cjs +33 -0
- package/dist/cjs/apis/addGroupDeputy.cjs +36 -0
- package/dist/cjs/apis/addPollOptions.cjs +31 -0
- package/dist/cjs/apis/addQuickMessage.cjs +65 -0
- package/dist/cjs/apis/addReaction.cjs +297 -0
- package/dist/cjs/apis/addUnreadMark.cjs +65 -0
- package/dist/cjs/apis/addUserToGroup.cjs +39 -0
- package/dist/cjs/apis/blockUser.cjs +33 -0
- package/dist/cjs/apis/blockViewFeed.cjs +35 -0
- package/dist/cjs/apis/changeAccountAvatar.cjs +56 -0
- package/dist/cjs/apis/changeFriendAlias.cjs +32 -0
- package/dist/cjs/apis/changeGroupAvatar.cjs +47 -0
- package/dist/cjs/apis/changeGroupName.cjs +37 -0
- package/dist/cjs/apis/changeGroupOwner.cjs +36 -0
- package/dist/cjs/apis/createAutoReply.cjs +42 -0
- package/dist/cjs/apis/createCatalog.cjs +34 -0
- package/dist/cjs/apis/createGroup.cjs +48 -0
- package/dist/cjs/apis/createNote.cjs +52 -0
- package/dist/cjs/apis/createPoll.cjs +45 -0
- package/dist/cjs/apis/createProductCatalog.cjs +55 -0
- package/dist/cjs/apis/createReminder.cjs +76 -0
- package/dist/cjs/apis/custom.cjs +19 -0
- package/dist/cjs/apis/deleteAutoReply.cjs +34 -0
- package/dist/cjs/apis/deleteAvatar.cjs +32 -0
- package/dist/cjs/apis/deleteCatalog.cjs +33 -0
- package/dist/cjs/apis/deleteChat.cjs +63 -0
- package/dist/cjs/apis/deleteGroupInviteBox.cjs +32 -0
- package/dist/cjs/apis/deleteMessage.cjs +65 -0
- package/dist/cjs/apis/deleteProductCatalog.cjs +36 -0
- package/dist/cjs/apis/disableGroupLink.cjs +29 -0
- package/dist/cjs/apis/disperseGroup.cjs +33 -0
- package/dist/cjs/apis/editNote.cjs +51 -0
- package/dist/cjs/apis/editReminder.cjs +74 -0
- package/dist/cjs/apis/enableGroupLink.cjs +30 -0
- package/dist/cjs/apis/fetchAccountInfo.cjs +15 -0
- package/dist/cjs/apis/findUser.cjs +45 -0
- package/dist/cjs/apis/forwardAttachment.cjs +85 -0
- package/dist/cjs/apis/forwardMessage.cjs +122 -0
- package/dist/cjs/apis/getAliasList.cjs +33 -0
- package/dist/cjs/apis/getAllFriends.cjs +37 -0
- package/dist/cjs/apis/getAllGroups.cjs +15 -0
- package/dist/cjs/apis/getArchivedChatList.cjs +28 -0
- package/dist/cjs/apis/getAutoDeleteChat.cjs +26 -0
- package/dist/cjs/apis/getAutoReplyList.cjs +29 -0
- package/dist/cjs/apis/getAvatarList.cjs +33 -0
- package/dist/cjs/apis/getBizAccount.cjs +32 -0
- package/dist/cjs/apis/getCatalogList.cjs +37 -0
- package/dist/cjs/apis/getContext.cjs +9 -0
- package/dist/cjs/apis/getCookie.cjs +14 -0
- package/dist/cjs/apis/getFriendBoardList.cjs +31 -0
- package/dist/cjs/apis/getFriendOnlines.cjs +40 -0
- package/dist/cjs/apis/getFriendRecommendations.cjs +32 -0
- package/dist/cjs/apis/getFriendRequestStatus.cjs +30 -0
- package/dist/cjs/apis/getGroupBlockedMember.cjs +34 -0
- package/dist/cjs/apis/getGroupInfo.cjs +37 -0
- package/dist/cjs/apis/getGroupInviteBoxInfo.cjs +43 -0
- package/dist/cjs/apis/getGroupInviteBoxList.cjs +36 -0
- package/dist/cjs/apis/getGroupLinkDetail.cjs +30 -0
- package/dist/cjs/apis/getGroupLinkInfo.cjs +33 -0
- package/dist/cjs/apis/getGroupMembersInfo.cjs +29 -0
- package/dist/cjs/apis/getHiddenConversations.cjs +28 -0
- package/dist/cjs/apis/getLabels.cjs +33 -0
- package/dist/cjs/apis/getLastMessage.cjs +25 -0
- package/dist/cjs/apis/getListBoard.cjs +58 -0
- package/dist/cjs/apis/getListReminder.cjs +60 -0
- package/dist/cjs/apis/getMute.cjs +27 -0
- package/dist/cjs/apis/getOwnId.cjs +9 -0
- package/dist/cjs/apis/getPendingGroupMembers.cjs +32 -0
- package/dist/cjs/apis/getPinConversations.cjs +27 -0
- package/dist/cjs/apis/getPollDetail.cjs +35 -0
- package/dist/cjs/apis/getProductCatalogList.cjs +38 -0
- package/dist/cjs/apis/getQR.cjs +34 -0
- package/dist/cjs/apis/getQuickMessageList.cjs +29 -0
- package/dist/cjs/apis/getRecommendFriends.cjs +25 -0
- package/dist/cjs/apis/getRelatedFriendGroup.cjs +35 -0
- package/dist/cjs/apis/getReminder.cjs +30 -0
- package/dist/cjs/apis/getReminderResponses.cjs +29 -0
- package/dist/cjs/apis/getSentFriendRequest.cjs +29 -0
- package/dist/cjs/apis/getSettings.cjs +25 -0
- package/dist/cjs/apis/getStickers.cjs +45 -0
- package/dist/cjs/apis/getStickersDetail.cjs +45 -0
- package/dist/cjs/apis/getUnreadMark.cjs +35 -0
- package/dist/cjs/apis/getUserInfo.cjs +47 -0
- package/dist/cjs/apis/inviteUserToGroups.cjs +35 -0
- package/dist/cjs/apis/joinGroupInviteBox.cjs +30 -0
- package/dist/cjs/apis/joinGroupLink.cjs +32 -0
- package/dist/cjs/apis/keepAlive.cjs +27 -0
- package/dist/cjs/apis/lastOnline.cjs +31 -0
- package/dist/cjs/apis/leaveGroup.cjs +38 -0
- package/dist/cjs/apis/lockPoll.cjs +33 -0
- package/dist/cjs/apis/parseLink.cjs +32 -0
- package/dist/cjs/apis/rejectFriendRequest.cjs +32 -0
- package/dist/cjs/apis/removeFriend.cjs +33 -0
- package/dist/cjs/apis/removeFriendAlias.cjs +29 -0
- package/dist/cjs/apis/removeGroupBlockedMember.cjs +33 -0
- package/dist/cjs/apis/removeGroupDeputy.cjs +35 -0
- package/dist/cjs/apis/removeQuickMessage.cjs +32 -0
- package/dist/cjs/apis/removeReminder.cjs +53 -0
- package/dist/cjs/apis/removeUnreadMark.cjs +63 -0
- package/dist/cjs/apis/removeUserFromGroup.cjs +39 -0
- package/dist/cjs/apis/resetHiddenConversPin.cjs +25 -0
- package/dist/cjs/apis/reuseAvatar.cjs +31 -0
- package/dist/cjs/apis/reviewPendingMemberRequest.cjs +33 -11
- package/dist/cjs/apis/sendBankCard.cjs +50 -0
- package/dist/cjs/apis/sendCard.cjs +72 -0
- package/dist/cjs/apis/sendDeliveredEvent.cjs +68 -0
- package/dist/cjs/apis/sendFriendRequest.cjs +44 -0
- package/dist/cjs/apis/sendLink.cjs +70 -0
- package/dist/cjs/apis/sendMessage.cjs +437 -11
- package/dist/cjs/apis/sendReport.cjs +48 -10
- package/dist/cjs/apis/sendSeenEvent.cjs +76 -0
- package/dist/cjs/apis/sendSticker.cjs +69 -0
- package/dist/cjs/apis/sendTypingEvent.cjs +46 -0
- package/dist/cjs/apis/sendVideo.cjs +131 -0
- package/dist/cjs/apis/sendVoice.cjs +86 -0
- package/dist/cjs/apis/setArchivedConversations.cjs +39 -0
- package/dist/cjs/apis/setHiddenConversations.cjs +52 -0
- package/dist/cjs/apis/setMute.cjs +57 -10
- package/dist/cjs/apis/setPinnedConversations.cjs +47 -0
- package/dist/cjs/apis/sharePoll.cjs +33 -0
- package/dist/cjs/apis/unblockUser.cjs +33 -0
- package/dist/cjs/apis/undo.cjs +55 -0
- package/dist/cjs/apis/undoFriendRequest.cjs +32 -0
- package/dist/cjs/apis/updateActiveStatus.cjs +32 -0
- package/dist/cjs/apis/updateAutoDeleteChat.cjs +35 -10
- package/dist/cjs/apis/updateAutoReply.cjs +43 -0
- package/dist/cjs/apis/updateCatalog.cjs +35 -0
- package/dist/cjs/apis/updateGroupSettings.cjs +48 -0
- package/dist/cjs/apis/updateHiddenConversPin.cjs +35 -0
- package/dist/cjs/apis/updateLabels.cjs +39 -0
- package/dist/cjs/apis/updateLang.cjs +27 -11
- package/dist/cjs/apis/updateProductCatalog.cjs +56 -0
- package/dist/cjs/apis/updateProfile.cjs +48 -0
- package/dist/cjs/apis/updateQuickMessage.cjs +66 -0
- package/dist/cjs/apis/updateSettings.cjs +77 -11
- package/dist/cjs/apis/uploadAttachment.cjs +208 -0
- package/dist/cjs/apis/uploadProductPhoto.cjs +50 -0
- package/dist/cjs/apis/votePoll.cjs +34 -0
- package/dist/cjs/apis.cjs +292 -0
- package/dist/cjs/context.cjs +15 -0
- package/dist/cjs/core/enums/common.cjs +14 -0
- package/dist/cjs/core/utils/index.cjs +33 -0
- package/dist/cjs/models/GroupEvent.cjs +2 -4
- package/dist/cjs/utils.cjs +229 -3
- package/dist/cjs/zalo.cjs +18 -7
- package/dist/index.d.ts +1 -0
- package/dist/models/GroupEvent.d.ts +2 -2
- package/dist/models/GroupEvent.js +2 -4
- package/dist/models/Message.d.ts +6 -0
- package/dist/zalo.d.ts +17 -10
- package/dist/zalo.js +19 -8
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IFileUpload } from '../core/interfaces/common.js';
|
|
2
2
|
import { ThreadType, type TMessage } from '../models/index.js';
|
|
3
|
+
import type { ParseLinkResponse } from './parseLink.js';
|
|
3
4
|
export type SendMessageResult = {
|
|
4
5
|
msgId: number;
|
|
5
6
|
};
|
|
@@ -85,6 +86,10 @@ export type MessageContent = {
|
|
|
85
86
|
* Mentions in the message (optional)
|
|
86
87
|
*/
|
|
87
88
|
mentions?: Mention[];
|
|
89
|
+
/**
|
|
90
|
+
* Parse Link (optional)
|
|
91
|
+
*/
|
|
92
|
+
parseLink?: ParseLinkResponse['data'];
|
|
88
93
|
/**
|
|
89
94
|
* Attachments in the message (optional)
|
|
90
95
|
*/
|
package/dist/apis/sendMessage.js
CHANGED
|
@@ -158,7 +158,7 @@ export const sendMessageFactory = apiFactory()((api, ctx, utils) => {
|
|
|
158
158
|
Object.assign(params, { metaData: { urgency } });
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
async function handleMessage({ msg, styles, urgency, mentions, quote, ttl }, threadId, type) {
|
|
161
|
+
async function handleMessage({ msg, styles, urgency, mentions, parseLink, quote, ttl }, threadId, type) {
|
|
162
162
|
if (!msg || msg.length == 0)
|
|
163
163
|
throw new ZaloApiError('Missing message content');
|
|
164
164
|
const isGroupMessage = type == ThreadType.Group;
|
|
@@ -192,16 +192,33 @@ export const sendMessageFactory = apiFactory()((api, ctx, utils) => {
|
|
|
192
192
|
qmsgTTL: quote.ttl,
|
|
193
193
|
ttl: ttl !== null && ttl !== void 0 ? ttl : 0,
|
|
194
194
|
}
|
|
195
|
-
:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
195
|
+
: parseLink
|
|
196
|
+
? {
|
|
197
|
+
msg: msg,
|
|
198
|
+
href: parseLink.href,
|
|
199
|
+
src: parseLink.src,
|
|
200
|
+
title: parseLink.title || parseLink.href,
|
|
201
|
+
desc: parseLink.desc,
|
|
202
|
+
thumb: parseLink.thumb,
|
|
203
|
+
type: 0,
|
|
204
|
+
media: JSON.stringify(parseLink.media),
|
|
205
|
+
ttl: 0,
|
|
206
|
+
toId: isGroupMessage ? undefined : threadId,
|
|
207
|
+
grid: isGroupMessage ? threadId : undefined,
|
|
208
|
+
clientId: Date.now(),
|
|
209
|
+
mentionInfo: isMentionsValid ? JSON.stringify(mentionsFinal) : '',
|
|
210
|
+
imei: isGroupMessage ? ctx.imei : undefined,
|
|
211
|
+
}
|
|
212
|
+
: {
|
|
213
|
+
message: msg,
|
|
214
|
+
clientId: Date.now(),
|
|
215
|
+
mentionInfo: isMentionsValid ? JSON.stringify(mentionsFinal) : undefined,
|
|
216
|
+
imei: isGroupMessage ? undefined : ctx.imei,
|
|
217
|
+
ttl: ttl !== null && ttl !== void 0 ? ttl : 0,
|
|
218
|
+
visibility: isGroupMessage ? 0 : undefined,
|
|
219
|
+
toid: isGroupMessage ? undefined : threadId,
|
|
220
|
+
grid: isGroupMessage ? threadId : undefined,
|
|
221
|
+
};
|
|
205
222
|
handleStyles(params, styles);
|
|
206
223
|
handleUrgency(params, urgency);
|
|
207
224
|
removeUndefinedKeys(params);
|
|
@@ -212,6 +229,9 @@ export const sendMessageFactory = apiFactory()((api, ctx, utils) => {
|
|
|
212
229
|
if (quote) {
|
|
213
230
|
finalServiceUrl.pathname = finalServiceUrl.pathname + '/quote';
|
|
214
231
|
}
|
|
232
|
+
else if (parseLink) {
|
|
233
|
+
finalServiceUrl.pathname = finalServiceUrl.pathname + '/' + (isGroupMessage ? 'sendlink' : 'link');
|
|
234
|
+
}
|
|
215
235
|
else {
|
|
216
236
|
finalServiceUrl.pathname = finalServiceUrl.pathname + '/' + (isGroupMessage ? (params.mentionInfo ? 'mention' : 'sendmsg') : 'sms');
|
|
217
237
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const acceptFriendRequestFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/accept`);
|
|
8
|
+
/**
|
|
9
|
+
* Accept a friend request from a User
|
|
10
|
+
*
|
|
11
|
+
* @param userId The User ID to friend request is accept
|
|
12
|
+
*
|
|
13
|
+
* @throws ZaloApiError
|
|
14
|
+
*/
|
|
15
|
+
return async function acceptFriendRequest(userId) {
|
|
16
|
+
const params = {
|
|
17
|
+
fid: userId,
|
|
18
|
+
language: ctx.language,
|
|
19
|
+
};
|
|
20
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
21
|
+
if (!encryptedParams)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
23
|
+
const response = await utils.request(serviceURL, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
body: new URLSearchParams({
|
|
26
|
+
params: encryptedParams,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
return utils.resolve(response);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.acceptFriendRequestFactory = acceptFriendRequestFactory;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const addGroupBlockedMemberFactory = utils.apiFactory()((api, _, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/blockedmems/add`);
|
|
8
|
+
/**
|
|
9
|
+
* Add group blocked member
|
|
10
|
+
*
|
|
11
|
+
* @param memberId member id(s)
|
|
12
|
+
* @param groupId group id
|
|
13
|
+
*
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function addGroupBlockedMember(memberId, groupId) {
|
|
17
|
+
if (!Array.isArray(memberId))
|
|
18
|
+
memberId = [memberId];
|
|
19
|
+
const params = {
|
|
20
|
+
grid: groupId,
|
|
21
|
+
members: memberId,
|
|
22
|
+
};
|
|
23
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
24
|
+
if (!encryptedParams)
|
|
25
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
26
|
+
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
});
|
|
29
|
+
return utils.resolve(response);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.addGroupBlockedMemberFactory = addGroupBlockedMemberFactory;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const addGroupDeputyFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/admins/add`);
|
|
8
|
+
/**
|
|
9
|
+
* Add group deputy
|
|
10
|
+
*
|
|
11
|
+
* @param memberId user Id or list of user Ids
|
|
12
|
+
* @param groupId group Id
|
|
13
|
+
*
|
|
14
|
+
* @throws ZaloApiError
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
return async function addGroupDeputy(memberId, groupId) {
|
|
18
|
+
if (!Array.isArray(memberId))
|
|
19
|
+
memberId = [memberId];
|
|
20
|
+
const params = {
|
|
21
|
+
grid: groupId,
|
|
22
|
+
members: memberId,
|
|
23
|
+
imei: ctx.imei,
|
|
24
|
+
};
|
|
25
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
26
|
+
if (!encryptedParams)
|
|
27
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
28
|
+
const urlWithParams = `${serviceURL}¶ms=${encodeURIComponent(encryptedParams)}`;
|
|
29
|
+
const response = await utils.request(urlWithParams, {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
});
|
|
32
|
+
return utils.resolve(response);
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
exports.addGroupDeputyFactory = addGroupDeputyFactory;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const addPollOptionsFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/poll/option/add`);
|
|
8
|
+
/**
|
|
9
|
+
* Add new option to poll
|
|
10
|
+
*
|
|
11
|
+
* @param payload
|
|
12
|
+
*
|
|
13
|
+
* @throws {ZaloApiError}
|
|
14
|
+
*/
|
|
15
|
+
return async function addPollOptions(payload) {
|
|
16
|
+
const params = {
|
|
17
|
+
poll_id: payload.pollId,
|
|
18
|
+
new_options: JSON.stringify(payload.options),
|
|
19
|
+
voted_option_ids: payload.votedOptionIds,
|
|
20
|
+
};
|
|
21
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
22
|
+
if (!encryptedParams)
|
|
23
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
24
|
+
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
|
|
25
|
+
method: 'GET',
|
|
26
|
+
});
|
|
27
|
+
return utils.resolve(response);
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
exports.addPollOptionsFactory = addPollOptionsFactory;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const addQuickMessageFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.quick_message[0]}/api/quickmessage/create`);
|
|
8
|
+
/**
|
|
9
|
+
* Add quick message
|
|
10
|
+
*
|
|
11
|
+
* @param addPayload - The payload containing data to add the quick message
|
|
12
|
+
*
|
|
13
|
+
* @note Zalo might throw an error with code 821 if you have reached the limit of quick messages.
|
|
14
|
+
*
|
|
15
|
+
* @throws {ZaloApiError}
|
|
16
|
+
*/
|
|
17
|
+
return async function addQuickMessage(addPayload) {
|
|
18
|
+
const isType = !addPayload.media ? 0 : 1;
|
|
19
|
+
const params = {
|
|
20
|
+
keyword: addPayload.keyword,
|
|
21
|
+
message: {
|
|
22
|
+
title: addPayload.title,
|
|
23
|
+
params: '',
|
|
24
|
+
},
|
|
25
|
+
type: isType,
|
|
26
|
+
imei: ctx.imei,
|
|
27
|
+
};
|
|
28
|
+
if (isType === 1) {
|
|
29
|
+
if (!addPayload.media)
|
|
30
|
+
throw new ZaloApiError.ZaloApiError('Media is required');
|
|
31
|
+
const uploadMedia = await api.uploadProductPhoto({
|
|
32
|
+
url: addPayload.media,
|
|
33
|
+
});
|
|
34
|
+
const photoId = uploadMedia.photoId;
|
|
35
|
+
const thumbUrl = uploadMedia.thumbUrl;
|
|
36
|
+
const normalUrl = uploadMedia.normalUrl;
|
|
37
|
+
const hdUrl = uploadMedia.hdUrl;
|
|
38
|
+
params.media = {
|
|
39
|
+
items: [
|
|
40
|
+
{
|
|
41
|
+
type: 0,
|
|
42
|
+
photoId: photoId,
|
|
43
|
+
title: '',
|
|
44
|
+
width: '',
|
|
45
|
+
height: '',
|
|
46
|
+
previewThumb: thumbUrl,
|
|
47
|
+
rawUrl: normalUrl || hdUrl,
|
|
48
|
+
thumbUrl: thumbUrl,
|
|
49
|
+
normalUrl: normalUrl || hdUrl,
|
|
50
|
+
hdUrl: hdUrl || normalUrl,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
56
|
+
if (!encryptedParams)
|
|
57
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
58
|
+
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
|
|
59
|
+
method: 'GET',
|
|
60
|
+
});
|
|
61
|
+
return utils.resolve(response);
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
exports.addQuickMessageFactory = addQuickMessageFactory;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var Enum = require('../models/Enum.cjs');
|
|
5
|
+
var Reaction = require('../models/Reaction.cjs');
|
|
6
|
+
var utils = require('../utils.cjs');
|
|
7
|
+
|
|
8
|
+
const addReactionFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
9
|
+
const serviceURLs = {
|
|
10
|
+
[Enum.ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.reaction[0]}/api/message/reaction`),
|
|
11
|
+
[Enum.ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.reaction[0]}/api/group/reaction`),
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Add reaction to a message
|
|
15
|
+
*
|
|
16
|
+
* @param icon Reaction icon
|
|
17
|
+
* @param dest Destination data including message IDs and thread information
|
|
18
|
+
*
|
|
19
|
+
* @throws ZaloApiError
|
|
20
|
+
*/
|
|
21
|
+
return async function addReaction(icon, dest) {
|
|
22
|
+
const serviceURL = serviceURLs[dest.type];
|
|
23
|
+
let rType, source;
|
|
24
|
+
if (typeof icon == 'object') {
|
|
25
|
+
rType = icon.rType;
|
|
26
|
+
source = icon.source;
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
switch (icon) {
|
|
30
|
+
case Reaction.Reactions.HAHA:
|
|
31
|
+
rType = 0;
|
|
32
|
+
source = 6;
|
|
33
|
+
break;
|
|
34
|
+
case Reaction.Reactions.LIKE:
|
|
35
|
+
rType = 3;
|
|
36
|
+
source = 6;
|
|
37
|
+
break;
|
|
38
|
+
case Reaction.Reactions.HEART:
|
|
39
|
+
rType = 5;
|
|
40
|
+
source = 6;
|
|
41
|
+
break;
|
|
42
|
+
case Reaction.Reactions.WOW:
|
|
43
|
+
rType = 32;
|
|
44
|
+
source = 6;
|
|
45
|
+
break;
|
|
46
|
+
case Reaction.Reactions.CRY:
|
|
47
|
+
rType = 2;
|
|
48
|
+
source = 6;
|
|
49
|
+
break;
|
|
50
|
+
case Reaction.Reactions.ANGRY:
|
|
51
|
+
rType = 20;
|
|
52
|
+
source = 6;
|
|
53
|
+
break;
|
|
54
|
+
case Reaction.Reactions.KISS:
|
|
55
|
+
rType = 8;
|
|
56
|
+
source = 6;
|
|
57
|
+
break;
|
|
58
|
+
case Reaction.Reactions.TEARS_OF_JOY:
|
|
59
|
+
rType = 7;
|
|
60
|
+
source = 6;
|
|
61
|
+
break;
|
|
62
|
+
case Reaction.Reactions.SHIT:
|
|
63
|
+
rType = 66;
|
|
64
|
+
source = 6;
|
|
65
|
+
break;
|
|
66
|
+
case Reaction.Reactions.ROSE:
|
|
67
|
+
rType = 120;
|
|
68
|
+
source = 6;
|
|
69
|
+
break;
|
|
70
|
+
case Reaction.Reactions.BROKEN_HEART:
|
|
71
|
+
rType = 65;
|
|
72
|
+
source = 6;
|
|
73
|
+
break;
|
|
74
|
+
case Reaction.Reactions.DISLIKE:
|
|
75
|
+
rType = 4;
|
|
76
|
+
source = 6;
|
|
77
|
+
break;
|
|
78
|
+
case Reaction.Reactions.LOVE:
|
|
79
|
+
rType = 29;
|
|
80
|
+
source = 6;
|
|
81
|
+
break;
|
|
82
|
+
case Reaction.Reactions.CONFUSED:
|
|
83
|
+
rType = 51;
|
|
84
|
+
source = 6;
|
|
85
|
+
break;
|
|
86
|
+
case Reaction.Reactions.WINK:
|
|
87
|
+
rType = 45;
|
|
88
|
+
source = 6;
|
|
89
|
+
break;
|
|
90
|
+
case Reaction.Reactions.FADE:
|
|
91
|
+
rType = 121;
|
|
92
|
+
source = 6;
|
|
93
|
+
break;
|
|
94
|
+
case Reaction.Reactions.SUN:
|
|
95
|
+
rType = 67;
|
|
96
|
+
source = 6;
|
|
97
|
+
break;
|
|
98
|
+
case Reaction.Reactions.BIRTHDAY:
|
|
99
|
+
rType = 126;
|
|
100
|
+
source = 6;
|
|
101
|
+
break;
|
|
102
|
+
case Reaction.Reactions.BOMB:
|
|
103
|
+
rType = 127;
|
|
104
|
+
source = 6;
|
|
105
|
+
break;
|
|
106
|
+
case Reaction.Reactions.OK:
|
|
107
|
+
rType = 68;
|
|
108
|
+
source = 6;
|
|
109
|
+
break;
|
|
110
|
+
case Reaction.Reactions.PEACE:
|
|
111
|
+
rType = 69;
|
|
112
|
+
source = 6;
|
|
113
|
+
break;
|
|
114
|
+
case Reaction.Reactions.THANKS:
|
|
115
|
+
rType = 70;
|
|
116
|
+
source = 6;
|
|
117
|
+
break;
|
|
118
|
+
case Reaction.Reactions.PUNCH:
|
|
119
|
+
rType = 71;
|
|
120
|
+
source = 6;
|
|
121
|
+
break;
|
|
122
|
+
case Reaction.Reactions.SHARE:
|
|
123
|
+
rType = 72;
|
|
124
|
+
source = 6;
|
|
125
|
+
break;
|
|
126
|
+
case Reaction.Reactions.PRAY:
|
|
127
|
+
rType = 73;
|
|
128
|
+
source = 6;
|
|
129
|
+
break;
|
|
130
|
+
case Reaction.Reactions.NO:
|
|
131
|
+
rType = 131;
|
|
132
|
+
source = 6;
|
|
133
|
+
break;
|
|
134
|
+
case Reaction.Reactions.BAD:
|
|
135
|
+
rType = 132;
|
|
136
|
+
source = 6;
|
|
137
|
+
break;
|
|
138
|
+
case Reaction.Reactions.LOVE_YOU:
|
|
139
|
+
rType = 133;
|
|
140
|
+
source = 6;
|
|
141
|
+
break;
|
|
142
|
+
case Reaction.Reactions.SAD:
|
|
143
|
+
rType = 1;
|
|
144
|
+
source = 6;
|
|
145
|
+
break;
|
|
146
|
+
case Reaction.Reactions.VERY_SAD:
|
|
147
|
+
rType = 16;
|
|
148
|
+
source = 6;
|
|
149
|
+
break;
|
|
150
|
+
case Reaction.Reactions.COOL:
|
|
151
|
+
rType = 21;
|
|
152
|
+
source = 6;
|
|
153
|
+
break;
|
|
154
|
+
case Reaction.Reactions.NERD:
|
|
155
|
+
rType = 22;
|
|
156
|
+
source = 6;
|
|
157
|
+
break;
|
|
158
|
+
case Reaction.Reactions.BIG_SMILE:
|
|
159
|
+
rType = 23;
|
|
160
|
+
source = 6;
|
|
161
|
+
break;
|
|
162
|
+
case Reaction.Reactions.SUNGLASSES:
|
|
163
|
+
rType = 26;
|
|
164
|
+
source = 6;
|
|
165
|
+
break;
|
|
166
|
+
case Reaction.Reactions.NEUTRAL:
|
|
167
|
+
rType = 30;
|
|
168
|
+
source = 6;
|
|
169
|
+
break;
|
|
170
|
+
case Reaction.Reactions.SAD_FACE:
|
|
171
|
+
rType = 35;
|
|
172
|
+
source = 6;
|
|
173
|
+
break;
|
|
174
|
+
case Reaction.Reactions.BYE:
|
|
175
|
+
rType = 36;
|
|
176
|
+
source = 6;
|
|
177
|
+
break;
|
|
178
|
+
case Reaction.Reactions.SLEEPY:
|
|
179
|
+
rType = 38;
|
|
180
|
+
source = 6;
|
|
181
|
+
break;
|
|
182
|
+
case Reaction.Reactions.WIPE:
|
|
183
|
+
rType = 39;
|
|
184
|
+
source = 6;
|
|
185
|
+
break;
|
|
186
|
+
case Reaction.Reactions.DIG:
|
|
187
|
+
rType = 42;
|
|
188
|
+
source = 6;
|
|
189
|
+
break;
|
|
190
|
+
case Reaction.Reactions.ANGUISH:
|
|
191
|
+
rType = 44;
|
|
192
|
+
source = 6;
|
|
193
|
+
break;
|
|
194
|
+
case Reaction.Reactions.HANDCLAP:
|
|
195
|
+
rType = 46;
|
|
196
|
+
source = 6;
|
|
197
|
+
break;
|
|
198
|
+
case Reaction.Reactions.ANGRY_FACE:
|
|
199
|
+
rType = 47;
|
|
200
|
+
source = 6;
|
|
201
|
+
break;
|
|
202
|
+
case Reaction.Reactions.F_CHAIR:
|
|
203
|
+
rType = 48;
|
|
204
|
+
source = 6;
|
|
205
|
+
break;
|
|
206
|
+
case Reaction.Reactions.L_CHAIR:
|
|
207
|
+
rType = 49;
|
|
208
|
+
source = 6;
|
|
209
|
+
break;
|
|
210
|
+
case Reaction.Reactions.R_CHAIR:
|
|
211
|
+
rType = 50;
|
|
212
|
+
source = 6;
|
|
213
|
+
break;
|
|
214
|
+
case Reaction.Reactions.SILENT:
|
|
215
|
+
rType = 52;
|
|
216
|
+
source = 6;
|
|
217
|
+
break;
|
|
218
|
+
case Reaction.Reactions.SURPRISE:
|
|
219
|
+
rType = 53;
|
|
220
|
+
source = 6;
|
|
221
|
+
break;
|
|
222
|
+
case Reaction.Reactions.EMBARRASSED:
|
|
223
|
+
rType = 54;
|
|
224
|
+
source = 6;
|
|
225
|
+
break;
|
|
226
|
+
case Reaction.Reactions.AFRAID:
|
|
227
|
+
rType = 60;
|
|
228
|
+
source = 6;
|
|
229
|
+
break;
|
|
230
|
+
case Reaction.Reactions.SAD2:
|
|
231
|
+
rType = 61;
|
|
232
|
+
source = 6;
|
|
233
|
+
break;
|
|
234
|
+
case Reaction.Reactions.BIG_LAUGH:
|
|
235
|
+
rType = 62;
|
|
236
|
+
source = 6;
|
|
237
|
+
break;
|
|
238
|
+
case Reaction.Reactions.RICH:
|
|
239
|
+
rType = 63;
|
|
240
|
+
source = 6;
|
|
241
|
+
break;
|
|
242
|
+
case Reaction.Reactions.BEER:
|
|
243
|
+
rType = 99;
|
|
244
|
+
source = 6;
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
rType = -1;
|
|
248
|
+
source = 6;
|
|
249
|
+
}
|
|
250
|
+
const params = {
|
|
251
|
+
react_list: [
|
|
252
|
+
{
|
|
253
|
+
message: JSON.stringify({
|
|
254
|
+
rMsg: [
|
|
255
|
+
{
|
|
256
|
+
gMsgID: parseInt(dest.data.msgId),
|
|
257
|
+
cMsgID: parseInt(dest.data.cliMsgId),
|
|
258
|
+
msgType: 1,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
rIcon: icon,
|
|
262
|
+
rType,
|
|
263
|
+
source,
|
|
264
|
+
}),
|
|
265
|
+
clientId: Date.now(),
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
imei: ctx.imei,
|
|
269
|
+
};
|
|
270
|
+
if (dest.type == Enum.ThreadType.User) {
|
|
271
|
+
params.toid = dest.threadId;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
params.grid = dest.threadId;
|
|
275
|
+
params.imei = ctx.imei;
|
|
276
|
+
}
|
|
277
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
278
|
+
if (!encryptedParams)
|
|
279
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt message');
|
|
280
|
+
const response = await utils.request(serviceURL, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
body: new URLSearchParams({
|
|
283
|
+
params: encryptedParams,
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
return utils.resolve(response, (result) => {
|
|
287
|
+
if (typeof result.data.msgIds === 'string') {
|
|
288
|
+
return {
|
|
289
|
+
msgIds: JSON.parse(result.data.msgIds),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return result.data;
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
exports.addReactionFactory = addReactionFactory;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
require('../models/AutoReply.cjs');
|
|
5
|
+
require('../models/Board.cjs');
|
|
6
|
+
var Enum = require('../models/Enum.cjs');
|
|
7
|
+
require('../models/FriendEvent.cjs');
|
|
8
|
+
require('../models/Group.cjs');
|
|
9
|
+
require('../models/GroupEvent.cjs');
|
|
10
|
+
var utils = require('../utils.cjs');
|
|
11
|
+
require('../models/Reaction.cjs');
|
|
12
|
+
require('../models/Reminder.cjs');
|
|
13
|
+
require('../models/ZBusiness.cjs');
|
|
14
|
+
|
|
15
|
+
const addUnreadMarkFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
16
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.conversation[0]}/api/conv/addUnreadMark`);
|
|
17
|
+
/**
|
|
18
|
+
* Add unread mark to conversation
|
|
19
|
+
*
|
|
20
|
+
* @param threadId Thread ID
|
|
21
|
+
* @param type Thread type (User/Group)
|
|
22
|
+
*
|
|
23
|
+
* @throws {ZaloApiError}
|
|
24
|
+
*/
|
|
25
|
+
return async function addUnreadMark(threadId, type = Enum.ThreadType.User) {
|
|
26
|
+
const timestamp = Date.now();
|
|
27
|
+
const timestampString = timestamp.toString();
|
|
28
|
+
const isGroup = type === Enum.ThreadType.Group;
|
|
29
|
+
const requestParams = {
|
|
30
|
+
param: JSON.stringify({
|
|
31
|
+
[isGroup ? 'convsGroup' : 'convsUser']: [
|
|
32
|
+
{
|
|
33
|
+
id: threadId,
|
|
34
|
+
cliMsgId: timestampString,
|
|
35
|
+
fromUid: '0',
|
|
36
|
+
ts: timestamp,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
[isGroup ? 'convsUser' : 'convsGroup']: [],
|
|
40
|
+
imei: ctx.imei,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(requestParams));
|
|
44
|
+
if (!encryptedParams)
|
|
45
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
46
|
+
const response = await utils.request(serviceURL, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
body: new URLSearchParams({
|
|
49
|
+
params: encryptedParams,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
return utils.resolve(response, (result) => {
|
|
53
|
+
const data = result.data;
|
|
54
|
+
if (typeof data.data === 'string') {
|
|
55
|
+
return {
|
|
56
|
+
data: JSON.parse(data.data),
|
|
57
|
+
status: data.status,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return result.data;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
exports.addUnreadMarkFactory = addUnreadMarkFactory;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const addUserToGroupFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/invite/v2`);
|
|
8
|
+
/**
|
|
9
|
+
* Add user to existing group
|
|
10
|
+
*
|
|
11
|
+
* @param groupId Group ID
|
|
12
|
+
* @param members User ID or list of user IDs to add
|
|
13
|
+
*
|
|
14
|
+
* @throws ZaloApiError
|
|
15
|
+
*/
|
|
16
|
+
return async function addUserToGroup(groupId, members) {
|
|
17
|
+
if (!Array.isArray(members))
|
|
18
|
+
members = [members];
|
|
19
|
+
const params = {
|
|
20
|
+
grid: groupId,
|
|
21
|
+
members: members,
|
|
22
|
+
membersTypes: members.map(() => -1),
|
|
23
|
+
imei: ctx.imei,
|
|
24
|
+
clientLang: ctx.language,
|
|
25
|
+
};
|
|
26
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
27
|
+
if (!encryptedParams)
|
|
28
|
+
throw new ZaloApiError.ZaloApiError('Failed to encrypt params');
|
|
29
|
+
const response = await utils.request(serviceURL, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: new URLSearchParams({
|
|
32
|
+
params: encryptedParams,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
return utils.resolve(response);
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
exports.addUserToGroupFactory = addUserToGroupFactory;
|