update lại thư mục cấu trúc mới của server nodejs và python

This commit is contained in:
Victor Phan
2026-07-21 09:13:52 +07:00
parent 7625bdd37b
commit 58b1dcd170
1555 changed files with 0 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
export type AcceptFriendRequestResponse = "";
export declare const acceptFriendRequestFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (friendId: string) => Promise<"">;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const acceptFriendRequestFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/accept`);
/**
* Accept a friend request from a User
*
* @param friendId The friend ID to user request is accept
*
* @throws {ZaloApiError}
*/
return async function acceptFriendRequest(friendId) {
const params = {
fid: friendId,
language: ctx.language,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type AddGroupBlockedMemberResponse = "";
export declare const addGroupBlockedMemberFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (memberId: string | string[], groupId: string) => Promise<"">;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const addGroupBlockedMemberFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/blockedmems/add`);
/**
* Add group blocked member
*
* @param memberId member id(s)
* @param groupId group id
*
* @throws {ZaloApiError}
*/
return async function addGroupBlockedMember(memberId, groupId) {
if (!Array.isArray(memberId))
memberId = [memberId];
const params = {
grid: groupId,
members: memberId,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type AddGroupDeputyResponse = "";
export declare const addGroupDeputyFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (memberId: string | string[], groupId: string) => Promise<"">;
+30
View File
@@ -0,0 +1,30 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const addGroupDeputyFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/admins/add`);
/**
* Add group deputy
*
* @param memberId user Id or list of user Ids
* @param groupId group Id
*
* @throws {ZaloApiError}
*
*/
return async function addGroupDeputy(memberId, groupId) {
if (!Array.isArray(memberId))
memberId = [memberId];
const params = {
grid: groupId,
members: memberId,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+14
View File
@@ -0,0 +1,14 @@
import type { PollOptions } from "../models/index.js";
export type AddPollOptionsOption = {
voted: boolean;
content: string;
};
export type AddPollOptionsPayload = {
pollId: number;
options: AddPollOptionsOption[];
votedOptionIds: number[];
};
export type AddPollOptionsResponse = {
options: PollOptions[];
};
export declare const addPollOptionsFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload: AddPollOptionsPayload) => Promise<AddPollOptionsResponse>;
+26
View File
@@ -0,0 +1,26 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const addPollOptionsFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/poll/option/add`);
/**
* Add new option to poll
*
* @param payload
*
* @throws {ZaloApiError}
*/
return async function addPollOptions(payload) {
const params = {
poll_id: payload.pollId,
new_options: JSON.stringify(payload.options),
voted_option_ids: payload.votedOptionIds,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+11
View File
@@ -0,0 +1,11 @@
import type { QuickMessage, AttachmentSource } from "../models/index.js";
export type AddQuickMessagePayload = {
keyword: string;
title: string;
media?: AttachmentSource;
};
export type AddQuickMessageResponse = {
item: QuickMessage;
version: number;
};
export declare const addQuickMessageFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (addPayload: AddQuickMessagePayload) => Promise<AddQuickMessageResponse>;
+60
View File
@@ -0,0 +1,60 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const addQuickMessageFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.quick_message[0]}/api/quickmessage/create`);
/**
* Add quick message
*
* @param addPayload - The payload containing data to add the quick message
*
* @note Zalo might throw an error with code 821 if you have reached the limit of quick messages.
*
* @throws {ZaloApiError}
*/
return async function addQuickMessage(addPayload) {
const isType = !addPayload.media ? 0 : 1;
const params = {
keyword: addPayload.keyword,
message: {
title: addPayload.title,
params: "",
},
type: isType,
imei: ctx.imei,
};
if (isType === 1) {
if (!addPayload.media)
throw new ZaloApiError("Media is required");
const uploadMedia = await api.uploadProductPhoto({
file: addPayload.media,
});
const photoId = uploadMedia.photoId;
const thumbUrl = uploadMedia.thumbUrl;
const normalUrl = uploadMedia.normalUrl;
const hdUrl = uploadMedia.hdUrl;
params.media = {
items: [
{
type: 0,
photoId: photoId,
title: "",
width: "",
height: "",
previewThumb: thumbUrl,
rawUrl: normalUrl || hdUrl,
thumbUrl: thumbUrl,
normalUrl: normalUrl || hdUrl,
hdUrl: hdUrl || normalUrl,
},
],
};
}
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+18
View File
@@ -0,0 +1,18 @@
import { ThreadType, Reactions } from "../models/index.js";
export type AddReactionResponse = {
msgIds: number[];
};
export type CustomReaction = {
rType: number;
source: number;
icon: string;
};
export type AddReactionDestination = {
data: {
msgId: string;
cliMsgId: string;
};
threadId: string;
type: ThreadType;
};
export declare const addReactionFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (icon: Reactions | CustomReaction, dest: AddReactionDestination) => Promise<AddReactionResponse>;
+294
View File
@@ -0,0 +1,294 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType, Reactions } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const addReactionFactory = apiFactory()((api, ctx, utils) => {
const serviceURLs = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.reaction[0]}/api/message/reaction`),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.reaction[0]}/api/group/reaction`),
};
/**
* Add reaction to a message
*
* @param icon Reaction icon
* @param dest Destination data including message IDs and thread information
*
* @throws {ZaloApiError}
*/
return async function addReaction(icon, dest) {
const serviceURL = serviceURLs[dest.type];
let rType, source;
if (typeof icon == "object") {
rType = icon.rType;
source = icon.source;
}
else
switch (icon) {
case Reactions.HAHA:
rType = 0;
source = 6;
break;
case Reactions.LIKE:
rType = 3;
source = 6;
break;
case Reactions.HEART:
rType = 5;
source = 6;
break;
case Reactions.WOW:
rType = 32;
source = 6;
break;
case Reactions.CRY:
rType = 2;
source = 6;
break;
case Reactions.ANGRY:
rType = 20;
source = 6;
break;
case Reactions.KISS:
rType = 8;
source = 6;
break;
case Reactions.TEARS_OF_JOY:
rType = 7;
source = 6;
break;
case Reactions.SHIT:
rType = 66;
source = 6;
break;
case Reactions.ROSE:
rType = 120;
source = 6;
break;
case Reactions.BROKEN_HEART:
rType = 65;
source = 6;
break;
case Reactions.DISLIKE:
rType = 4;
source = 6;
break;
case Reactions.LOVE:
rType = 29;
source = 6;
break;
case Reactions.CONFUSED:
rType = 51;
source = 6;
break;
case Reactions.WINK:
rType = 45;
source = 6;
break;
case Reactions.FADE:
rType = 121;
source = 6;
break;
case Reactions.SUN:
rType = 67;
source = 6;
break;
case Reactions.BIRTHDAY:
rType = 126;
source = 6;
break;
case Reactions.BOMB:
rType = 127;
source = 6;
break;
case Reactions.OK:
rType = 68;
source = 6;
break;
case Reactions.PEACE:
rType = 69;
source = 6;
break;
case Reactions.THANKS:
rType = 70;
source = 6;
break;
case Reactions.PUNCH:
rType = 71;
source = 6;
break;
case Reactions.SHARE:
rType = 72;
source = 6;
break;
case Reactions.PRAY:
rType = 73;
source = 6;
break;
case Reactions.NO:
rType = 131;
source = 6;
break;
case Reactions.BAD:
rType = 132;
source = 6;
break;
case Reactions.LOVE_YOU:
rType = 133;
source = 6;
break;
case Reactions.SAD:
rType = 1;
source = 6;
break;
case Reactions.VERY_SAD:
rType = 16;
source = 6;
break;
case Reactions.COOL:
rType = 21;
source = 6;
break;
case Reactions.NERD:
rType = 22;
source = 6;
break;
case Reactions.BIG_SMILE:
rType = 23;
source = 6;
break;
case Reactions.SUNGLASSES:
rType = 26;
source = 6;
break;
case Reactions.NEUTRAL:
rType = 30;
source = 6;
break;
case Reactions.SAD_FACE:
rType = 35;
source = 6;
break;
case Reactions.BYE:
rType = 36;
source = 6;
break;
case Reactions.SLEEPY:
rType = 38;
source = 6;
break;
case Reactions.WIPE:
rType = 39;
source = 6;
break;
case Reactions.DIG:
rType = 42;
source = 6;
break;
case Reactions.ANGUISH:
rType = 44;
source = 6;
break;
case Reactions.HANDCLAP:
rType = 46;
source = 6;
break;
case Reactions.ANGRY_FACE:
rType = 47;
source = 6;
break;
case Reactions.F_CHAIR:
rType = 48;
source = 6;
break;
case Reactions.L_CHAIR:
rType = 49;
source = 6;
break;
case Reactions.R_CHAIR:
rType = 50;
source = 6;
break;
case Reactions.SILENT:
rType = 52;
source = 6;
break;
case Reactions.SURPRISE:
rType = 53;
source = 6;
break;
case Reactions.EMBARRASSED:
rType = 54;
source = 6;
break;
case Reactions.AFRAID:
rType = 60;
source = 6;
break;
case Reactions.SAD2:
rType = 61;
source = 6;
break;
case Reactions.BIG_LAUGH:
rType = 62;
source = 6;
break;
case Reactions.RICH:
rType = 63;
source = 6;
break;
case Reactions.BEER:
rType = 99;
source = 6;
break;
default:
rType = -1;
source = 6;
}
const rIcon = typeof icon == "object" ? icon.icon : icon;
if (rType == undefined || source == undefined || rIcon == undefined) {
throw new ZaloApiError("Invalid reaction");
}
const params = {
react_list: [
{
message: JSON.stringify({
rMsg: [
{
gMsgID: parseInt(dest.data.msgId),
cMsgID: parseInt(dest.data.cliMsgId),
msgType: 1,
},
],
rIcon,
rType,
source,
}),
clientId: Date.now(),
},
],
};
if (dest.type == ThreadType.User) {
params.toid = dest.threadId;
}
else {
params.grid = dest.threadId;
params.imei = ctx.imei;
}
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt message");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response, (result) => {
if (typeof result.data.msgIds === "string") {
return {
msgIds: JSON.parse(result.data.msgIds),
};
}
return result.data;
});
};
});
+8
View File
@@ -0,0 +1,8 @@
import { ThreadType } from "../models/index.js";
export type AddUnreadMarkResponse = {
data: {
updateId: number;
};
status: number;
};
export declare const addUnreadMarkFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (threadId: string, type?: ThreadType) => Promise<AddUnreadMarkResponse>;
+52
View File
@@ -0,0 +1,52 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const addUnreadMarkFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.conversation[0]}/api/conv/addUnreadMark`);
/**
* Add unread mark to conversation
*
* @param threadId Thread ID
* @param type Thread type (User/Group)
*
* @throws {ZaloApiError}
*/
return async function addUnreadMark(threadId, type = ThreadType.User) {
const timestamp = Date.now();
const timestampString = timestamp.toString();
const isGroup = type === ThreadType.Group;
const requestParams = {
param: JSON.stringify({
[isGroup ? "convsGroup" : "convsUser"]: [
{
id: threadId,
cliMsgId: timestampString,
fromUid: "0",
ts: timestamp,
},
],
[isGroup ? "convsUser" : "convsGroup"]: [],
imei: ctx.imei,
}),
};
const encryptedParams = utils.encodeAES(JSON.stringify(requestParams));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response, (result) => {
const data = result.data;
if (typeof data.data === "string") {
return {
data: JSON.parse(data.data),
status: data.status,
};
}
return result.data;
});
};
});
+5
View File
@@ -0,0 +1,5 @@
export type AddUserToGroupResponse = {
errorMembers: string[];
error_data: Record<string, string[]>;
};
export declare const addUserToGroupFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (memberId: string | string[], groupId: string) => Promise<AddUserToGroupResponse>;
+34
View File
@@ -0,0 +1,34 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const addUserToGroupFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/invite/v2`);
/**
* Add user to existing group
*
* @param memberId User ID or list of user IDs to add
* @param groupId Group ID
*
* @throws {ZaloApiError}
*/
return async function addUserToGroup(memberId, groupId) {
if (!Array.isArray(memberId))
memberId = [memberId];
const params = {
grid: groupId,
members: memberId,
memberTypes: memberId.map(() => -1),
imei: ctx.imei,
clientLang: ctx.language,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type BlockUserResponse = "";
export declare const blockUserFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (userId: string) => Promise<"">;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const blockUserFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/block`);
/**
* Block a User
*
* @param userId The ID of the User to block
*
* @throws {ZaloApiError}
*/
return async function blockUser(userId) {
const params = {
fid: userId,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type BlockViewFeedResponse = "";
export declare const blockViewFeedFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (isBlockFeed: boolean, userId: string) => Promise<"">;
+30
View File
@@ -0,0 +1,30 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const blockViewFeedFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/feed/block`);
/**
* Block/Unblock friend view feed by ID
*
* @param isBlockFeed Boolean to block/unblock view feed
* @param userId User ID to block/unblock view feed
*
* @throws {ZaloApiError}
*/
return async function blockViewFeed(isBlockFeed, userId) {
const params = {
fid: userId,
isBlockFeed: isBlockFeed ? 1 : 0,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+3
View File
@@ -0,0 +1,3 @@
import type { AttachmentSource } from "../models/index.js";
export type ChangeAccountAvatarResponse = "";
export declare const changeAccountAvatarFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (avatarSource: AttachmentSource) => Promise<"">;
+52
View File
@@ -0,0 +1,52 @@
import FormData from "form-data";
import fs from "node:fs";
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory, formatTime, getImageMetaData } from "../utils.js";
export const changeAccountAvatarFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.file[0]}/api/profile/upavatar`);
/**
* Change account avatar
*
* @param avatarSource Attachment source, can be a file path or an Attachment object
*
* @throws {ZaloApiError | ZaloApiMissingImageMetadataGetter}
*/
return async function changeAccountAvatar(avatarSource) {
const isSourceFilePath = typeof avatarSource == "string";
const imageMetaData = isSourceFilePath ? await getImageMetaData(ctx, avatarSource) : avatarSource.metadata;
const fileSize = imageMetaData.totalSize || 0;
const params = {
avatarSize: 120,
clientId: String(ctx.uid + formatTime("%H:%M %d/%m/%Y")),
language: ctx.language,
metaData: JSON.stringify({
origin: {
width: imageMetaData.width || 1080,
height: imageMetaData.height || 1080,
},
processed: {
width: imageMetaData.width || 1080,
height: imageMetaData.height || 1080,
size: fileSize,
},
}),
};
const avatarData = isSourceFilePath ? fs.readFileSync(avatarSource) : avatarSource.data;
const formData = new FormData();
formData.append("fileContent", avatarData, {
filename: "blob",
contentType: "image/jpeg",
});
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, {
params: encryptedParams,
}), {
method: "POST",
headers: formData.getHeaders(),
body: formData.getBuffer(),
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type ChangeFriendAliasResponse = "";
export declare const changeFriendAliasFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (alias: string, friendId: string) => Promise<"">;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const changeFriendAliasFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.alias[0]}/api/alias/update`);
/**
* Change friend's alias
*
* @param alias new alias (nickname - bietdanh)
* @param friendId friend id
*
* @throws {ZaloApiError}
*/
return async function changeFriendAlias(alias, friendId) {
const params = {
friendId: friendId,
alias: alias,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+3
View File
@@ -0,0 +1,3 @@
import type { AttachmentSource } from "../models/index.js";
export type ChangeGroupAvatarResponse = "";
export declare const changeGroupAvatarFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (avatarSource: AttachmentSource, groupId: string) => Promise<"">;
+44
View File
@@ -0,0 +1,44 @@
import FormData from "form-data";
import fs from "node:fs";
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory, getFullTimeFromMillisecond, getImageMetaData } from "../utils.js";
export const changeGroupAvatarFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.file[0]}/api/group/upavatar`);
/**
* Change group avatar
*
* @param avatarSource Attachment source, can be a file path or an Attachment object
* @param groupId Group ID
*
* @throws {ZaloApiError | ZaloApiMissingImageMetadataGetter}
*/
return async function changeGroupAvatar(avatarSource, groupId) {
const params = {
grid: groupId,
avatarSize: 120,
clientId: `g${groupId}${getFullTimeFromMillisecond(new Date().getTime())}`,
imei: ctx.imei,
};
const isSourceFilePath = typeof avatarSource == "string";
const imageMetaData = isSourceFilePath ? await getImageMetaData(ctx, avatarSource) : avatarSource.metadata;
params.originWidth = imageMetaData.width || 1080;
params.originHeight = imageMetaData.height || 1080;
const avatarData = isSourceFilePath ? fs.readFileSync(avatarSource) : avatarSource.data;
const formData = new FormData();
formData.append("fileContent", avatarData, {
filename: "blob",
contentType: "image/jpeg",
});
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, {
params: encryptedParams,
}), {
method: "POST",
headers: formData.getHeaders(),
body: formData.getBuffer(),
});
return utils.resolve(response);
};
});
+4
View File
@@ -0,0 +1,4 @@
export type ChangeGroupNameResponse = {
status: number;
};
export declare const changeGroupNameFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (name: string, groupId: string) => Promise<ChangeGroupNameResponse>;
+32
View File
@@ -0,0 +1,32 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const changeGroupNameFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/updateinfo`);
/**
* Change group name
*
* @param name New group name
* @param groupId Group ID
*
* @throws {ZaloApiError}
*/
return async function changeGroupName(name, groupId) {
if (name.length == 0)
name = Date.now().toString();
const params = {
grid: groupId,
gname: name,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+4
View File
@@ -0,0 +1,4 @@
export type ChangeGroupOwnerResponse = {
time: number;
};
export declare const changeGroupOwnerFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (memberId: string, groupId: string) => Promise<ChangeGroupOwnerResponse>;
+30
View File
@@ -0,0 +1,30 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const changeGroupOwnerFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/change-owner`);
/**
* Change group owner
*
* @param memberId User Id of new group owner
* @param groupId Group Id
* @note Be careful when changing the key, as it will result in losing group admin rights
*
* @throws {ZaloApiError}
*
*/
return async function changeGroupOwner(memberId, groupId) {
const params = {
grid: groupId,
newAdminId: memberId,
imei: ctx.imei,
language: ctx.language,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+14
View File
@@ -0,0 +1,14 @@
import type { AutoReplyItem, AutoReplyScope } from "../models/index.js";
export type CreateAutoReplyPayload = {
content: string;
isEnable: boolean;
startTime: number;
endTime: number;
scope: AutoReplyScope;
uids?: string | string[];
};
export type CreateAutoReplyResponse = {
item: AutoReplyItem;
version: number;
};
export declare const createAutoReplyFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload: CreateAutoReplyPayload) => Promise<CreateAutoReplyResponse>;
+37
View File
@@ -0,0 +1,37 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createAutoReplyFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.auto_reply[0]}/api/autoreply/create`);
/**
* Create auto reply
*
* @param payload payload
*
* @note this API used for zBusiness
* @throws {ZaloApiError}
*/
return async function createAutoReply(payload) {
const uids = Array.isArray(payload.uids) ? payload.uids : [payload.uids];
const resultUids = (payload.scope === 2 || payload.scope === 3) ? uids : [];
const params = {
cliLang: ctx.language,
enable: payload.isEnable,
content: payload.content,
startTime: payload.startTime,
endTime: payload.endTime,
recurrence: ["RRULE:FREQ=DAILY;"],
scope: payload.scope,
uids: resultUids,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+7
View File
@@ -0,0 +1,7 @@
import type { CatalogItem } from "../models/index.js";
export type CreateCatalogResponse = {
item: CatalogItem;
version_ls_catalog: number;
version_catalog: number;
};
export declare const createCatalogFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (catalogName: string) => Promise<CreateCatalogResponse>;
+29
View File
@@ -0,0 +1,29 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createCatalogFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/catalog/create`);
/**
* Create catalog?
*
* @param catalogName catalog name
*
* @note this API is used for zBusiness
* @throws {ZaloApiError}
*/
return async function createCatalog(catalogName) {
const params = {
catalog_name: catalogName,
catalog_photo: "",
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+28
View File
@@ -0,0 +1,28 @@
import type { AttachmentSource } from "../models/index.js";
export type CreateGroupResponse = {
groupType: number;
sucessMembers: string[];
groupId: string;
errorMembers: string[];
error_data: Record<string, unknown>;
};
export type CreateGroupOptions = {
/**
* Group name
*/
name?: string;
/**
* List of member IDs to add to the group
*/
members: string[];
/**
* Avatar source, can be a file path or an Attachment object
*/
avatarSource?: AttachmentSource;
/**
* Path to the avatar image file
* @deprecated Use `avatarSource` instead
*/
avatarPath?: string;
};
export declare const createGroupFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: CreateGroupOptions) => Promise<CreateGroupResponse>;
+43
View File
@@ -0,0 +1,43 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createGroupFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/create/v2`);
/**
* Create a new group
*
* @param options Group options
*
* @throws {ZaloApiError}
*/
return async function createGroup(options) {
if (options.members.length == 0)
throw new ZaloApiError("Group must have at least one member");
const params = {
clientId: Date.now(),
gname: String(Date.now()),
gdesc: null,
members: options.members,
membersTypes: options.members.map(() => -1),
nameChanged: 0,
createLink: 1,
clientLang: ctx.language,
imei: ctx.imei,
zsource: 601,
};
if (options.name && options.name.length > 0) {
params.gname = options.name;
params.nameChanged = 1;
}
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 }), {
method: "POST",
});
const data = await utils.resolve(response);
options.avatarSource = options.avatarSource || options.avatarPath;
if (options.avatarSource)
await api.changeGroupAvatar(options.avatarSource, data.groupId).catch(utils.logger.error);
return data;
};
});
+7
View File
@@ -0,0 +1,7 @@
import type { NoteDetail } from "../models/index.js";
export type CreateNoteOptions = {
title: string;
pinAct?: boolean;
};
export type CreateNoteResponse = NoteDetail;
export declare const createNoteFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: CreateNoteOptions, groupId: string) => Promise<NoteDetail>;
+47
View File
@@ -0,0 +1,47 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createNoteFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/createv2`);
/**
* Create a note in a group
*
* @param options note options
* @param options.title note title
* @param options.pinAct pin action (pin note)
* @param groupId group id
*
* @throws {ZaloApiError}
*/
return async function createNote(options, groupId) {
const params = {
grid: groupId,
type: 0,
color: -16777216,
emoji: "",
startTime: -1,
duration: -1,
params: JSON.stringify({
title: options.title,
}),
repeat: 0,
src: 1,
imei: ctx.imei,
pinAct: options.pinAct ? 1 : 0,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response, (result) => {
if (typeof result.data.params === "string") {
result.data.params = JSON.parse(result.data.params);
}
return result.data;
});
};
});
+36
View File
@@ -0,0 +1,36 @@
import type { PollDetail } from "../models/index.js";
/**
* Options for creating a poll.
*/
export type CreatePollOptions = {
/**
* Question for the poll.
*/
question: string;
/**
* List of options for the poll.
*/
options: string[];
/**
* Poll expiration time in milliseconds (0 = no expiration).
*/
expiredTime?: number;
/**
* Allows multiple choices in the poll.
*/
allowMultiChoices?: boolean;
/**
* Allows members to add new options to the poll.
*/
allowAddNewOption?: boolean;
/**
* Hides voting results until the user has voted.
*/
hideVotePreview?: boolean;
/**
* Hides poll voters (anonymous poll).
*/
isAnonymous?: boolean;
};
export type CreatePollResponse = PollDetail;
export declare const createPollFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: CreatePollOptions, groupId: string) => Promise<PollDetail>;
+40
View File
@@ -0,0 +1,40 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createPollFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/poll/create`);
/**
* Create a poll in a group.
*
* @param options Poll options
* @param groupId Group ID to create poll from
*
* @throws {ZaloApiError}
*/
return async function createPoll(options, groupId) {
var _a;
const params = {
group_id: groupId,
question: options.question,
options: options.options,
expired_time: (_a = options.expiredTime) !== null && _a !== void 0 ? _a : 0,
pinAct: false,
allow_multi_choices: !!options.allowMultiChoices,
allow_add_new_option: !!options.allowAddNewOption,
is_hide_vote_preview: !!options.hideVotePreview,
is_anonymous: !!options.isAnonymous,
poll_type: 0,
src: 1,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+23
View File
@@ -0,0 +1,23 @@
import type { AttachmentSource, ProductCatalogItem } from "../models/index.js";
export type CreateProductCatalogPayload = {
catalogId: string;
productName: string;
price: string;
description: string;
/**
* Upto 5 media files are allowed, will be ignored if product_photos is provided
*/
files?: AttachmentSource[];
/**
* List of product photo URLs, upto 5
*
* You can manually get the URL using `uploadProductPhoto` api
*/
product_photos?: string[];
};
export type CreateProductCatalogResponse = {
item: ProductCatalogItem;
version_ls_catalog: number;
version_catalog: number;
};
export declare const createProductCatalogFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload: CreateProductCatalogPayload) => Promise<CreateProductCatalogResponse>;
+50
View File
@@ -0,0 +1,50 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const createProductCatalogFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/product/create`);
/**
* Create product catalog?
*
* @param payload payload
*
* @note this API is used for zBussiness - Maximum 5 media files are supported
* @throws {ZaloApiError}
*/
return async function createProductCatalog(payload) {
const productPhoto = payload.product_photos || [];
if (payload.files && payload.files.length == 0) {
if (payload.files.length > 5) {
throw new ZaloApiError("Maximum 5 media files are allowed");
}
for (const mediaFile of payload.files) {
const uploadMedia = await api.uploadProductPhoto({
file: mediaFile,
});
const url = uploadMedia.normalUrl || uploadMedia.hdUrl;
productPhoto.push(url);
}
}
if (productPhoto.length > 5) {
throw new ZaloApiError("Maximum 5 media files are allowed");
}
const params = {
product_name: payload.productName,
price: payload.price,
description: payload.description,
product_photos: productPhoto,
catalog_id: payload.catalogId,
currency_unit: "₫", // $
create_time: Date.now(),
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+12
View File
@@ -0,0 +1,12 @@
import type { ReminderGroup, ReminderUser } from "../models/index.js";
import { ReminderRepeatMode, ThreadType } from "../models/index.js";
export type CreateReminderOptions = {
title: string;
emoji?: string;
startTime?: number;
repeat?: ReminderRepeatMode;
};
export type CreateReminderUser = ReminderUser;
export type CreateReminderGroup = Omit<ReminderGroup, "responseMem">;
export type CreateReminderResponse = CreateReminderUser | CreateReminderGroup;
export declare const createReminderFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: CreateReminderOptions, threadId: string, type?: ThreadType) => Promise<CreateReminderResponse>;
+63
View File
@@ -0,0 +1,63 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ReminderRepeatMode, ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const createReminderFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/oneone/create`),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/createv2`),
};
/**
* Create a reminder in a group
*
* @param options reminder options
* @param threadId Group ID to create note from
* @param type Thread type (User or Group)
*
* @throws {ZaloApiError}
*/
return async function createReminder(options, threadId, type = ThreadType.User) {
var _a, _b, _c, _d, _e, _f;
const params = type === ThreadType.User
? {
objectData: JSON.stringify({
toUid: threadId,
type: 0,
color: -16245706,
emoji: (_a = options.emoji) !== null && _a !== void 0 ? _a : "⏰",
startTime: (_b = options.startTime) !== null && _b !== void 0 ? _b : Date.now(),
duration: -1,
params: { title: options.title },
needPin: false,
repeat: (_c = options.repeat) !== null && _c !== void 0 ? _c : ReminderRepeatMode.None,
creatorUid: ctx.uid, // Note: for some reason, you can put any valid UID here instead of your own and it still works, atleast for mobile
src: 1,
}),
imei: ctx.imei,
}
: {
grid: threadId,
type: 0,
color: -16245706,
emoji: (_d = options.emoji) !== null && _d !== void 0 ? _d : "⏰",
startTime: (_e = options.startTime) !== null && _e !== void 0 ? _e : Date.now(),
duration: -1,
params: JSON.stringify({
title: options.title,
}),
repeat: (_f = options.repeat) !== null && _f !== void 0 ? _f : ReminderRepeatMode.None,
src: 1,
imei: ctx.imei,
pinAct: 0,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL[type], {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+9
View File
@@ -0,0 +1,9 @@
import { type ContextSession } from "../context.js";
import { type FactoryUtils } from "../utils.js";
export type CustomAPIProps<T, K> = {
ctx: ContextSession;
utils: FactoryUtils<T>;
props: K;
};
export type CustomAPICallback<T, K> = (props: CustomAPIProps<T, K>) => T | Promise<T>;
export declare const customFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => <T, K = any>(name: string, callback: CustomAPICallback<T, K>) => void;
+15
View File
@@ -0,0 +1,15 @@
import {} from "../context.js";
import { apiFactory } from "../utils.js";
/* eslint-disable */
export const customFactory = apiFactory()((api, ctx, utils) => {
return function custom(name, callback) {
Object.defineProperty(api, name, {
value: function (props) {
return callback({ ctx, utils, props });
},
writable: false,
enumerable: false,
configurable: false,
});
};
});
+5
View File
@@ -0,0 +1,5 @@
export type DeleteAutoReplyResponse = {
item: number;
version: number;
};
export declare const deleteAutoReplyFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (id: number) => Promise<DeleteAutoReplyResponse>;
+29
View File
@@ -0,0 +1,29 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const deleteAutoReplyFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.auto_reply[0]}/api/autoreply/delete`);
/**
* Delete auto reply
*
* @param id id of auto reply
*
* @note this API used for zBusiness
* @throws {ZaloApiError}
*/
return async function deleteAutoReply(id) {
const params = {
cliLang: ctx.language,
id: id,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+9
View File
@@ -0,0 +1,9 @@
export type DeleteAvatarResponse = {
delPhotoIds: string[];
errMap: {
[key: string]: {
err: number;
};
};
};
export declare const deleteAvatarFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (photoId: string | string[]) => Promise<DeleteAvatarResponse>;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const deleteAvatarFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/del-avatars`);
/**
* Delete avatar from avatar list
*
* @param photoId avatar photo ID(s) to delete - can be a single string or array of strings
*
* @throws {ZaloApiError}
*/
return async function deleteAvatar(photoId) {
const photoIds = Array.isArray(photoId) ? photoId : [photoId];
const delPhotos = photoIds.map((id) => ({ photoId: id }));
const params = {
delPhotos: JSON.stringify(delPhotos),
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type DeleteCatalogResponse = "";
export declare const deleteCatalogFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (catalogId: string) => Promise<"">;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const deleteCatalogFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/catalog/delete`);
/**
* Delete catalog?
*
* @param catalogId catalog id
*
* @note this API is used for zBusiness
* @throws {ZaloApiError}
*/
return async function deleteCatalog(catalogId) {
const params = {
catalog_id: catalogId,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+19
View File
@@ -0,0 +1,19 @@
import { ThreadType } from "../models/index.js";
export type DeleteChatResponse = {
status: number;
};
export type DeleteChatLastMessage = {
/**
* Last message owner ID to delete backwards
*/
ownerId: string;
/**
* Last message client ID to delete backwards
*/
cliMsgId: string;
/**
* Last message global ID to delete backwards
*/
globalMsgId: string;
};
export declare const deleteChatFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (lastMessage: DeleteChatLastMessage, threadId: string, type?: ThreadType) => Promise<DeleteChatResponse>;
+50
View File
@@ -0,0 +1,50 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const deleteChatFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.chat[0]}/api/message/deleteconver`, {
nretry: 0,
}),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/deleteconver`, {
nretry: 0,
}),
};
/**
* Delete chat
*
* @param lastMessage Last message info
* @param threadId Thread ID
* @param type Thread type
*
* @throws {ZaloApiError}
*/
return async function deleteChat(lastMessage, threadId, type = ThreadType.User) {
const timestampString = Date.now().toString();
const params = type === ThreadType.User
? {
toid: threadId,
cliMsgId: timestampString,
conver: lastMessage,
onlyMe: 1,
imei: ctx.imei,
}
: {
grid: threadId,
cliMsgId: timestampString,
conver: lastMessage,
onlyMe: 1,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL[type], {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+9
View File
@@ -0,0 +1,9 @@
export type DeleteGroupInviteBoxResponse = {
delInvitaionIds: string[];
errMap: {
[groupId: string]: {
err: number;
};
};
};
export declare const deleteGroupInviteBoxFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (groupId: string | string[], blockFutureInvite?: boolean) => Promise<DeleteGroupInviteBoxResponse>;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const deleteGroupInviteBoxFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/inv-box/mdel-inv`);
/**
* Delete group invite box
*
* @param groupId - The group id
* @param blockFutureInvite - Whether to block future invites from this group
*
* @throws {ZaloApiError}
*/
return async function deleteGroupInviteBox(groupId, blockFutureInvite = false) {
const grids = Array.isArray(groupId) ? groupId : [groupId];
const params = {
invitations: JSON.stringify(grids.map((grid) => ({ grid }))),
block: blockFutureInvite ? 1 : 0,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+14
View File
@@ -0,0 +1,14 @@
import { ThreadType } from "../models/index.js";
export type DeleteMessageResponse = {
status: number;
};
export type DeleteMessageDestination = {
data: {
cliMsgId: string;
msgId: string;
uidFrom: string;
};
threadId: string;
type?: ThreadType;
};
export declare const deleteMessageFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (dest: DeleteMessageDestination, onlyMe?: boolean) => Promise<DeleteMessageResponse>;
+52
View File
@@ -0,0 +1,52 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const deleteMessageFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.chat[0]}/api/message/delete`),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/deletemsg`),
};
/**
* Delete a message
*
* @param dest Delete target
* @param onlyMe Delete message for only you
*
* @throws {ZaloApiError}
*/
return async function deleteMessage(dest, onlyMe = false) {
const { threadId, type = ThreadType.User, data } = dest;
const isGroup = type === ThreadType.Group;
const isSelf = ctx.uid == data.uidFrom;
if (isSelf && onlyMe === false)
throw new ZaloApiError("To delete your message for everyone, use undo api instead");
if (!isGroup && onlyMe === false)
throw new ZaloApiError("Can't delete message for everyone in a private chat");
const params = {
[isGroup ? "grid" : "toid"]: threadId,
cliMsgId: Date.now(),
msgs: [
{
cliMsgId: data.cliMsgId,
globalMsgId: data.msgId,
ownerId: data.uidFrom,
destId: threadId,
},
],
onlyMe: onlyMe ? 1 : 0,
};
if (!isGroup) {
params.imei = ctx.imei;
}
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt message");
const response = await utils.request(serviceURL[type], {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+10
View File
@@ -0,0 +1,10 @@
export type DeleteProductCatalogPayload = {
productIds: string | string[];
catalogId: string;
};
export type DeleteProductCatalogResponse = {
item: number[];
version_ls_catalog: number;
version_catalog: number;
};
export declare const deleteProductCatalogFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload: DeleteProductCatalogPayload) => Promise<DeleteProductCatalogResponse>;
+31
View File
@@ -0,0 +1,31 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const deleteProductCatalogFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/product/mdelete`);
/**
* Delete product catalog?
*
* @param payload payload
*
* @note this API is used for zBusiness
* @throws {ZaloApiError}
*/
return async function deleteProductCatalog(payload) {
if (!Array.isArray(payload.productIds))
payload.productIds = [payload.productIds];
const params = {
product_ids: payload.productIds,
catalog_id: payload.catalogId,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type DisableGroupLinkResponse = "";
export declare const disableGroupLinkFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (groupId: string) => Promise<"">;
+24
View File
@@ -0,0 +1,24 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const disableGroupLinkFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/link/disable`);
/**
* Disable group link
*
* @param groupId The group id
*
* @throws {ZaloApiError}
*/
return async function disableGroupLink(groupId) {
const params = {
grid: groupId,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+2
View File
@@ -0,0 +1,2 @@
export type DisperseGroupResponse = "";
export declare const disperseGroupFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (groupId: string) => Promise<"">;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const disperseGroupFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/disperse`);
/**
* Disperse Group
*
* @param groupId Group ID to disperse Group from
*
* @throws {ZaloApiError}
*/
return async function disperseGroup(groupId) {
const params = {
grid: groupId,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+17
View File
@@ -0,0 +1,17 @@
import type { NoteDetail } from "../models/index.js";
export type EditNoteOptions = {
/**
* New note title
*/
title: string;
/**
* Topic ID to edit note from
*/
topicId: string;
/**
* Should the note be pinned?
*/
pinAct?: boolean;
};
export type EditNoteResponse = NoteDetail;
export declare const editNoteFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: EditNoteOptions, groupId: string) => Promise<NoteDetail>;
+46
View File
@@ -0,0 +1,46 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const editNoteFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/updatev2`);
/**
* Edit an existing note in a group
*
* @param options Options for editing the note
* @param groupId Group ID to create note from
*
* @throws {ZaloApiError}
*/
return async function editNote(options, groupId) {
const params = {
grid: groupId,
type: 0,
color: -16777216,
emoji: "",
startTime: -1,
duration: -1,
params: JSON.stringify({
title: options.title,
}),
topicId: options.topicId,
repeat: 0,
imei: ctx.imei,
pinAct: options.pinAct ? 1 : 2,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response, (result) => {
const data = result.data;
if (typeof data.params == "string") {
data.params = JSON.parse(data.params);
}
return data;
});
};
});
+13
View File
@@ -0,0 +1,13 @@
import type { ReminderRepeatMode, ReminderGroup, ReminderUser } from "../models/index.js";
import { ThreadType } from "../models/index.js";
export type EditReminderOptions = {
title: string;
topicId: string;
emoji?: string;
startTime?: number;
repeat?: ReminderRepeatMode;
};
export type EditReminderUser = ReminderUser;
export type EditReminderGroup = Omit<ReminderGroup, "responseMem">;
export type EditReminderResponse = EditReminderUser | EditReminderGroup;
export declare const editReminderFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (options: EditReminderOptions, threadId: string, type?: ThreadType) => Promise<EditReminderResponse>;
+61
View File
@@ -0,0 +1,61 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const editReminderFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/oneone/update`),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.group_board[0]}/api/board/topic/updatev2`),
};
/**
* Edit an existing reminder
*
* @param options Reminder parameters
* @param threadId Thread ID
* @param type Thread type (User/Group)
*
* @throws {ZaloApiError}
*/
return async function editReminder(options, threadId, type = ThreadType.User) {
var _a, _b, _c, _d, _e, _f;
const requestParams = type === ThreadType.User
? {
objectData: JSON.stringify({
toUid: threadId,
type: 0,
color: -16777216,
emoji: (_a = options.emoji) !== null && _a !== void 0 ? _a : "",
startTime: (_b = options.startTime) !== null && _b !== void 0 ? _b : Date.now(),
duration: -1,
params: { title: options.title },
needPin: false,
reminderId: options.topicId,
repeat: (_c = options.repeat) !== null && _c !== void 0 ? _c : 0,
}),
}
: {
grid: threadId,
type: 0,
color: -16777216,
emoji: (_d = options.emoji) !== null && _d !== void 0 ? _d : "",
startTime: (_e = options.startTime) !== null && _e !== void 0 ? _e : Date.now(),
duration: -1,
params: JSON.stringify({
title: options.title,
}),
topicId: options.topicId,
repeat: (_f = options.repeat) !== null && _f !== void 0 ? _f : 0,
imei: ctx.imei,
pinAct: 2,
};
const encryptedParams = utils.encodeAES(JSON.stringify(requestParams));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL[type], {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+6
View File
@@ -0,0 +1,6 @@
export type EnableGroupLinkResponse = {
link: string;
expiration_date: number;
enabled: number;
};
export declare const enableGroupLinkFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (groupId: string) => Promise<EnableGroupLinkResponse>;
+25
View File
@@ -0,0 +1,25 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const enableGroupLinkFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/link/new`);
/**
* Enable and create new group link
*
* @param groupId The group id
*
* @throws {ZaloApiError}
*/
return async function enableGroupLink(groupId) {
const params = {
grid: groupId,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+5
View File
@@ -0,0 +1,5 @@
import type { User } from "../models/index.js";
export type FetchAccountInfoResponse = {
profile: User;
};
export declare const fetchAccountInfoFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<FetchAccountInfoResponse>;
+10
View File
@@ -0,0 +1,10 @@
import { apiFactory } from "../utils.js";
export const fetchAccountInfoFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/profile/me-v2`);
return async function fetchAccountInfo() {
const response = await utils.request(serviceURL, {
method: "GET",
});
return utils.resolve(response);
};
});
+3
View File
@@ -0,0 +1,3 @@
import { AvatarSize, type UserBasic } from "../models/index.js";
export type FindUserResponse = UserBasic;
export declare const findUserFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (phoneNumber: string, avatarSize?: AvatarSize) => Promise<UserBasic>;
+42
View File
@@ -0,0 +1,42 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
import { AvatarSize } from "../models/index.js";
export const findUserFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/profile/get`);
/**
* Find user by phone number
*
* @param phoneNumber Phone number
* @param avatarSize Avatar size (default: AvatarSize.Large)
*
* @throws {ZaloApiError}
*/
return async function findUser(phoneNumber, avatarSize = AvatarSize.Large) {
if (!phoneNumber)
throw new ZaloApiError("Missing phoneNumber");
if (phoneNumber.startsWith("0")) {
if (ctx.language == "vi")
phoneNumber = "84" + phoneNumber.slice(1);
}
const params = {
phone: phoneNumber,
avatar_size: avatarSize,
language: ctx.language,
imei: ctx.imei,
reqSrc: 40,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt message");
const finalServiceUrl = new URL(serviceURL);
finalServiceUrl.searchParams.append("params", encryptedParams);
const response = await utils.request(utils.makeURL(finalServiceUrl.toString(), {
params: encryptedParams,
}));
return utils.resolve(response, (result) => {
if (result.error && result.error.code != 216)
throw new ZaloApiError(result.error.message, result.error.code);
return result.data;
});
};
});
+3
View File
@@ -0,0 +1,3 @@
import { AvatarSize, type UserBasic } from "../models/index.js";
export type FindUserByUsernameResponse = UserBasic;
export declare const findUserByUsernameFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (username: string, avatarSize?: AvatarSize) => Promise<UserBasic>;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
import { AvatarSize } from "../models/index.js";
export const findUserByUsernameFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.friend[0]}/api/friend/search/by-user-name`);
/**
* Find user by username
*
* @param username username for find
* @param avatarSize Avatar size (default: AvatarSize.Large)
*
* @throws {ZaloApiError}
*/
return async function findUserByUsername(username, avatarSize = AvatarSize.Large) {
const params = {
user_name: username,
avatar_size: avatarSize,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+24
View File
@@ -0,0 +1,24 @@
import { ThreadType } from "../models/index.js";
export type ForwardMessagePayload = {
message: string;
ttl?: number;
reference?: {
id: string;
ts: number;
logSrcType: number;
fwLvl: number;
};
};
export type ForwardMessageSuccess = {
clientId: string;
msgId: string;
};
export type ForwardMessageFail = {
clientId: string;
error_code: string;
};
export type ForwardMessageResponse = {
success: ForwardMessageSuccess[];
fail: ForwardMessageFail[];
};
export declare const forwardMessageFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload: ForwardMessagePayload, threadIds: string[], type?: ThreadType) => Promise<ForwardMessageResponse>;
+99
View File
@@ -0,0 +1,99 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { ThreadType } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const forwardMessageFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = {
[ThreadType.User]: utils.makeURL(`${api.zpwServiceMap.file[0]}/api/message/mforward`),
[ThreadType.Group]: utils.makeURL(`${api.zpwServiceMap.file[0]}/api/group/mforward`),
};
/**
* Forward message to multiple threads
*
* @param payload Forward message payload
* @param threadId Thread ID(s)
* @param type Thread type (User/Group)
*
* @throws {ZaloApiError}
*/
return async function forwardMessage(payload, threadIds, type = ThreadType.User) {
var _a, _b;
if (!payload.message)
throw new ZaloApiError("Missing message content");
if (!threadIds || threadIds.length === 0)
throw new ZaloApiError("Missing thread IDs");
const timestamp = Date.now();
const clientId = timestamp.toString();
const msgInfo = {
message: payload.message,
reference: payload.reference
? JSON.stringify({
type: 3,
data: JSON.stringify(payload.reference),
})
: undefined,
};
const decorLog = payload.reference
? {
fw: {
pmsg: {
st: 1,
ts: payload.reference.ts,
id: payload.reference.id,
},
rmsg: {
st: 1,
ts: payload.reference.ts,
id: payload.reference.id,
},
fwLvl: payload.reference.fwLvl,
},
}
: null;
let params;
if (type === ThreadType.User) {
params = {
toIds: threadIds.map((threadId) => {
var _a;
return ({
clientId,
toUid: threadId,
ttl: (_a = payload.ttl) !== null && _a !== void 0 ? _a : 0,
});
}),
imei: ctx.imei,
ttl: (_a = payload.ttl) !== null && _a !== void 0 ? _a : 0,
msgType: "1",
totalIds: threadIds.length,
msgInfo: JSON.stringify(msgInfo),
decorLog: JSON.stringify(decorLog),
};
}
else {
params = {
grids: threadIds.map((threadId) => {
var _a;
return ({
clientId,
grid: threadId,
ttl: (_a = payload.ttl) !== null && _a !== void 0 ? _a : 0,
});
}),
ttl: (_b = payload.ttl) !== null && _b !== void 0 ? _b : 0,
msgType: "1",
totalIds: threadIds.length,
msgInfo: JSON.stringify(msgInfo),
decorLog: JSON.stringify(decorLog),
};
}
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL[type], {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+8
View File
@@ -0,0 +1,8 @@
export type GetAliasListResponse = {
items: {
userId: string;
alias: string;
}[];
updateTime: string;
};
export declare const getAliasListFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (count?: number, page?: number) => Promise<GetAliasListResponse>;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getAliasListFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.alias[0]}/api/alias/list`);
/**
* Get alias list
*
* @param count Page size (default: 100)
* @param page Page number (default: 1)
*
* @throws {ZaloApiError}
*/
return async function getAliasList(count = 100, page = 1) {
const params = {
page,
count,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+3
View File
@@ -0,0 +1,3 @@
import { AvatarSize, type User } from "../models/index.js";
export type GetAllFriendsResponse = User[];
export declare const getAllFriendsFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (count?: number, page?: number, avatarSize?: AvatarSize) => Promise<GetAllFriendsResponse>;
+34
View File
@@ -0,0 +1,34 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
import { AvatarSize } from "../models/index.js";
export const getAllFriendsFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/friend/getfriends`);
/**
* Get all friends
*
* @param count Page size (default: 20000)
* @param page Page number (default: 1)
* @param avatarSize Avatar size (default: AvatarSize.Small)
*
* @throws {ZaloApiError}
*/
return async function getAllFriends(count = 20000, page = 1, avatarSize = AvatarSize.Small) {
const params = {
incInvalid: 1,
page,
count,
avatar_size: avatarSize,
actiontime: 0,
imei: ctx.imei,
};
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,
}), {
method: "GET",
});
return utils.resolve(response);
};
});
+7
View File
@@ -0,0 +1,7 @@
export type GetAllGroupsResponse = {
version: string;
gridVerMap: {
[groupId: string]: string;
};
};
export declare const getAllGroupsFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<GetAllGroupsResponse>;
+10
View File
@@ -0,0 +1,10 @@
import { apiFactory } from "../utils.js";
export const getAllGroupsFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_poll[0]}/api/group/getlg/v4`);
return async function getAllGroups() {
const response = await utils.request(serviceURL, {
method: "GET",
});
return utils.resolve(response);
};
});
+5
View File
@@ -0,0 +1,5 @@
export type GetArchivedChatListResponse = {
items: unknown[];
version: number;
};
export declare const getArchivedChatListFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<GetArchivedChatListResponse>;
+23
View File
@@ -0,0 +1,23 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getArchivedChatListFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.label[0]}/api/archivedchat/list`);
/**
* Get arcnived chat list
*
* @throws {ZaloApiError}
*/
return async function getArchivedChatList() {
const params = {
version: 1,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+9
View File
@@ -0,0 +1,9 @@
export type GetAutoDeleteChatResponse = {
convers: {
destId: string;
isGroup: boolean;
ttl: number;
createdAt: number;
}[];
};
export declare const getAutoDeleteChatFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<GetAutoDeleteChatResponse>;
+21
View File
@@ -0,0 +1,21 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getAutoDeleteChatFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.conversation[0]}/api/conv/autodelete/getConvers`);
/**
* Get auto delete chat
*
* @throws {ZaloApiError}
*
*/
return async function getAutoDeleteChat() {
const params = {};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+6
View File
@@ -0,0 +1,6 @@
import type { AutoReplyItem } from "../models/index.js";
export type GetAutoReplyListResponse = {
item: AutoReplyItem[];
version: number;
};
export declare const getAutoReplyListFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<GetAutoReplyListResponse>;
+24
View File
@@ -0,0 +1,24 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getAutoReplyListFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.auto_reply[0]}/api/autoreply/list`);
/**
* Get auto reply list
*
* @note this API used for zBusiness
* @throws {ZaloApiError}
*/
return async function getAutoReplyList() {
const params = {
version: 0,
cliLang: ctx.language,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+12
View File
@@ -0,0 +1,12 @@
export type GetAvatarListResponse = {
albumId: string;
nextPhotoId: string;
hasMore: number;
photos: {
photoId: string;
thumbnail: string;
url: string;
bkUrl: string;
}[];
};
export declare const getAvatarListFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (count?: number, page?: number) => Promise<GetAvatarListResponse>;
+28
View File
@@ -0,0 +1,28 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getAvatarListFactory = apiFactory()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/avatar-list`);
/**
* Get avatar list
*
* @param count The number of avatars to fetch (default: 50)
* @param page The page number to fetch (default: 1)
*
* @throws {ZaloApiError}
*/
return async function getAvatarList(count = 50, page = 1) {
const params = {
page,
albumId: "0",
count,
imei: ctx.imei,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+7
View File
@@ -0,0 +1,7 @@
import { AvatarSize } from "../models/index.js";
export type GetAvatarUrlProfileResponse = {
[userId: string]: {
avatar: string;
};
};
export declare const getAvatarUrlProfileFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (friendIds: string | string[], avatarSize?: AvatarSize) => Promise<GetAvatarUrlProfileResponse>;
+30
View File
@@ -0,0 +1,30 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { AvatarSize } from "../models/index.js";
import { apiFactory } from "../utils.js";
export const getAvatarUrlProfileFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/profile/avatar-url`);
/**
* Get avatar url profile
*
* @param friendId friend id(s)
* @param avatarSize Avatar size (default: AvatarSize.Large)
*
* @throws {ZaloApiError}
*/
return async function getAvatarUrlProfile(friendIds, avatarSize = AvatarSize.Large) {
if (!Array.isArray(friendIds))
friendIds = [friendIds];
const params = {
friend_ids: friendIds,
avatar_size: avatarSize,
srcReq: -1,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});
+24
View File
@@ -0,0 +1,24 @@
import type { BusinessCategory } from "../models/index.js";
export type GetBizAccountResponse = {
biz?: {
desc: string | null;
cate: BusinessCategory;
addr: string;
website: string;
email: string;
};
setting_start_page?: {
enable_biz_label: number;
enable_cate: number;
enable_add: number;
cta_profile: number;
/**
* Relative path used to build the catalog URL.
*
* Example: https://catalog.zalo.me/${cta_catalog}
*/
cta_catalog: string | null;
} | null;
pkgId: number;
};
export declare const getBizAccountFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (friendId: string) => Promise<GetBizAccountResponse>;
+27
View File
@@ -0,0 +1,27 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getBizAccountFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/friend/get-bizacc`);
/**
* Get biz account
*
* @param friendId The friend ID to get biz account
*
* @throws {ZaloApiError}
*/
return async function getBizAccount(friendId) {
const params = {
fid: friendId,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+18
View File
@@ -0,0 +1,18 @@
import type { CatalogItem } from "../models/index.js";
export type GetCatalogListPayload = {
/**
* Number of items to retrieve (default: 20)
*/
limit?: number;
lastProductId?: number;
/**
* Page number (default: 0)
*/
page?: number;
};
export type GetCatalogListResponse = {
items: CatalogItem[];
version: number;
has_more: number;
};
export declare const getCatalogListFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => (payload?: GetCatalogListPayload) => Promise<GetCatalogListResponse>;
+32
View File
@@ -0,0 +1,32 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getCatalogListFactory = apiFactory()((api, _, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.catalog[0]}/api/prodcatalog/catalog/list`);
/**
* Get catalog list?
*
* @param payload payload
*
* @note this API is used for zBusiness
* @throws {ZaloApiError}
*/
return async function getCatalogList(payload) {
var _a, _b, _c;
const params = {
version_list_catalog: 0,
limit: (_a = payload === null || payload === void 0 ? void 0 : payload.limit) !== null && _a !== void 0 ? _a : 20,
last_product_id: (_b = payload === null || payload === void 0 ? void 0 : payload.lastProductId) !== null && _b !== void 0 ? _b : -1,
page: (_c = payload === null || payload === void 0 ? void 0 : payload.page) !== null && _c !== void 0 ? _c : 0,
};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});
return utils.resolve(response);
};
});
+3
View File
@@ -0,0 +1,3 @@
import type { User } from "../models/index.js";
export type GetCloseFriendsResponse = User[];
export declare const getCloseFriendsFactory: (ctx: import("../context.js").ContextBase, api: import("../apis.js").API) => () => Promise<GetCloseFriendsResponse>;
+20
View File
@@ -0,0 +1,20 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";
export const getCloseFriendsFactory = apiFactory()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.profile[0]}/api/social/friend/getclosedfriends`);
/**
* Get close friends
*
* @throws {ZaloApiError}
*/
return async function getCloseFriends() {
const params = {};
const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams)
throw new ZaloApiError("Failed to encrypt params");
const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});
return utils.resolve(response);
};
});

Some files were not shown because too many files have changed in this diff Show More