evolution-api-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
266 lines (262 loc) • 8.32 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/modules/chats/index.ts
var chats_exports = {};
__export(chats_exports, {
ChatsModule: () => ChatsModule
});
module.exports = __toCommonJS(chats_exports);
// src/api/routes.ts
var Routes = {
Message: {
SendText: "message/sendText",
SendMedia: "message/sendMedia",
SendVoice: "message/sendWhatsAppAudio",
SendSticker: "message/sendSticker",
SendLocation: "message/sendLocation",
SendContact: "message/sendContact",
SendPoll: "message/sendPoll",
SendReaction: "message/sendReaction",
SendTemplate: "message/sendTemplate",
SendStatus: "message/sendStatus",
SendList: "message/sendList"
},
Chats: {
Check: "chat/whatsappNumbers",
FindAll: "chat/findChats",
SendPresence: "chat/sendPresence",
MarkAsRead: "chat/markMessageAsRead",
MarkAsUnread: "chat/markChatUnread",
Archive: "chat/archive",
DeleteMessage: "chat/deleteMessageForEveryone",
FetchProfilePicture: "chat/fetchProfilePictureUrl",
FindContacts: "chat/findContacts",
FindMessages: "chat/findMessages",
FindStatusMessage: "chat/findStatusMessage",
UpdateMessage: "chat/updateMessage"
},
Groups: {
FindAll: "group/fetchAllGroups",
FindByJid: "group/findGroupInfos",
FindByInviteCode: "group/inviteInfo",
Create: "group/create",
UpdatePicture: "group/updateGroupPicture",
UpdateSubject: "group/updateGroupSubject",
UpdateDescription: "group/updateGroupDescription",
FetchInviteCode: "group/fetchInviteCode",
AcceptInviteCode: "group/acceptInviteCode",
RevokeInviteCode: "group/revokeInviteCode",
SendGroupInvite: "group/sendGroupInvite",
FindMembers: "group/findGroupMembers",
UpdateMembers: "group/updateGroupMembers",
UpdateSetting: "group/updateGroupSetting",
ToggleEphemeral: "group/toggleEphemeral",
Leave: "group/leaveGroup"
},
Profile: {
FetchBusinessProfile: "chat/fetchBusinessProfile",
FetchProfile: "chat/fetchProfile",
UpdateName: "chat/updateProfileName",
UpdateStatus: "chat/updateProfileStatus",
UpdatePicture: "chat/updateProfilePicture",
RemovePicture: "chat/removeProfilePicture",
FetchPrivacySettings: "chat/fetchPrivacySettings",
UpdatePrivacySettings: "chat/updatePrivacySettings"
},
Webhook: {
Set: "webhook/set",
Find: "webhook/find"
},
Settings: {
Set: "settings/set",
Find: "settings/find"
},
Instance: {
Create: "instance/create",
FetchAll: "instance/fetchInstances",
Connect: "instance/connect",
Restart: "instance/restart",
ConnectionState: "instance/connectionState",
Logout: "instance/logout",
Delete: "instance/delete",
SetPresence: "instance/setPresence"
}
};
// src/schemas/common.ts
var import_libphonenumber_js = require("libphonenumber-js");
var validateJid = (value) => value.endsWith("@s.whatsapp.net");
var validateGroupJid = (value) => value.endsWith("@g.us");
// src/modules/chats/index.ts
var ChatsModule = class {
constructor(api) {
this.api = api;
}
/**
* Checks if phone numbers are registered on WhatsApp
* @param numbers - Array of phone numbers to check
* @param methodOptions - Method-specific options (instance override)
*/
async check(numbers, methodOptions) {
const body = {
numbers: Array.isArray(numbers) ? numbers : [numbers]
};
const response = await this.api.post(Routes.Chats.Check, {
body,
...methodOptions
});
return response;
}
/**
* Gets all chats
* @param methodOptions - Method-specific options (instance override)
*/
async findAll(methodOptions) {
const response = await this.api.get(Routes.Chats.FindAll, methodOptions);
return response;
}
/**
* Updates presence status
* @param params - Presence parameters
* @param methodOptions - Method-specific options (instance override)
*/
async updatePresence(options, methodOptions) {
if (!options.number) {
throw new Error("Number is required");
}
if (!validateJid(options.number) && !validateGroupJid(options.number)) {
options.number = `${options.number}@s.whatsapp.net`;
}
await this.api.post(Routes.Chats.SendPresence, {
body: options,
...methodOptions
});
}
/**
* Marks messages as read
* @param options - Mark as read options
* @param methodOptions - Method-specific options (instance override)
*/
async markAsRead(options, methodOptions) {
const response = await this.api.post(Routes.Chats.MarkAsRead, {
body: options,
...methodOptions
});
return response;
}
/**
* Marks messages as unread
* @param options - Mark as unread options
* @param methodOptions - Method-specific options (instance override)
*/
async markAsUnread(options, methodOptions) {
const response = await this.api.post(Routes.Chats.MarkAsUnread, {
body: options,
...methodOptions
});
return response;
}
/**
* Archives a chat
* @param options - Archive options
* @param methodOptions - Method-specific options (instance override)
*/
async archive(options, methodOptions) {
const response = await this.api.post(Routes.Chats.Archive, {
body: options,
...methodOptions
});
return response;
}
/**
* Deletes a message
* @param options - Delete message options
* @param methodOptions - Method-specific options (instance override)
*/
async deleteMessage(options, methodOptions) {
const response = await this.api.delete(Routes.Chats.DeleteMessage, {
body: options,
...methodOptions
});
return response;
}
/**
* Fetches profile picture
* @param options - Fetch profile picture options
* @param methodOptions - Method-specific options (instance override)
*/
async fetchProfilePicture(options, methodOptions) {
const response = await this.api.post(Routes.Chats.FetchProfilePicture, {
body: options,
...methodOptions
});
return response;
}
/**
* Finds contacts
* @param options - Find contacts options
* @param methodOptions - Method-specific options (instance override)
*/
async findContacts(options, methodOptions) {
const response = await this.api.post(Routes.Chats.FindContacts, {
body: options,
...methodOptions
});
return response;
}
/**
* Finds messages
* @param options - Find messages options
* @param methodOptions - Method-specific options (instance override)
*/
async findMessages(options, methodOptions) {
const response = await this.api.post(Routes.Chats.FindMessages, {
body: options,
...methodOptions
});
return response;
}
/**
* Finds status messages
* @param options - Find status message options
* @param methodOptions - Method-specific options (instance override)
*/
async findStatusMessage(options, methodOptions) {
const response = await this.api.post(Routes.Chats.FindStatusMessage, {
body: options,
...methodOptions
});
return response;
}
/**
* Updates a message
* @param options - Update message options
* @param methodOptions - Method-specific options (instance override)
*/
async updateMessage(options, methodOptions) {
const response = await this.api.put(Routes.Chats.UpdateMessage, {
body: options,
...methodOptions
});
return response;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ChatsModule
});
//# sourceMappingURL=index.js.map