evolution-api-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
1,100 lines (1,084 loc) • 33.5 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
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);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/index.ts
var index_exports = {};
__export(index_exports, {
ChatId: () => ChatId,
EvolutionApiError: () => EvolutionApiError,
EvolutionClient: () => EvolutionClient,
GroupJid: () => GroupJid,
Jid: () => Jid,
MessageId: () => MessageId,
WebhookEvent: () => WebhookEvent,
WebhookEventSetup: () => WebhookEventSetup,
phoneNumberFromJid: () => phoneNumberFromJid
});
module.exports = __toCommonJS(index_exports);
// src/types/webhooks.ts
var WebhookEvent = /* @__PURE__ */ ((WebhookEvent2) => {
WebhookEvent2["APPLICATION_STARTUP"] = "application.startup";
WebhookEvent2["QRCODE_UPDATED"] = "qrcode.updated";
WebhookEvent2["CONNECTION_UPDATE"] = "connection.update";
WebhookEvent2["MESSAGES_SET"] = "messages.set";
WebhookEvent2["MESSAGES_UPSERT"] = "messages.upsert";
WebhookEvent2["MESSAGES_UPDATE"] = "messages.update";
WebhookEvent2["MESSAGES_DELETE"] = "messages.delete";
WebhookEvent2["SEND_MESSAGE"] = "send.message";
WebhookEvent2["CONTACTS_SET"] = "contacts.set";
WebhookEvent2["CONTACTS_UPSERT"] = "contacts.upsert";
WebhookEvent2["CONTACTS_UPDATE"] = "contacts.update";
WebhookEvent2["PRESENCE_UPDATE"] = "presence.update";
WebhookEvent2["CHATS_SET"] = "chats.set";
WebhookEvent2["CHATS_UPDATE"] = "chats.update";
WebhookEvent2["CHATS_UPSERT"] = "chats.upsert";
WebhookEvent2["CHATS_DELETE"] = "chats.delete";
WebhookEvent2["GROUPS_UPSERT"] = "groups.upsert";
WebhookEvent2["GROUPS_UPDATE"] = "groups.update";
WebhookEvent2["GROUP_PARTICIPANTS_UPDATE"] = "group.participants.update";
WebhookEvent2["NEW_TOKEN"] = "new.jwt";
return WebhookEvent2;
})(WebhookEvent || {});
var WebhookEventSetup = /* @__PURE__ */ ((WebhookEventSetup2) => {
WebhookEventSetup2["APPLICATION_STARTUP"] = "APPLICATION_STARTUP";
WebhookEventSetup2["QRCODE_UPDATED"] = "QRCODE_UPDATED";
WebhookEventSetup2["CONNECTION_UPDATE"] = "CONNECTION_UPDATE";
WebhookEventSetup2["MESSAGES_SET"] = "MESSAGES_SET";
WebhookEventSetup2["MESSAGES_UPSERT"] = "MESSAGES_UPSERT";
WebhookEventSetup2["MESSAGES_UPDATE"] = "MESSAGES_UPDATE";
WebhookEventSetup2["MESSAGES_DELETE"] = "MESSAGES_DELETE";
WebhookEventSetup2["SEND_MESSAGE"] = "SEND_MESSAGE";
WebhookEventSetup2["CONTACTS_SET"] = "CONTACTS_SET";
WebhookEventSetup2["CONTACTS_UPSERT"] = "CONTACTS_UPSERT";
WebhookEventSetup2["CONTACTS_UPDATE"] = "CONTACTS_UPDATE";
WebhookEventSetup2["PRESENCE_UPDATE"] = "PRESENCE_UPDATE";
WebhookEventSetup2["CHATS_SET"] = "CHATS_SET";
WebhookEventSetup2["CHATS_UPDATE"] = "CHATS_UPDATE";
WebhookEventSetup2["CHATS_UPSERT"] = "CHATS_UPSERT";
WebhookEventSetup2["CHATS_DELETE"] = "CHATS_DELETE";
WebhookEventSetup2["GROUPS_UPSERT"] = "GROUPS_UPSERT";
WebhookEventSetup2["GROUPS_UPDATE"] = "GROUPS_UPDATE";
WebhookEventSetup2["GROUP_PARTICIPANTS_UPDATE"] = "GROUP_PARTICIPANTS_UPDATE";
WebhookEventSetup2["NEW_TOKEN"] = "NEW_TOKEN";
return WebhookEventSetup2;
})(WebhookEventSetup || {});
// src/api/errors.ts
var EvolutionApiError = class _EvolutionApiError extends Error {
constructor(message, cause, statusCode) {
const extractedMessage = extractErrorMessage(cause);
const finalMessage = extractedMessage || message || "Unknown error occurred";
super(finalMessage);
__publicField(this, "statusCode");
__publicField(this, "details");
this.name = _EvolutionApiError.name;
this.message = finalMessage;
this.statusCode = statusCode;
this.details = cause;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, _EvolutionApiError);
}
}
/**
* Returns a user-friendly string representation of the error
*/
toString() {
let result = `${this.name}: ${this.message}`;
if (this.statusCode) {
result += ` (${this.statusCode})`;
}
if (this.details && typeof this.details === "object") {
const details = this.details;
const relevantDetails = [];
if (details.url) {
relevantDetails.push(`URL: ${details.url}`);
}
if (details.method) {
relevantDetails.push(`Method: ${details.method}`);
}
if (details.response && typeof details.response === "object") {
const response = details.response;
if (response.error && response.error !== this.message) {
relevantDetails.push(`Server Error: ${response.error}`);
}
if (response.message && response.message !== this.message) {
relevantDetails.push(`Server Message: ${response.message}`);
}
}
if (relevantDetails.length > 0) {
result += `
${relevantDetails.join("\n ")}`;
}
}
return result;
}
/**
* Returns a JSON representation suitable for logging
*/
toJSON() {
return {
name: this.name,
message: this.message,
statusCode: this.statusCode,
details: this.details,
stack: this.stack
};
}
};
function extractErrorMessage(response) {
if (!response) {
return null;
}
if (typeof response === "string") {
return response;
}
if (typeof response === "object" && response !== null) {
const errorObj = response;
const messagePaths = [
// Evolution API specific nested structure (most common)
errorObj.response?.response?.message?.[0],
errorObj.response?.response?.error,
errorObj.response?.response?.description,
// Evolution API first level nested
Array.isArray(errorObj.response?.message) ? errorObj.response.message[0] : null,
errorObj.response?.error,
errorObj.response?.description,
// Direct error message
Array.isArray(errorObj.message) ? errorObj.message[0] : errorObj.message,
errorObj.error,
errorObj.description,
errorObj.detail,
// Other nested error messages
errorObj.data?.error,
errorObj.data?.message,
// Array format messages (fallback)
Array.isArray(errorObj.error) ? errorObj.error[0] : null,
Array.isArray(errorObj.errors) ? errorObj.errors[0] : null
];
for (const path of messagePaths) {
if (typeof path === "string" && path.trim()) {
return path.trim();
}
if (typeof path === "object" && path !== null) {
const nestedMessage = extractErrorMessage(path);
if (nestedMessage) {
return nestedMessage;
}
}
}
if (errorObj.validation && Array.isArray(errorObj.validation)) {
const validationErrors = errorObj.validation.map((v) => v.message || v.error || String(v)).filter(Boolean).join(", ");
if (validationErrors) {
return `Validation error: ${validationErrors}`;
}
}
if (errorObj.statusCode && errorObj.statusText) {
return `${errorObj.statusCode}: ${errorObj.statusText}`;
}
if (Object.keys(errorObj).length > 0) {
try {
return JSON.stringify(errorObj);
} catch {
return "[Complex error object]";
}
}
}
return null;
}
// src/api/service.ts
var ApiService = class {
constructor(options) {
this.options = options;
}
setInstance(instance) {
this.options.instance = instance;
}
async request(path, options = {}) {
const { isInstanceUrl = true } = options;
let instance = this.options.instance;
if (options.instance) {
instance = options.instance;
delete options.instance;
}
if (isInstanceUrl && !instance) {
throw new EvolutionApiError("Instance not set", {
message: "Please set the instance before making a request or pass instance in the method options."
});
}
const { init, params } = this.makeInit(options);
const urlPath = isInstanceUrl ? `/${path}/${instance}/` : `/${path}/`;
const url = new URL(urlPath, this.options.serverUrl);
if (params.toString()) {
url.search = params.toString();
}
let response;
let data;
try {
response = await fetch(url, init);
data = await response.json();
} catch (error) {
throw new EvolutionApiError("Network or parsing error", error);
}
if (!response.ok) {
const errorMessage = extractErrorMessage(data) || `Request failed with status ${response.status}: ${response.statusText}`;
throw new EvolutionApiError(
errorMessage,
{
message: errorMessage,
response: JSON.stringify(data),
url: url.toString(),
params: params.toString(),
body: JSON.stringify(options.body)
},
response.status
);
}
return data;
}
makeInit(options) {
const init = {
method: options.method || "GET",
headers: {
"Content-Type": "application/json",
apikey: this.options.token,
// Evolution API uses apikey header
...this.options.headers,
...options.headers
}
};
if (options.body) {
init.body = JSON.stringify(options.body);
}
const params = new URLSearchParams();
if (options.params) {
Object.entries(options.params).forEach(([key, value]) => {
if (value !== void 0 && value !== null) {
params.append(key, String(value));
}
});
}
return { init, params };
}
async get(path, options = {}) {
return this.request(path, { ...options, method: "GET" });
}
async post(path, options = {}) {
return this.request(path, { ...options, method: "POST" });
}
async put(path, options = {}) {
return this.request(path, { ...options, method: "PUT" });
}
async patch(path, options = {}) {
return this.request(path, { ...options, method: "PATCH" });
}
async delete(path, options = {}) {
return this.request(path, { ...options, method: "DELETE" });
}
};
// 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}.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;
}
};
// src/modules/groups/index.ts
var GroupsModule = class {
constructor(api) {
this.api = api;
}
async findAll(getParticipants = false, methodOptions) {
const response = await this.api.get(Routes.Groups.FindAll, {
params: { getParticipants },
...methodOptions
});
if (getParticipants) {
return response;
}
return response;
}
/**
* Gets a group by invite code
* @param inviteCode - The group invite code (not the URL)
* @param methodOptions - Method-specific options (instance override)
*/
async findByInviteCode(inviteCode, methodOptions) {
const response = await this.api.get(Routes.Groups.FindByInviteCode, {
params: { inviteCode },
...methodOptions
});
return response;
}
/**
* Gets a group by JID
* @param groupJid - The group JID terminated with \@g.us
* @param methodOptions - Method-specific options (instance override)
*/
async findByJid(groupJid, methodOptions) {
const response = await this.api.get(Routes.Groups.FindByJid, {
params: { groupJid },
...methodOptions
});
return response;
}
async create(options, methodOptions) {
const response = await this.api.post(Routes.Groups.Create, {
body: options,
...methodOptions
});
return response;
}
async updatePicture(options, methodOptions) {
const response = await this.api.post(Routes.Groups.UpdatePicture, {
body: options,
...methodOptions
});
return response;
}
async updateSubject(options, methodOptions) {
const response = await this.api.post(Routes.Groups.UpdateSubject, {
body: options,
...methodOptions
});
return response;
}
async updateDescription(options, methodOptions) {
const response = await this.api.post(Routes.Groups.UpdateDescription, {
body: options,
...methodOptions
});
return response;
}
async fetchInviteCode(options, methodOptions) {
const response = await this.api.get(Routes.Groups.FetchInviteCode, {
params: options,
...methodOptions
});
return response;
}
async acceptInviteCode(options, methodOptions) {
const response = await this.api.post(Routes.Groups.AcceptInviteCode, {
body: options,
...methodOptions
});
return response;
}
async revokeInviteCode(options, methodOptions) {
const response = await this.api.post(Routes.Groups.RevokeInviteCode, {
body: options,
...methodOptions
});
return response;
}
async sendGroupInvite(options, methodOptions) {
const response = await this.api.post(Routes.Groups.SendGroupInvite, {
body: options,
...methodOptions
});
return response;
}
async findMembers(options, methodOptions) {
const response = await this.api.get(Routes.Groups.FindMembers, {
params: options,
...methodOptions
});
return response;
}
async updateMembers(options, methodOptions) {
const response = await this.api.post(Routes.Groups.UpdateMembers, {
body: options,
...methodOptions
});
return response;
}
async updateSetting(options, methodOptions) {
const response = await this.api.post(Routes.Groups.UpdateSetting, {
body: options,
...methodOptions
});
return response;
}
async toggleEphemeral(options, methodOptions) {
const response = await this.api.post(Routes.Groups.ToggleEphemeral, {
body: options,
...methodOptions
});
return response;
}
async leave(options, methodOptions) {
const response = await this.api.post(Routes.Groups.Leave, {
body: options,
...methodOptions
});
return response;
}
};
// src/modules/instance/index.ts
var InstanceModule = class {
constructor(api) {
this.api = api;
}
async create(options) {
const response = await this.api.post(Routes.Instance.Create, {
body: options,
isInstanceUrl: false
});
return response;
}
async connect(options, methodOptions) {
const { instanceName } = options;
const instance = methodOptions?.instance ?? instanceName;
if (!instance) {
throw new Error("Instance name is required");
}
const response = await this.api.get(Routes.Instance.Connect, {
instance,
isInstanceUrl: true
});
return response;
}
async connectionState(options, methodOptions) {
const { instanceName } = options;
const instance = methodOptions?.instance ?? instanceName;
if (!instance) {
throw new Error("Instance name is required");
}
const response = await this.api.get(Routes.Instance.ConnectionState, {
instance,
isInstanceUrl: true
});
return response;
}
async logout(options, methodOptions) {
const { instanceName } = options;
const instance = methodOptions?.instance ?? instanceName;
if (!instance) {
throw new Error("Instance name is required");
}
const response = await this.api.delete(Routes.Instance.Logout, {
instance,
isInstanceUrl: true
});
return response;
}
async delete(options) {
const response = await this.api.delete(Routes.Instance.Delete, {
instance: options.instanceName,
isInstanceUrl: true
});
return response;
}
async restart(options, methodOptions) {
const { instanceName } = options;
const instance = methodOptions?.instance ?? instanceName;
if (!instance) {
throw new Error("Instance name is required");
}
const response = await this.api.post(Routes.Instance.Restart, {
instance,
isInstanceUrl: true
});
return response;
}
async fetchAll(options) {
const response = await this.api.get(Routes.Instance.FetchAll, {
params: options,
isInstanceUrl: false
});
return response;
}
async setPresence(options, methodOptions) {
const { instanceName, ...rest } = options;
const instance = methodOptions?.instance ?? instanceName;
if (!instance) {
throw new Error("Instance name is required");
}
const response = await this.api.post(Routes.Instance.SetPresence, {
body: rest,
instance,
isInstanceUrl: true
});
return response;
}
};
// src/modules/messages/index.ts
var MessagesModule = class {
constructor(api) {
this.api = api;
}
/**
* Sends a text message
* @param options - Text message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendText(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendText, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends an image
* @param options - Image message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendImage(options, methodOptions) {
options.mediatype = "image";
const response = await this.api.post(Routes.Message.SendMedia, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a video
* @param options - Video message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendVideo(options, methodOptions) {
options.mediatype = "video";
const response = await this.api.post(Routes.Message.SendMedia, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a document
* @param options - Document message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendDocument(options, methodOptions) {
options.mediatype = "document";
const response = await this.api.post(Routes.Message.SendMedia, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends an audio
* @param options - Audio message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendAudio(options, methodOptions) {
options.mediatype = "audio";
const response = await this.api.post(Routes.Message.SendMedia, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a voice message
* @param options - Voice message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendVoice(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendVoice, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a sticker
* @param options - Sticker message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendSticker(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendSticker, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a location
* @param options - Location message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendLocation(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendLocation, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a contact
* @param options - Contact message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendContact(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendContact, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a reaction
* @param options - Reaction message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendReaction(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendReaction, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a template
* @param options - Template message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendTemplate(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendTemplate, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a status
* @param options - Status message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendStatus(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendStatus, {
body: options,
...methodOptions
});
return response;
}
/**
* Sends a list
* @param options - List message options
* @param methodOptions - Method-specific options (instance override)
*/
async sendList(options, methodOptions) {
const response = await this.api.post(Routes.Message.SendList, {
body: options,
...methodOptions
});
return response;
}
};
// src/modules/profile/index.ts
var ProfileModule = class {
constructor(api) {
this.api = api;
}
async fetchBusinessProfile(options, methodOptions) {
const response = await this.api.post(Routes.Profile.FetchBusinessProfile, {
body: options,
...methodOptions
});
return response;
}
async fetchProfile(options, methodOptions) {
const response = await this.api.post(Routes.Profile.FetchProfile, {
body: options,
...methodOptions
});
return response;
}
async updateName(options, methodOptions) {
const response = await this.api.post(Routes.Profile.UpdateName, {
body: options,
...methodOptions
});
return response;
}
async updateStatus(options, methodOptions) {
const response = await this.api.post(Routes.Profile.UpdateStatus, {
body: options,
...methodOptions
});
return response;
}
async updatePicture(options, methodOptions) {
const response = await this.api.post(Routes.Profile.UpdatePicture, {
body: options,
...methodOptions
});
return response;
}
async removePicture(methodOptions) {
const response = await this.api.delete(
Routes.Profile.RemovePicture,
methodOptions
);
return response;
}
async fetchPrivacySettings(methodOptions) {
const response = await this.api.get(
Routes.Profile.FetchPrivacySettings,
methodOptions
);
return response;
}
async updatePrivacySettings(options, methodOptions) {
const response = await this.api.put(Routes.Profile.UpdatePrivacySettings, {
body: options,
...methodOptions
});
return response;
}
};
// src/modules/settings/index.ts
var SettingsModule = class {
constructor(api) {
this.api = api;
}
async set(options, methodOptions) {
const response = await this.api.post(Routes.Settings.Set, {
body: options,
...methodOptions
});
return response;
}
async find(methodOptions) {
const response = await this.api.get(Routes.Settings.Find, methodOptions);
return response;
}
};
// src/modules/webhook/index.ts
var WebhookModule = class {
constructor(api) {
this.api = api;
}
async set(options, methodOptions) {
const response = await this.api.post(Routes.Webhook.Set, {
body: options,
...methodOptions
});
return response;
}
async find(methodOptions) {
const response = await this.api.get(Routes.Webhook.Find, methodOptions);
return response;
}
};
// src/types/tags.ts
var Jid = (jid) => jid;
var GroupJid = (jid) => jid;
var MessageId = (id) => id;
var ChatId = (id) => id;
// src/utils/phone-numer-from-jid.ts
var import_libphonenumber_js2 = require("libphonenumber-js");
function phoneNumberFromJid(jid) {
return (0, import_libphonenumber_js2.parsePhoneNumber)(`+${jid.split("@")[0]}`).number;
}
// src/index.ts
var EvolutionClient = class {
/**
* Evolution Client - API client for interacting with the Evolution API
* @param options - Client options
*/
constructor(options) {
this.options = options;
/**
* API service for directly interacting with the Evolution API (no specific typings)
*/
__publicField(this, "api");
/**
* Find and manage chats, send presences and check numbers
*/
__publicField(this, "chats");
/**
* Find and manage groups
*/
__publicField(this, "groups");
/**
* Send messages
*/
__publicField(this, "messages");
/**
* Create and manage instances
*/
__publicField(this, "instances");
/**
* Manage profile settings
*/
__publicField(this, "profile");
/**
* Manage webhooks
*/
__publicField(this, "webhook");
/**
* Manage settings
*/
__publicField(this, "settings");
this.api = new ApiService(options);
this.chats = new ChatsModule(this.api);
this.groups = new GroupsModule(this.api);
this.messages = new MessagesModule(this.api);
this.instances = new InstanceModule(this.api);
this.profile = new ProfileModule(this.api);
this.webhook = new WebhookModule(this.api);
this.settings = new SettingsModule(this.api);
}
setInstance(instance) {
this.options.instance = instance;
this.api.setInstance(instance);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ChatId,
EvolutionApiError,
EvolutionClient,
GroupJid,
Jid,
MessageId,
WebhookEvent,
WebhookEventSetup,
phoneNumberFromJid
});
//# sourceMappingURL=index.js.map