update lại thư mục cấu trúc mới của server nodejs và python
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
import { ZaloApiError } from "../Errors/ZaloApiError.js";
|
||||
import { apiFactory, resolveResponse } from "../utils.js";
|
||||
export const getStickersDetailFactory = apiFactory()((api, ctx, utils) => {
|
||||
const serviceURL = utils.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("Missing sticker id");
|
||||
if (!Array.isArray(stickerIds))
|
||||
stickerIds = [stickerIds];
|
||||
if (stickerIds.length == 0)
|
||||
throw new 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.encodeAES(JSON.stringify(params));
|
||||
if (!encryptedParams)
|
||||
throw new ZaloApiError("Failed to encrypt message");
|
||||
const response = await utils.request(utils.makeURL(serviceURL, {
|
||||
params: encryptedParams,
|
||||
}));
|
||||
return resolveResponse(ctx, response);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user