@warriorteam/zalo-personal
Version:
Unofficial Zalo Personal API for JavaScript - A powerful library for interacting with Zalo personal accounts with URL attachment support
48 lines (44 loc) • 1.51 kB
JavaScript
;
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
var utils = require('../utils.cjs');
const getUserInfoFactory = utils.apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/friend/getprofiles/v2`);
/**
* Get user info using user id
*
* @param userId user id
*
* @throws ZaloApiError
*/
return async function getUserInfo(userId) {
if (!userId)
throw new ZaloApiError.ZaloApiError("Missing user id");
if (!Array.isArray(userId))
userId = [userId];
userId = userId.map((id) => {
if (id.split("_").length > 1) {
return id;
}
return `${id}_0`;
});
const params = {
phonebook_version: ctx.extraVer.phonebook,
friend_pversion_map: userId,
avatar_size: 120,
language: ctx.language,
show_online_status: 1,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
exports.getUserInfoFactory = getUserInfoFactory;