@warriorteam/zalo-personal
Version:
Unofficial Zalo Personal API for JavaScript - A powerful library for interacting with Zalo personal accounts with URL attachment support, auto-reply, product catalog, and business features
46 lines (42 loc) • 1.69 kB
JavaScript
;
var ZaloApiError = require('../Errors/ZaloApiError.cjs');
var utils = require('../utils.cjs');
const getStickersDetailFactory = utils.apiFactory()((api, ctx, utils$1) => {
const serviceURL = utils$1.makeURL(`${api.zpwServiceMap.sticker}/api/message/sticker/sticker_detail`);
/**
* Get stickers detail by sticker IDs
*
* @param stickerIds Sticker IDs to search for
*
* @throws {ZaloApiError}
*/
return async function getStickersDetail(stickerIds) {
if (!stickerIds)
throw new ZaloApiError.ZaloApiError("Missing sticker id");
if (!Array.isArray(stickerIds))
stickerIds = [stickerIds];
if (stickerIds.length == 0)
throw new ZaloApiError.ZaloApiError("Missing sticker id");
const stickers = [];
const tasks = stickerIds.map((stickerId) => getStickerDetail(stickerId));
const tasksResult = await Promise.allSettled(tasks);
tasksResult.forEach((result) => {
if (result.status === "fulfilled")
stickers.push(result.value);
});
return stickers;
};
async function getStickerDetail(stickerId) {
const params = {
sid: stickerId,
};
const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError.ZaloApiError("Failed to encrypt message");
const response = await utils$1.request(utils$1.makeURL(serviceURL, {
params: encryptedParams,
}));
return utils.resolveResponse(ctx, response);
}
});
exports.getStickersDetailFactory = getStickersDetailFactory;