UNPKG

@nguyennhuy/zalo-api

Version:

Unofficial Zalo API for JavaScript

26 lines (25 loc) 885 B
import { ZaloApiError } from "../../Errors/ZaloApiError.js"; import { apiFactory } from "../../utils.js"; export const getAvatarFactory = apiFactory()((api, ctx, utils) => { const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/profile/avatar`); /** * get avatar * * @throws ZaloApiError * */ return async function getAvatar(fid) { const params = { fid, imei: ctx.imei, }; const encryptedParams = utils.encodeAES(JSON.stringify(params)); if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params"); const urlWithParams = `${serviceURL}&params=${encodeURIComponent(encryptedParams)}`; const response = await utils.request(urlWithParams, { method: "GET", }); return utils.resolve(response); }; });