@gymspace/evolution 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1273 -0
- package/dist/index.d.mts +1790 -0
- package/dist/index.d.ts +1790 -0
- package/dist/index.js +1091 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1077 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
- package/src/api/errors.ts +220 -0
- package/src/api/routes.ts +76 -0
- package/src/api/service.ts +141 -0
- package/src/index.ts +89 -0
- package/src/modules/chats/index.ts +253 -0
- package/src/modules/chats/schemas/archive.ts +15 -0
- package/src/modules/chats/schemas/check.ts +20 -0
- package/src/modules/chats/schemas/delete-message.ts +16 -0
- package/src/modules/chats/schemas/fetch-profile-picture.ts +13 -0
- package/src/modules/chats/schemas/find-all.ts +49 -0
- package/src/modules/chats/schemas/find-contacts.ts +17 -0
- package/src/modules/chats/schemas/find-messages.ts +55 -0
- package/src/modules/chats/schemas/find-status-message.ts +11 -0
- package/src/modules/chats/schemas/get-base64-from-media-message.ts +20 -0
- package/src/modules/chats/schemas/index.ts +33 -0
- package/src/modules/chats/schemas/mark-as-read.ts +20 -0
- package/src/modules/chats/schemas/mark-as-unread.ts +17 -0
- package/src/modules/chats/schemas/presence.ts +41 -0
- package/src/modules/chats/schemas/update-message.ts +16 -0
- package/src/modules/groups/index.ts +246 -0
- package/src/modules/groups/schemas/accept-invite-code.ts +14 -0
- package/src/modules/groups/schemas/common.ts +89 -0
- package/src/modules/groups/schemas/create.ts +15 -0
- package/src/modules/groups/schemas/fetch-invite-code.ts +13 -0
- package/src/modules/groups/schemas/find-all.ts +26 -0
- package/src/modules/groups/schemas/find-by-invite-code.ts +39 -0
- package/src/modules/groups/schemas/find-by-jid.ts +14 -0
- package/src/modules/groups/schemas/find-members.ts +16 -0
- package/src/modules/groups/schemas/index.ts +24 -0
- package/src/modules/groups/schemas/leave.ts +14 -0
- package/src/modules/groups/schemas/revoke-invite-code.ts +14 -0
- package/src/modules/groups/schemas/send-group-invite.ts +15 -0
- package/src/modules/groups/schemas/toggle-ephemeral.ts +15 -0
- package/src/modules/groups/schemas/update-description.ts +15 -0
- package/src/modules/groups/schemas/update-members.ts +18 -0
- package/src/modules/groups/schemas/update-picture.ts +15 -0
- package/src/modules/groups/schemas/update-setting.ts +16 -0
- package/src/modules/groups/schemas/update-subject.ts +15 -0
- package/src/modules/index.ts +7 -0
- package/src/modules/instance/index.ts +126 -0
- package/src/modules/instance/schemas/connect.ts +14 -0
- package/src/modules/instance/schemas/connection-state.ts +16 -0
- package/src/modules/instance/schemas/create.ts +99 -0
- package/src/modules/instance/schemas/delete.ts +21 -0
- package/src/modules/instance/schemas/fetch-all.ts +57 -0
- package/src/modules/instance/schemas/index.ts +8 -0
- package/src/modules/instance/schemas/logout.ts +22 -0
- package/src/modules/instance/schemas/restart.ts +13 -0
- package/src/modules/instance/schemas/set-presence.ts +20 -0
- package/src/modules/messages/index.ts +246 -0
- package/src/modules/messages/schemas/audio.ts +12 -0
- package/src/modules/messages/schemas/base.ts +11 -0
- package/src/modules/messages/schemas/contact.ts +70 -0
- package/src/modules/messages/schemas/document.ts +12 -0
- package/src/modules/messages/schemas/image.ts +12 -0
- package/src/modules/messages/schemas/index.ts +31 -0
- package/src/modules/messages/schemas/list.ts +36 -0
- package/src/modules/messages/schemas/location.ts +76 -0
- package/src/modules/messages/schemas/media.ts +51 -0
- package/src/modules/messages/schemas/poll.ts +87 -0
- package/src/modules/messages/schemas/reaction.ts +21 -0
- package/src/modules/messages/schemas/status.ts +18 -0
- package/src/modules/messages/schemas/sticker.ts +77 -0
- package/src/modules/messages/schemas/template.ts +39 -0
- package/src/modules/messages/schemas/text.ts +88 -0
- package/src/modules/messages/schemas/video.ts +12 -0
- package/src/modules/messages/schemas/voice.ts +94 -0
- package/src/modules/profile/index.ts +110 -0
- package/src/modules/profile/schemas/fetch-business-profile.ts +29 -0
- package/src/modules/profile/schemas/fetch-privacy-settings.ts +11 -0
- package/src/modules/profile/schemas/fetch-profile.ts +23 -0
- package/src/modules/profile/schemas/index.ts +8 -0
- package/src/modules/profile/schemas/remove-picture.ts +4 -0
- package/src/modules/profile/schemas/update-name.ts +11 -0
- package/src/modules/profile/schemas/update-picture.ts +11 -0
- package/src/modules/profile/schemas/update-privacy-settings.ts +18 -0
- package/src/modules/profile/schemas/update-status.ts +11 -0
- package/src/modules/settings/index.ts +28 -0
- package/src/modules/settings/schemas/find.ts +11 -0
- package/src/modules/settings/schemas/index.ts +2 -0
- package/src/modules/settings/schemas/set.ts +18 -0
- package/src/modules/webhook/index.ts +28 -0
- package/src/modules/webhook/schemas/find.ts +7 -0
- package/src/modules/webhook/schemas/index.ts +2 -0
- package/src/modules/webhook/schemas/set.ts +16 -0
- package/src/schemas/client.ts +23 -0
- package/src/schemas/common.ts +44 -0
- package/src/types/api.ts +17 -0
- package/src/types/events.ts +53 -0
- package/src/types/messages.ts +5 -0
- package/src/types/tags.ts +14 -0
- package/src/types/webhooks.ts +255 -0
- package/src/utils/phone-numer-from-jid.ts +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1091 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var libphonenumberJs = require('libphonenumber-js');
|
|
4
|
+
|
|
5
|
+
// src/types/webhooks.ts
|
|
6
|
+
var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
|
|
7
|
+
ConnectionState2["OPEN"] = "open";
|
|
8
|
+
ConnectionState2["CONNECTING"] = "connecting";
|
|
9
|
+
ConnectionState2["CLOSED"] = "close";
|
|
10
|
+
ConnectionState2["REFUSED"] = "refused";
|
|
11
|
+
return ConnectionState2;
|
|
12
|
+
})(ConnectionState || {});
|
|
13
|
+
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
14
|
+
MessageType2["CONVERSATION"] = "conversation";
|
|
15
|
+
MessageType2["TEXT"] = "textMessage";
|
|
16
|
+
MessageType2["EPHEMERAL"] = "ephemeralMessage";
|
|
17
|
+
MessageType2["AUDIO"] = "audioMessage";
|
|
18
|
+
MessageType2["IMAGE"] = "imageMessage";
|
|
19
|
+
MessageType2["VIDEO"] = "videoMessage";
|
|
20
|
+
MessageType2["DOCUMENT"] = "documentMessage";
|
|
21
|
+
MessageType2["STICKER"] = "stickerMessage";
|
|
22
|
+
MessageType2["CONTACT"] = "contactMessage";
|
|
23
|
+
MessageType2["LOCATION"] = "locationMessage";
|
|
24
|
+
MessageType2["REACTION"] = "reactionMessage";
|
|
25
|
+
MessageType2["BUTTONS"] = "buttonsMessage";
|
|
26
|
+
return MessageType2;
|
|
27
|
+
})(MessageType || {});
|
|
28
|
+
|
|
29
|
+
// src/api/errors.ts
|
|
30
|
+
var EvolutionApiError = class _EvolutionApiError extends Error {
|
|
31
|
+
constructor(message, cause, statusCode) {
|
|
32
|
+
const extractedMessage = extractErrorMessage(cause);
|
|
33
|
+
const finalMessage = extractedMessage || message || "Unknown error occurred";
|
|
34
|
+
super(finalMessage);
|
|
35
|
+
this.name = _EvolutionApiError.name;
|
|
36
|
+
this.message = finalMessage;
|
|
37
|
+
this.statusCode = statusCode;
|
|
38
|
+
this.details = cause;
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, _EvolutionApiError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns a user-friendly string representation of the error
|
|
45
|
+
*/
|
|
46
|
+
toString() {
|
|
47
|
+
let result = `${this.name}: ${this.message}`;
|
|
48
|
+
if (this.statusCode) {
|
|
49
|
+
result += ` (${this.statusCode})`;
|
|
50
|
+
}
|
|
51
|
+
if (this.details && typeof this.details === "object") {
|
|
52
|
+
const details = this.details;
|
|
53
|
+
const relevantDetails = [];
|
|
54
|
+
if (details.url) {
|
|
55
|
+
relevantDetails.push(`URL: ${details.url}`);
|
|
56
|
+
}
|
|
57
|
+
if (details.method) {
|
|
58
|
+
relevantDetails.push(`Method: ${details.method}`);
|
|
59
|
+
}
|
|
60
|
+
if (details.response && typeof details.response === "object") {
|
|
61
|
+
const response = details.response;
|
|
62
|
+
if (response.error && response.error !== this.message) {
|
|
63
|
+
relevantDetails.push(`Server Error: ${response.error}`);
|
|
64
|
+
}
|
|
65
|
+
if (response.message && response.message !== this.message) {
|
|
66
|
+
relevantDetails.push(`Server Message: ${response.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (relevantDetails.length > 0) {
|
|
70
|
+
result += `
|
|
71
|
+
${relevantDetails.join("\n ")}`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns a JSON representation suitable for logging
|
|
78
|
+
*/
|
|
79
|
+
toJSON() {
|
|
80
|
+
return {
|
|
81
|
+
name: this.name,
|
|
82
|
+
message: this.message,
|
|
83
|
+
statusCode: this.statusCode,
|
|
84
|
+
details: this.details,
|
|
85
|
+
stack: this.stack
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
function extractErrorMessage(response) {
|
|
90
|
+
if (!response) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (typeof response === "string") {
|
|
94
|
+
return response;
|
|
95
|
+
}
|
|
96
|
+
if (typeof response === "object" && response !== null) {
|
|
97
|
+
const errorObj = response;
|
|
98
|
+
const messagePaths = [
|
|
99
|
+
// Evolution API specific nested structure (most common)
|
|
100
|
+
errorObj.response?.response?.message?.[0],
|
|
101
|
+
errorObj.response?.response?.error,
|
|
102
|
+
errorObj.response?.response?.description,
|
|
103
|
+
// Evolution API first level nested
|
|
104
|
+
Array.isArray(errorObj.response?.message) ? errorObj.response.message[0] : null,
|
|
105
|
+
errorObj.response?.error,
|
|
106
|
+
errorObj.response?.description,
|
|
107
|
+
// Direct error message
|
|
108
|
+
Array.isArray(errorObj.message) ? errorObj.message[0] : errorObj.message,
|
|
109
|
+
errorObj.error,
|
|
110
|
+
errorObj.description,
|
|
111
|
+
errorObj.detail,
|
|
112
|
+
// Other nested error messages
|
|
113
|
+
errorObj.data?.error,
|
|
114
|
+
errorObj.data?.message,
|
|
115
|
+
// Array format messages (fallback)
|
|
116
|
+
Array.isArray(errorObj.error) ? errorObj.error[0] : null,
|
|
117
|
+
Array.isArray(errorObj.errors) ? errorObj.errors[0] : null
|
|
118
|
+
];
|
|
119
|
+
for (const path of messagePaths) {
|
|
120
|
+
if (typeof path === "string" && path.trim()) {
|
|
121
|
+
return path.trim();
|
|
122
|
+
}
|
|
123
|
+
if (typeof path === "object" && path !== null) {
|
|
124
|
+
const nestedMessage = extractErrorMessage(path);
|
|
125
|
+
if (nestedMessage) {
|
|
126
|
+
return nestedMessage;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (errorObj.validation && Array.isArray(errorObj.validation)) {
|
|
131
|
+
const validationErrors = errorObj.validation.map((v) => v.message || v.error || String(v)).filter(Boolean).join(", ");
|
|
132
|
+
if (validationErrors) {
|
|
133
|
+
return `Validation error: ${validationErrors}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (errorObj.statusCode && errorObj.statusText) {
|
|
137
|
+
return `${errorObj.statusCode}: ${errorObj.statusText}`;
|
|
138
|
+
}
|
|
139
|
+
if (Object.keys(errorObj).length > 0) {
|
|
140
|
+
try {
|
|
141
|
+
return JSON.stringify(errorObj);
|
|
142
|
+
} catch {
|
|
143
|
+
return "[Complex error object]";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/api/service.ts
|
|
151
|
+
var ApiService = class {
|
|
152
|
+
constructor(options) {
|
|
153
|
+
this.options = options;
|
|
154
|
+
}
|
|
155
|
+
setInstance(instance) {
|
|
156
|
+
this.options.instance = instance;
|
|
157
|
+
}
|
|
158
|
+
async request(path, options = {}) {
|
|
159
|
+
const { isInstanceUrl = true } = options;
|
|
160
|
+
let instance = this.options.instance;
|
|
161
|
+
if (options.instance) {
|
|
162
|
+
instance = options.instance;
|
|
163
|
+
delete options.instance;
|
|
164
|
+
}
|
|
165
|
+
if (isInstanceUrl && !instance) {
|
|
166
|
+
throw new EvolutionApiError("Instance not set", {
|
|
167
|
+
message: "Please set the instance before making a request or pass instance in the method options."
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const { init, params } = this.makeInit(options);
|
|
171
|
+
const urlPath = isInstanceUrl ? `/${path}/${instance}/` : `/${path}/`;
|
|
172
|
+
const url = new URL(urlPath, this.options.serverUrl);
|
|
173
|
+
if (params.toString()) {
|
|
174
|
+
url.search = params.toString();
|
|
175
|
+
}
|
|
176
|
+
let response;
|
|
177
|
+
let data;
|
|
178
|
+
try {
|
|
179
|
+
response = await fetch(url, init);
|
|
180
|
+
data = await response.json();
|
|
181
|
+
} catch (error) {
|
|
182
|
+
throw new EvolutionApiError("Network or parsing error", error);
|
|
183
|
+
}
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
const errorMessage = extractErrorMessage(data) || `Request failed with status ${response.status}: ${response.statusText}`;
|
|
186
|
+
throw new EvolutionApiError(
|
|
187
|
+
errorMessage,
|
|
188
|
+
{
|
|
189
|
+
message: errorMessage,
|
|
190
|
+
response: JSON.stringify(data),
|
|
191
|
+
url: url.toString(),
|
|
192
|
+
params: params.toString(),
|
|
193
|
+
body: JSON.stringify(options.body)
|
|
194
|
+
},
|
|
195
|
+
response.status
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return data;
|
|
199
|
+
}
|
|
200
|
+
makeInit(options) {
|
|
201
|
+
const init = {
|
|
202
|
+
method: options.method || "GET",
|
|
203
|
+
headers: {
|
|
204
|
+
"Content-Type": "application/json",
|
|
205
|
+
apikey: this.options.token,
|
|
206
|
+
// Evolution API uses apikey header
|
|
207
|
+
...this.options.headers,
|
|
208
|
+
...options.headers
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
if (options.body) {
|
|
212
|
+
init.body = JSON.stringify(options.body);
|
|
213
|
+
}
|
|
214
|
+
const params = new URLSearchParams();
|
|
215
|
+
if (options.params) {
|
|
216
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
217
|
+
if (value !== void 0 && value !== null) {
|
|
218
|
+
params.append(key, String(value));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return { init, params };
|
|
223
|
+
}
|
|
224
|
+
async get(path, options = {}) {
|
|
225
|
+
return this.request(path, { ...options, method: "GET" });
|
|
226
|
+
}
|
|
227
|
+
async post(path, options = {}) {
|
|
228
|
+
return this.request(path, { ...options, method: "POST" });
|
|
229
|
+
}
|
|
230
|
+
async put(path, options = {}) {
|
|
231
|
+
return this.request(path, { ...options, method: "PUT" });
|
|
232
|
+
}
|
|
233
|
+
async patch(path, options = {}) {
|
|
234
|
+
return this.request(path, { ...options, method: "PATCH" });
|
|
235
|
+
}
|
|
236
|
+
async delete(path, options = {}) {
|
|
237
|
+
return this.request(path, { ...options, method: "DELETE" });
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/api/routes.ts
|
|
242
|
+
var Routes = {
|
|
243
|
+
Message: {
|
|
244
|
+
SendText: "message/sendText",
|
|
245
|
+
SendMedia: "message/sendMedia",
|
|
246
|
+
SendVoice: "message/sendWhatsAppAudio",
|
|
247
|
+
SendSticker: "message/sendSticker",
|
|
248
|
+
SendLocation: "message/sendLocation",
|
|
249
|
+
SendContact: "message/sendContact",
|
|
250
|
+
SendReaction: "message/sendReaction",
|
|
251
|
+
SendTemplate: "message/sendTemplate",
|
|
252
|
+
SendStatus: "message/sendStatus",
|
|
253
|
+
SendList: "message/sendList"
|
|
254
|
+
},
|
|
255
|
+
Chats: {
|
|
256
|
+
Check: "chat/whatsappNumbers",
|
|
257
|
+
FindAll: "chat/findChats",
|
|
258
|
+
SendPresence: "chat/sendPresence",
|
|
259
|
+
MarkAsRead: "chat/markMessageAsRead",
|
|
260
|
+
MarkAsUnread: "chat/markChatUnread",
|
|
261
|
+
Archive: "chat/archive",
|
|
262
|
+
DeleteMessage: "chat/deleteMessageForEveryone",
|
|
263
|
+
FetchProfilePicture: "chat/fetchProfilePictureUrl",
|
|
264
|
+
FindContacts: "chat/findContacts",
|
|
265
|
+
FindMessages: "chat/findMessages",
|
|
266
|
+
FindStatusMessage: "chat/findStatusMessage",
|
|
267
|
+
UpdateMessage: "chat/updateMessage",
|
|
268
|
+
GetBase64FromMediaMessage: "chat/getBase64FromMediaMessage"
|
|
269
|
+
},
|
|
270
|
+
Groups: {
|
|
271
|
+
FindAll: "group/fetchAllGroups",
|
|
272
|
+
FindByJid: "group/findGroupInfos",
|
|
273
|
+
FindByInviteCode: "group/inviteInfo",
|
|
274
|
+
Create: "group/create",
|
|
275
|
+
UpdatePicture: "group/updateGroupPicture",
|
|
276
|
+
UpdateSubject: "group/updateGroupSubject",
|
|
277
|
+
UpdateDescription: "group/updateGroupDescription",
|
|
278
|
+
FetchInviteCode: "group/fetchInviteCode",
|
|
279
|
+
AcceptInviteCode: "group/acceptInviteCode",
|
|
280
|
+
RevokeInviteCode: "group/revokeInviteCode",
|
|
281
|
+
SendGroupInvite: "group/sendGroupInvite",
|
|
282
|
+
FindMembers: "group/findGroupMembers",
|
|
283
|
+
UpdateMembers: "group/updateGroupMembers",
|
|
284
|
+
UpdateSetting: "group/updateGroupSetting",
|
|
285
|
+
ToggleEphemeral: "group/toggleEphemeral",
|
|
286
|
+
Leave: "group/leaveGroup"
|
|
287
|
+
},
|
|
288
|
+
Profile: {
|
|
289
|
+
FetchBusinessProfile: "chat/fetchBusinessProfile",
|
|
290
|
+
FetchProfile: "chat/fetchProfile",
|
|
291
|
+
UpdateName: "chat/updateProfileName",
|
|
292
|
+
UpdateStatus: "chat/updateProfileStatus",
|
|
293
|
+
UpdatePicture: "chat/updateProfilePicture",
|
|
294
|
+
RemovePicture: "chat/removeProfilePicture",
|
|
295
|
+
FetchPrivacySettings: "chat/fetchPrivacySettings",
|
|
296
|
+
UpdatePrivacySettings: "chat/updatePrivacySettings"
|
|
297
|
+
},
|
|
298
|
+
Webhook: {
|
|
299
|
+
Set: "webhook/set",
|
|
300
|
+
Find: "webhook/find"
|
|
301
|
+
},
|
|
302
|
+
Settings: {
|
|
303
|
+
Set: "settings/set",
|
|
304
|
+
Find: "settings/find"
|
|
305
|
+
},
|
|
306
|
+
Instance: {
|
|
307
|
+
Create: "instance/create",
|
|
308
|
+
FetchAll: "instance/fetchInstances",
|
|
309
|
+
Connect: "instance/connect",
|
|
310
|
+
Restart: "instance/restart",
|
|
311
|
+
ConnectionState: "instance/connectionState",
|
|
312
|
+
Logout: "instance/logout",
|
|
313
|
+
Delete: "instance/delete",
|
|
314
|
+
SetPresence: "instance/setPresence"
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var validatePhoneNumber = (value) => libphonenumberJs.isValidPhoneNumber(value);
|
|
318
|
+
var validateJid = (value) => value.endsWith("@s.whatsapp.net");
|
|
319
|
+
var validateGroupJid = (value) => value.endsWith("@g.us");
|
|
320
|
+
|
|
321
|
+
// src/modules/chats/index.ts
|
|
322
|
+
var ChatsModule = class {
|
|
323
|
+
constructor(api) {
|
|
324
|
+
this.api = api;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Checks if phone numbers are registered on WhatsApp
|
|
328
|
+
* @param numbers - Array of phone numbers to check
|
|
329
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
330
|
+
*/
|
|
331
|
+
async check(numbers, methodOptions) {
|
|
332
|
+
const body = {
|
|
333
|
+
numbers: Array.isArray(numbers) ? numbers : [numbers]
|
|
334
|
+
};
|
|
335
|
+
const response = await this.api.post(Routes.Chats.Check, {
|
|
336
|
+
body,
|
|
337
|
+
...methodOptions
|
|
338
|
+
});
|
|
339
|
+
return response;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Gets all chats
|
|
343
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
344
|
+
*/
|
|
345
|
+
async findAll(methodOptions) {
|
|
346
|
+
const response = await this.api.post(Routes.Chats.FindAll, {
|
|
347
|
+
body: {},
|
|
348
|
+
...methodOptions
|
|
349
|
+
});
|
|
350
|
+
return response;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Updates presence status
|
|
354
|
+
* @param params - Presence parameters
|
|
355
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
356
|
+
*/
|
|
357
|
+
async updatePresence(options, methodOptions) {
|
|
358
|
+
if (!options.number) {
|
|
359
|
+
throw new Error("Number is required");
|
|
360
|
+
}
|
|
361
|
+
if (!validateJid(options.number) && !validateGroupJid(options.number)) {
|
|
362
|
+
options.number = `${options.number}@s.whatsapp.net`;
|
|
363
|
+
}
|
|
364
|
+
await this.api.post(Routes.Chats.SendPresence, {
|
|
365
|
+
body: options,
|
|
366
|
+
...methodOptions
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Marks messages as read
|
|
371
|
+
* @param options - Mark as read options
|
|
372
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
373
|
+
*/
|
|
374
|
+
async markAsRead(options, methodOptions) {
|
|
375
|
+
const response = await this.api.post(Routes.Chats.MarkAsRead, {
|
|
376
|
+
body: options,
|
|
377
|
+
...methodOptions
|
|
378
|
+
});
|
|
379
|
+
return response;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Marks messages as unread
|
|
383
|
+
* @param options - Mark as unread options
|
|
384
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
385
|
+
*/
|
|
386
|
+
async markAsUnread(options, methodOptions) {
|
|
387
|
+
const response = await this.api.post(Routes.Chats.MarkAsUnread, {
|
|
388
|
+
body: options,
|
|
389
|
+
...methodOptions
|
|
390
|
+
});
|
|
391
|
+
return response;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Archives a chat
|
|
395
|
+
* @param options - Archive options
|
|
396
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
397
|
+
*/
|
|
398
|
+
async archive(options, methodOptions) {
|
|
399
|
+
const response = await this.api.post(Routes.Chats.Archive, {
|
|
400
|
+
body: options,
|
|
401
|
+
...methodOptions
|
|
402
|
+
});
|
|
403
|
+
return response;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Deletes a message
|
|
407
|
+
* @param options - Delete message options
|
|
408
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
409
|
+
*/
|
|
410
|
+
async deleteMessage(options, methodOptions) {
|
|
411
|
+
const response = await this.api.delete(Routes.Chats.DeleteMessage, {
|
|
412
|
+
body: options,
|
|
413
|
+
...methodOptions
|
|
414
|
+
});
|
|
415
|
+
return response;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Fetches profile picture
|
|
419
|
+
* @param options - Fetch profile picture options
|
|
420
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
421
|
+
*/
|
|
422
|
+
async fetchProfilePicture(options, methodOptions) {
|
|
423
|
+
const response = await this.api.post(Routes.Chats.FetchProfilePicture, {
|
|
424
|
+
body: options,
|
|
425
|
+
...methodOptions
|
|
426
|
+
});
|
|
427
|
+
return response;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Finds contacts
|
|
431
|
+
* @param options - Find contacts options
|
|
432
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
433
|
+
*/
|
|
434
|
+
async findContacts(options, methodOptions) {
|
|
435
|
+
const response = await this.api.post(Routes.Chats.FindContacts, {
|
|
436
|
+
body: options,
|
|
437
|
+
...methodOptions
|
|
438
|
+
});
|
|
439
|
+
return response;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Finds messages
|
|
443
|
+
* @param options - Find messages options
|
|
444
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
445
|
+
*/
|
|
446
|
+
async findMessages(options, methodOptions) {
|
|
447
|
+
const response = await this.api.post(Routes.Chats.FindMessages, {
|
|
448
|
+
body: options,
|
|
449
|
+
...methodOptions
|
|
450
|
+
});
|
|
451
|
+
return response;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Finds status messages
|
|
455
|
+
* @param options - Find status message options
|
|
456
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
457
|
+
*/
|
|
458
|
+
async findStatusMessage(options, methodOptions) {
|
|
459
|
+
const response = await this.api.post(Routes.Chats.FindStatusMessage, {
|
|
460
|
+
body: options,
|
|
461
|
+
...methodOptions
|
|
462
|
+
});
|
|
463
|
+
return response;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Updates a message
|
|
467
|
+
* @param options - Update message options
|
|
468
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
469
|
+
*/
|
|
470
|
+
async updateMessage(options, methodOptions) {
|
|
471
|
+
const response = await this.api.put(Routes.Chats.UpdateMessage, {
|
|
472
|
+
body: options,
|
|
473
|
+
...methodOptions
|
|
474
|
+
});
|
|
475
|
+
return response;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Gets base64 representation of media from a message
|
|
479
|
+
* @param options - Get base64 from media message options
|
|
480
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
481
|
+
*/
|
|
482
|
+
async getBase64FromMediaMessage(options, methodOptions) {
|
|
483
|
+
const response = await this.api.post(
|
|
484
|
+
Routes.Chats.GetBase64FromMediaMessage,
|
|
485
|
+
{
|
|
486
|
+
body: options,
|
|
487
|
+
...methodOptions
|
|
488
|
+
}
|
|
489
|
+
);
|
|
490
|
+
return response;
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/modules/groups/index.ts
|
|
495
|
+
var GroupsModule = class {
|
|
496
|
+
constructor(api) {
|
|
497
|
+
this.api = api;
|
|
498
|
+
}
|
|
499
|
+
async findAll(getParticipants = false, methodOptions) {
|
|
500
|
+
const response = await this.api.get(Routes.Groups.FindAll, {
|
|
501
|
+
params: { getParticipants },
|
|
502
|
+
...methodOptions
|
|
503
|
+
});
|
|
504
|
+
if (getParticipants) {
|
|
505
|
+
return response;
|
|
506
|
+
}
|
|
507
|
+
return response;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Gets a group by invite code
|
|
511
|
+
* @param inviteCode - The group invite code (not the URL)
|
|
512
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
513
|
+
*/
|
|
514
|
+
async findByInviteCode(inviteCode, methodOptions) {
|
|
515
|
+
const response = await this.api.get(Routes.Groups.FindByInviteCode, {
|
|
516
|
+
params: { inviteCode },
|
|
517
|
+
...methodOptions
|
|
518
|
+
});
|
|
519
|
+
return response;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Gets a group by JID
|
|
523
|
+
* @param groupJid - The group JID terminated with \@g.us
|
|
524
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
525
|
+
*/
|
|
526
|
+
async findByJid(groupJid, methodOptions) {
|
|
527
|
+
const response = await this.api.get(Routes.Groups.FindByJid, {
|
|
528
|
+
params: { groupJid },
|
|
529
|
+
...methodOptions
|
|
530
|
+
});
|
|
531
|
+
return response;
|
|
532
|
+
}
|
|
533
|
+
async create(options, methodOptions) {
|
|
534
|
+
const response = await this.api.post(Routes.Groups.Create, {
|
|
535
|
+
body: options,
|
|
536
|
+
...methodOptions
|
|
537
|
+
});
|
|
538
|
+
return response;
|
|
539
|
+
}
|
|
540
|
+
async updatePicture(options, methodOptions) {
|
|
541
|
+
const response = await this.api.post(Routes.Groups.UpdatePicture, {
|
|
542
|
+
body: options,
|
|
543
|
+
...methodOptions
|
|
544
|
+
});
|
|
545
|
+
return response;
|
|
546
|
+
}
|
|
547
|
+
async updateSubject(options, methodOptions) {
|
|
548
|
+
const response = await this.api.post(Routes.Groups.UpdateSubject, {
|
|
549
|
+
body: options,
|
|
550
|
+
...methodOptions
|
|
551
|
+
});
|
|
552
|
+
return response;
|
|
553
|
+
}
|
|
554
|
+
async updateDescription(options, methodOptions) {
|
|
555
|
+
const response = await this.api.post(Routes.Groups.UpdateDescription, {
|
|
556
|
+
body: options,
|
|
557
|
+
...methodOptions
|
|
558
|
+
});
|
|
559
|
+
return response;
|
|
560
|
+
}
|
|
561
|
+
async fetchInviteCode(options, methodOptions) {
|
|
562
|
+
const response = await this.api.get(Routes.Groups.FetchInviteCode, {
|
|
563
|
+
params: options,
|
|
564
|
+
...methodOptions
|
|
565
|
+
});
|
|
566
|
+
return response;
|
|
567
|
+
}
|
|
568
|
+
async acceptInviteCode(options, methodOptions) {
|
|
569
|
+
const response = await this.api.post(Routes.Groups.AcceptInviteCode, {
|
|
570
|
+
body: options,
|
|
571
|
+
...methodOptions
|
|
572
|
+
});
|
|
573
|
+
return response;
|
|
574
|
+
}
|
|
575
|
+
async revokeInviteCode(options, methodOptions) {
|
|
576
|
+
const response = await this.api.post(Routes.Groups.RevokeInviteCode, {
|
|
577
|
+
body: options,
|
|
578
|
+
...methodOptions
|
|
579
|
+
});
|
|
580
|
+
return response;
|
|
581
|
+
}
|
|
582
|
+
async sendGroupInvite(options, methodOptions) {
|
|
583
|
+
const response = await this.api.post(Routes.Groups.SendGroupInvite, {
|
|
584
|
+
body: options,
|
|
585
|
+
...methodOptions
|
|
586
|
+
});
|
|
587
|
+
return response;
|
|
588
|
+
}
|
|
589
|
+
async findMembers(options, methodOptions) {
|
|
590
|
+
const response = await this.api.get(Routes.Groups.FindMembers, {
|
|
591
|
+
params: options,
|
|
592
|
+
...methodOptions
|
|
593
|
+
});
|
|
594
|
+
return response;
|
|
595
|
+
}
|
|
596
|
+
async updateMembers(options, methodOptions) {
|
|
597
|
+
const response = await this.api.post(Routes.Groups.UpdateMembers, {
|
|
598
|
+
body: options,
|
|
599
|
+
...methodOptions
|
|
600
|
+
});
|
|
601
|
+
return response;
|
|
602
|
+
}
|
|
603
|
+
async updateSetting(options, methodOptions) {
|
|
604
|
+
const response = await this.api.post(Routes.Groups.UpdateSetting, {
|
|
605
|
+
body: options,
|
|
606
|
+
...methodOptions
|
|
607
|
+
});
|
|
608
|
+
return response;
|
|
609
|
+
}
|
|
610
|
+
async toggleEphemeral(options, methodOptions) {
|
|
611
|
+
const response = await this.api.post(Routes.Groups.ToggleEphemeral, {
|
|
612
|
+
body: options,
|
|
613
|
+
...methodOptions
|
|
614
|
+
});
|
|
615
|
+
return response;
|
|
616
|
+
}
|
|
617
|
+
async leave(options, methodOptions) {
|
|
618
|
+
const response = await this.api.post(Routes.Groups.Leave, {
|
|
619
|
+
body: options,
|
|
620
|
+
...methodOptions
|
|
621
|
+
});
|
|
622
|
+
return response;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
// src/modules/instance/index.ts
|
|
627
|
+
var InstanceModule = class {
|
|
628
|
+
constructor(api) {
|
|
629
|
+
this.api = api;
|
|
630
|
+
}
|
|
631
|
+
async create(options) {
|
|
632
|
+
const response = await this.api.post(Routes.Instance.Create, {
|
|
633
|
+
body: options,
|
|
634
|
+
isInstanceUrl: false
|
|
635
|
+
});
|
|
636
|
+
return response;
|
|
637
|
+
}
|
|
638
|
+
async connect(options, methodOptions) {
|
|
639
|
+
const { instanceName } = options;
|
|
640
|
+
const instance = methodOptions?.instance ?? instanceName;
|
|
641
|
+
if (!instance) {
|
|
642
|
+
throw new Error("Instance name is required");
|
|
643
|
+
}
|
|
644
|
+
const response = await this.api.get(Routes.Instance.Connect, {
|
|
645
|
+
instance,
|
|
646
|
+
isInstanceUrl: true
|
|
647
|
+
});
|
|
648
|
+
return response;
|
|
649
|
+
}
|
|
650
|
+
async connectionState(options, methodOptions) {
|
|
651
|
+
const { instanceName } = options;
|
|
652
|
+
const instance = methodOptions?.instance ?? instanceName;
|
|
653
|
+
if (!instance) {
|
|
654
|
+
throw new Error("Instance name is required");
|
|
655
|
+
}
|
|
656
|
+
const response = await this.api.get(Routes.Instance.ConnectionState, {
|
|
657
|
+
instance,
|
|
658
|
+
isInstanceUrl: true
|
|
659
|
+
});
|
|
660
|
+
return response;
|
|
661
|
+
}
|
|
662
|
+
async logout(options, methodOptions) {
|
|
663
|
+
const { instanceName } = options;
|
|
664
|
+
const instance = methodOptions?.instance ?? instanceName;
|
|
665
|
+
if (!instance) {
|
|
666
|
+
throw new Error("Instance name is required");
|
|
667
|
+
}
|
|
668
|
+
const response = await this.api.delete(Routes.Instance.Logout, {
|
|
669
|
+
instance,
|
|
670
|
+
isInstanceUrl: true
|
|
671
|
+
});
|
|
672
|
+
return response;
|
|
673
|
+
}
|
|
674
|
+
async delete(options) {
|
|
675
|
+
const response = await this.api.delete(Routes.Instance.Delete, {
|
|
676
|
+
instance: options.instanceName,
|
|
677
|
+
isInstanceUrl: true
|
|
678
|
+
});
|
|
679
|
+
return response;
|
|
680
|
+
}
|
|
681
|
+
async restart(options, methodOptions) {
|
|
682
|
+
const { instanceName } = options;
|
|
683
|
+
const instance = methodOptions?.instance ?? instanceName;
|
|
684
|
+
if (!instance) {
|
|
685
|
+
throw new Error("Instance name is required");
|
|
686
|
+
}
|
|
687
|
+
const response = await this.api.post(Routes.Instance.Restart, {
|
|
688
|
+
instance,
|
|
689
|
+
isInstanceUrl: true
|
|
690
|
+
});
|
|
691
|
+
return response;
|
|
692
|
+
}
|
|
693
|
+
async fetchAll(options) {
|
|
694
|
+
const response = await this.api.get(Routes.Instance.FetchAll, {
|
|
695
|
+
params: options,
|
|
696
|
+
isInstanceUrl: false
|
|
697
|
+
});
|
|
698
|
+
return response;
|
|
699
|
+
}
|
|
700
|
+
async setPresence(options, methodOptions) {
|
|
701
|
+
const { instanceName, ...rest } = options;
|
|
702
|
+
const instance = methodOptions?.instance ?? instanceName;
|
|
703
|
+
if (!instance) {
|
|
704
|
+
throw new Error("Instance name is required");
|
|
705
|
+
}
|
|
706
|
+
const response = await this.api.post(Routes.Instance.SetPresence, {
|
|
707
|
+
body: rest,
|
|
708
|
+
instance,
|
|
709
|
+
isInstanceUrl: true
|
|
710
|
+
});
|
|
711
|
+
return response;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// src/modules/messages/index.ts
|
|
716
|
+
var MessagesModule = class {
|
|
717
|
+
constructor(api) {
|
|
718
|
+
this.api = api;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Sends a text message
|
|
722
|
+
* @param options - Text message options
|
|
723
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
724
|
+
*/
|
|
725
|
+
async sendText(options, methodOptions) {
|
|
726
|
+
const response = await this.api.post(Routes.Message.SendText, {
|
|
727
|
+
body: options,
|
|
728
|
+
...methodOptions
|
|
729
|
+
});
|
|
730
|
+
return response;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Sends an image
|
|
734
|
+
* @param options - Image message options
|
|
735
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
736
|
+
*/
|
|
737
|
+
async sendImage(options, methodOptions) {
|
|
738
|
+
options.mediatype = "image";
|
|
739
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
740
|
+
body: options,
|
|
741
|
+
...methodOptions
|
|
742
|
+
});
|
|
743
|
+
return response;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Sends a video
|
|
747
|
+
* @param options - Video message options
|
|
748
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
749
|
+
*/
|
|
750
|
+
async sendVideo(options, methodOptions) {
|
|
751
|
+
options.mediatype = "video";
|
|
752
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
753
|
+
body: options,
|
|
754
|
+
...methodOptions
|
|
755
|
+
});
|
|
756
|
+
return response;
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Sends a document
|
|
760
|
+
* @param options - Document message options
|
|
761
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
762
|
+
*/
|
|
763
|
+
async sendDocument(options, methodOptions) {
|
|
764
|
+
options.mediatype = "document";
|
|
765
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
766
|
+
body: options,
|
|
767
|
+
...methodOptions
|
|
768
|
+
});
|
|
769
|
+
return response;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Sends an audio
|
|
773
|
+
* @param options - Audio message options
|
|
774
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
775
|
+
*/
|
|
776
|
+
async sendAudio(options, methodOptions) {
|
|
777
|
+
options.mediatype = "audio";
|
|
778
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
779
|
+
body: options,
|
|
780
|
+
...methodOptions
|
|
781
|
+
});
|
|
782
|
+
return response;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Sends a voice message
|
|
786
|
+
* @param options - Voice message options
|
|
787
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
788
|
+
*/
|
|
789
|
+
async sendVoice(options, methodOptions) {
|
|
790
|
+
const response = await this.api.post(Routes.Message.SendVoice, {
|
|
791
|
+
body: options,
|
|
792
|
+
...methodOptions
|
|
793
|
+
});
|
|
794
|
+
return response;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Sends a sticker
|
|
798
|
+
* @param options - Sticker message options
|
|
799
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
800
|
+
*/
|
|
801
|
+
async sendSticker(options, methodOptions) {
|
|
802
|
+
const response = await this.api.post(Routes.Message.SendSticker, {
|
|
803
|
+
body: options,
|
|
804
|
+
...methodOptions
|
|
805
|
+
});
|
|
806
|
+
return response;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Sends a location
|
|
810
|
+
* @param options - Location message options
|
|
811
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
812
|
+
*/
|
|
813
|
+
async sendLocation(options, methodOptions) {
|
|
814
|
+
const response = await this.api.post(Routes.Message.SendLocation, {
|
|
815
|
+
body: options,
|
|
816
|
+
...methodOptions
|
|
817
|
+
});
|
|
818
|
+
return response;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Sends a contact
|
|
822
|
+
* @param options - Contact message options
|
|
823
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
824
|
+
*/
|
|
825
|
+
async sendContact(options, methodOptions) {
|
|
826
|
+
const response = await this.api.post(Routes.Message.SendContact, {
|
|
827
|
+
body: options,
|
|
828
|
+
...methodOptions
|
|
829
|
+
});
|
|
830
|
+
return response;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Sends a reaction
|
|
834
|
+
* @param options - Reaction message options
|
|
835
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
836
|
+
*/
|
|
837
|
+
async sendReaction(options, methodOptions) {
|
|
838
|
+
const response = await this.api.post(Routes.Message.SendReaction, {
|
|
839
|
+
body: options,
|
|
840
|
+
...methodOptions
|
|
841
|
+
});
|
|
842
|
+
return response;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Sends a template
|
|
846
|
+
* @param options - Template message options
|
|
847
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
848
|
+
*/
|
|
849
|
+
async sendTemplate(options, methodOptions) {
|
|
850
|
+
const response = await this.api.post(Routes.Message.SendTemplate, {
|
|
851
|
+
body: options,
|
|
852
|
+
...methodOptions
|
|
853
|
+
});
|
|
854
|
+
return response;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Sends a status
|
|
858
|
+
* @param options - Status message options
|
|
859
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
860
|
+
*/
|
|
861
|
+
async sendStatus(options, methodOptions) {
|
|
862
|
+
const response = await this.api.post(Routes.Message.SendStatus, {
|
|
863
|
+
body: options,
|
|
864
|
+
...methodOptions
|
|
865
|
+
});
|
|
866
|
+
return response;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Sends a list
|
|
870
|
+
* @param options - List message options
|
|
871
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
872
|
+
*/
|
|
873
|
+
async sendList(options, methodOptions) {
|
|
874
|
+
const response = await this.api.post(Routes.Message.SendList, {
|
|
875
|
+
body: options,
|
|
876
|
+
...methodOptions
|
|
877
|
+
});
|
|
878
|
+
return response;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
// src/modules/profile/index.ts
|
|
883
|
+
var ProfileModule = class {
|
|
884
|
+
constructor(api) {
|
|
885
|
+
this.api = api;
|
|
886
|
+
}
|
|
887
|
+
async fetchBusinessProfile(options, methodOptions) {
|
|
888
|
+
const response = await this.api.post(Routes.Profile.FetchBusinessProfile, {
|
|
889
|
+
body: options,
|
|
890
|
+
...methodOptions
|
|
891
|
+
});
|
|
892
|
+
return response;
|
|
893
|
+
}
|
|
894
|
+
async fetchProfile(options, methodOptions) {
|
|
895
|
+
const response = await this.api.post(Routes.Profile.FetchProfile, {
|
|
896
|
+
body: options,
|
|
897
|
+
...methodOptions
|
|
898
|
+
});
|
|
899
|
+
return response;
|
|
900
|
+
}
|
|
901
|
+
async updateName(options, methodOptions) {
|
|
902
|
+
const response = await this.api.post(Routes.Profile.UpdateName, {
|
|
903
|
+
body: options,
|
|
904
|
+
...methodOptions
|
|
905
|
+
});
|
|
906
|
+
return response;
|
|
907
|
+
}
|
|
908
|
+
async updateStatus(options, methodOptions) {
|
|
909
|
+
const response = await this.api.post(Routes.Profile.UpdateStatus, {
|
|
910
|
+
body: options,
|
|
911
|
+
...methodOptions
|
|
912
|
+
});
|
|
913
|
+
return response;
|
|
914
|
+
}
|
|
915
|
+
async updatePicture(options, methodOptions) {
|
|
916
|
+
const response = await this.api.post(Routes.Profile.UpdatePicture, {
|
|
917
|
+
body: options,
|
|
918
|
+
...methodOptions
|
|
919
|
+
});
|
|
920
|
+
return response;
|
|
921
|
+
}
|
|
922
|
+
async removePicture(methodOptions) {
|
|
923
|
+
const response = await this.api.delete(
|
|
924
|
+
Routes.Profile.RemovePicture,
|
|
925
|
+
methodOptions
|
|
926
|
+
);
|
|
927
|
+
return response;
|
|
928
|
+
}
|
|
929
|
+
async fetchPrivacySettings(methodOptions) {
|
|
930
|
+
const response = await this.api.get(
|
|
931
|
+
Routes.Profile.FetchPrivacySettings,
|
|
932
|
+
methodOptions
|
|
933
|
+
);
|
|
934
|
+
return response;
|
|
935
|
+
}
|
|
936
|
+
async updatePrivacySettings(options, methodOptions) {
|
|
937
|
+
const response = await this.api.put(Routes.Profile.UpdatePrivacySettings, {
|
|
938
|
+
body: options,
|
|
939
|
+
...methodOptions
|
|
940
|
+
});
|
|
941
|
+
return response;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// src/modules/settings/index.ts
|
|
946
|
+
var SettingsModule = class {
|
|
947
|
+
constructor(api) {
|
|
948
|
+
this.api = api;
|
|
949
|
+
}
|
|
950
|
+
async set(options, methodOptions) {
|
|
951
|
+
const response = await this.api.post(Routes.Settings.Set, {
|
|
952
|
+
body: options,
|
|
953
|
+
...methodOptions
|
|
954
|
+
});
|
|
955
|
+
return response;
|
|
956
|
+
}
|
|
957
|
+
async find(methodOptions) {
|
|
958
|
+
const response = await this.api.get(Routes.Settings.Find, methodOptions);
|
|
959
|
+
return response;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
// src/modules/webhook/index.ts
|
|
964
|
+
var WebhookModule = class {
|
|
965
|
+
constructor(api) {
|
|
966
|
+
this.api = api;
|
|
967
|
+
}
|
|
968
|
+
async set(options, methodOptions) {
|
|
969
|
+
const response = await this.api.post(Routes.Webhook.Set, {
|
|
970
|
+
body: options,
|
|
971
|
+
...methodOptions
|
|
972
|
+
});
|
|
973
|
+
return response;
|
|
974
|
+
}
|
|
975
|
+
async find(methodOptions) {
|
|
976
|
+
const response = await this.api.get(Routes.Webhook.Find, methodOptions);
|
|
977
|
+
return response;
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
function phoneNumberFromJid(jid) {
|
|
981
|
+
return libphonenumberJs.parsePhoneNumber(`+${jid.split("@")[0]}`).number;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/types/messages.ts
|
|
985
|
+
var MessageUpdateStatus = /* @__PURE__ */ ((MessageUpdateStatus2) => {
|
|
986
|
+
MessageUpdateStatus2["DELIVERY_ACK"] = "DELIVERY_ACK";
|
|
987
|
+
MessageUpdateStatus2["READ"] = "READ";
|
|
988
|
+
MessageUpdateStatus2["SERVER_ACK"] = "SERVER_ACK";
|
|
989
|
+
return MessageUpdateStatus2;
|
|
990
|
+
})(MessageUpdateStatus || {});
|
|
991
|
+
|
|
992
|
+
// src/types/tags.ts
|
|
993
|
+
var Jid = (jid) => jid;
|
|
994
|
+
var GroupJid = (jid) => jid;
|
|
995
|
+
var MessageId = (id) => id;
|
|
996
|
+
var ChatId = (id) => id;
|
|
997
|
+
|
|
998
|
+
// src/types/events.ts
|
|
999
|
+
var WebhookEvent = /* @__PURE__ */ ((WebhookEvent2) => {
|
|
1000
|
+
WebhookEvent2["APPLICATION_STARTUP"] = "application.startup";
|
|
1001
|
+
WebhookEvent2["QRCODE_UPDATED"] = "qrcode.updated";
|
|
1002
|
+
WebhookEvent2["CONNECTION_UPDATE"] = "connection.update";
|
|
1003
|
+
WebhookEvent2["MESSAGES_SET"] = "messages.set";
|
|
1004
|
+
WebhookEvent2["MESSAGES_UPSERT"] = "messages.upsert";
|
|
1005
|
+
WebhookEvent2["MESSAGES_UPDATE"] = "messages.update";
|
|
1006
|
+
WebhookEvent2["MESSAGES_DELETE"] = "messages.delete";
|
|
1007
|
+
WebhookEvent2["SEND_MESSAGE"] = "send.message";
|
|
1008
|
+
WebhookEvent2["CONTACTS_SET"] = "contacts.set";
|
|
1009
|
+
WebhookEvent2["CONTACTS_UPSERT"] = "contacts.upsert";
|
|
1010
|
+
WebhookEvent2["CONTACTS_UPDATE"] = "contacts.update";
|
|
1011
|
+
WebhookEvent2["PRESENCE_UPDATE"] = "presence.update";
|
|
1012
|
+
WebhookEvent2["CHATS_SET"] = "chats.set";
|
|
1013
|
+
WebhookEvent2["CHATS_UPDATE"] = "chats.update";
|
|
1014
|
+
WebhookEvent2["CHATS_UPSERT"] = "chats.upsert";
|
|
1015
|
+
WebhookEvent2["CHATS_DELETE"] = "chats.delete";
|
|
1016
|
+
WebhookEvent2["GROUPS_UPSERT"] = "groups.upsert";
|
|
1017
|
+
WebhookEvent2["GROUPS_UPDATE"] = "groups.update";
|
|
1018
|
+
WebhookEvent2["GROUP_PARTICIPANTS_UPDATE"] = "group.participants.update";
|
|
1019
|
+
WebhookEvent2["NEW_TOKEN"] = "new.jwt";
|
|
1020
|
+
return WebhookEvent2;
|
|
1021
|
+
})(WebhookEvent || {});
|
|
1022
|
+
var WebhookEventSetup = /* @__PURE__ */ ((WebhookEventSetup2) => {
|
|
1023
|
+
WebhookEventSetup2["APPLICATION_STARTUP"] = "APPLICATION_STARTUP";
|
|
1024
|
+
WebhookEventSetup2["QRCODE_UPDATED"] = "QRCODE_UPDATED";
|
|
1025
|
+
WebhookEventSetup2["CONNECTION_UPDATE"] = "CONNECTION_UPDATE";
|
|
1026
|
+
WebhookEventSetup2["MESSAGES_SET"] = "MESSAGES_SET";
|
|
1027
|
+
WebhookEventSetup2["MESSAGES_UPSERT"] = "MESSAGES_UPSERT";
|
|
1028
|
+
WebhookEventSetup2["MESSAGES_UPDATE"] = "MESSAGES_UPDATE";
|
|
1029
|
+
WebhookEventSetup2["MESSAGES_DELETE"] = "MESSAGES_DELETE";
|
|
1030
|
+
WebhookEventSetup2["SEND_MESSAGE"] = "SEND_MESSAGE";
|
|
1031
|
+
WebhookEventSetup2["CONTACTS_SET"] = "CONTACTS_SET";
|
|
1032
|
+
WebhookEventSetup2["CONTACTS_UPSERT"] = "CONTACTS_UPSERT";
|
|
1033
|
+
WebhookEventSetup2["CONTACTS_UPDATE"] = "CONTACTS_UPDATE";
|
|
1034
|
+
WebhookEventSetup2["PRESENCE_UPDATE"] = "PRESENCE_UPDATE";
|
|
1035
|
+
WebhookEventSetup2["CHATS_SET"] = "CHATS_SET";
|
|
1036
|
+
WebhookEventSetup2["CHATS_UPDATE"] = "CHATS_UPDATE";
|
|
1037
|
+
WebhookEventSetup2["CHATS_UPSERT"] = "CHATS_UPSERT";
|
|
1038
|
+
WebhookEventSetup2["CHATS_DELETE"] = "CHATS_DELETE";
|
|
1039
|
+
WebhookEventSetup2["GROUPS_UPSERT"] = "GROUPS_UPSERT";
|
|
1040
|
+
WebhookEventSetup2["GROUPS_UPDATE"] = "GROUPS_UPDATE";
|
|
1041
|
+
WebhookEventSetup2["GROUP_PARTICIPANTS_UPDATE"] = "GROUP_PARTICIPANTS_UPDATE";
|
|
1042
|
+
WebhookEventSetup2["NEW_TOKEN"] = "NEW_TOKEN";
|
|
1043
|
+
WebhookEventSetup2["MESSAGES_EDITED"] = "MESSAGES_EDITED";
|
|
1044
|
+
WebhookEventSetup2["LABELS_EDIT"] = "LABELS_EDIT";
|
|
1045
|
+
WebhookEventSetup2["LABELS_ASSOCIATION"] = "LABELS_ASSOCIATION";
|
|
1046
|
+
WebhookEventSetup2["CALL"] = "CALL";
|
|
1047
|
+
WebhookEventSetup2["TYPEBOT_START"] = "TYPEBOT_START";
|
|
1048
|
+
WebhookEventSetup2["TYPEBOT_CHANGE_STATUS"] = "TYPEBOT_CHANGE_STATUS";
|
|
1049
|
+
WebhookEventSetup2["ERRORS"] = "ERRORS";
|
|
1050
|
+
WebhookEventSetup2["ERRORS_WEBHOOK"] = "ERRORS_WEBHOOK";
|
|
1051
|
+
return WebhookEventSetup2;
|
|
1052
|
+
})(WebhookEventSetup || {});
|
|
1053
|
+
|
|
1054
|
+
// src/index.ts
|
|
1055
|
+
var EvolutionClient = class {
|
|
1056
|
+
/**
|
|
1057
|
+
* Evolution Client - API client for interacting with the Evolution API
|
|
1058
|
+
* @param options - Client options
|
|
1059
|
+
*/
|
|
1060
|
+
constructor(options) {
|
|
1061
|
+
this.options = options;
|
|
1062
|
+
this.api = new ApiService(options);
|
|
1063
|
+
this.chats = new ChatsModule(this.api);
|
|
1064
|
+
this.groups = new GroupsModule(this.api);
|
|
1065
|
+
this.messages = new MessagesModule(this.api);
|
|
1066
|
+
this.instances = new InstanceModule(this.api);
|
|
1067
|
+
this.profile = new ProfileModule(this.api);
|
|
1068
|
+
this.webhook = new WebhookModule(this.api);
|
|
1069
|
+
this.settings = new SettingsModule(this.api);
|
|
1070
|
+
}
|
|
1071
|
+
setInstance(instance) {
|
|
1072
|
+
this.options.instance = instance;
|
|
1073
|
+
this.api.setInstance(instance);
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
exports.ChatId = ChatId;
|
|
1078
|
+
exports.ConnectionState = ConnectionState;
|
|
1079
|
+
exports.EvolutionApiError = EvolutionApiError;
|
|
1080
|
+
exports.EvolutionClient = EvolutionClient;
|
|
1081
|
+
exports.GroupJid = GroupJid;
|
|
1082
|
+
exports.Jid = Jid;
|
|
1083
|
+
exports.MessageId = MessageId;
|
|
1084
|
+
exports.MessageType = MessageType;
|
|
1085
|
+
exports.MessageUpdateStatus = MessageUpdateStatus;
|
|
1086
|
+
exports.WebhookEvent = WebhookEvent;
|
|
1087
|
+
exports.WebhookEventSetup = WebhookEventSetup;
|
|
1088
|
+
exports.phoneNumberFromJid = phoneNumberFromJid;
|
|
1089
|
+
exports.validatePhoneNumber = validatePhoneNumber;
|
|
1090
|
+
//# sourceMappingURL=index.js.map
|
|
1091
|
+
//# sourceMappingURL=index.js.map
|