@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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { ClientOptions } from "@/schemas/client";
|
|
2
|
+
import type { APIRequestInit } from "@/types/api";
|
|
3
|
+
|
|
4
|
+
import { EvolutionApiError, extractErrorMessage } from "./errors";
|
|
5
|
+
|
|
6
|
+
export class ApiService {
|
|
7
|
+
constructor(private options: ClientOptions) {}
|
|
8
|
+
|
|
9
|
+
setInstance(instance: string) {
|
|
10
|
+
this.options.instance = instance;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async request<T = unknown>(
|
|
14
|
+
path: string,
|
|
15
|
+
options: APIRequestInit = {}
|
|
16
|
+
): Promise<T> {
|
|
17
|
+
const { isInstanceUrl = true } = options;
|
|
18
|
+
let instance = this.options.instance;
|
|
19
|
+
|
|
20
|
+
// Priority: options.instance > this.options.instance
|
|
21
|
+
if (options.instance) {
|
|
22
|
+
instance = options.instance;
|
|
23
|
+
delete options.instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isInstanceUrl && !instance) {
|
|
27
|
+
throw new EvolutionApiError("Instance not set", {
|
|
28
|
+
message:
|
|
29
|
+
"Please set the instance before making a request or pass instance in the method options.",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { init, params } = this.makeInit(options);
|
|
34
|
+
|
|
35
|
+
const urlPath = isInstanceUrl ? `/${path}/${instance}/` : `/${path}/`;
|
|
36
|
+
const url = new URL(urlPath, this.options.serverUrl);
|
|
37
|
+
|
|
38
|
+
// Add query parameters if any
|
|
39
|
+
if (params.toString()) {
|
|
40
|
+
url.search = params.toString();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let response: Response;
|
|
44
|
+
let data: any;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
response = await fetch(url, init);
|
|
48
|
+
data = await response.json();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// Handle network errors or JSON parsing errors
|
|
51
|
+
throw new EvolutionApiError("Network or parsing error", error);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
// Extract meaningful error message from the response
|
|
56
|
+
const errorMessage =
|
|
57
|
+
extractErrorMessage(data) ||
|
|
58
|
+
`Request failed with status ${response.status}: ${response.statusText}`;
|
|
59
|
+
|
|
60
|
+
throw new EvolutionApiError(
|
|
61
|
+
errorMessage,
|
|
62
|
+
{
|
|
63
|
+
message: errorMessage,
|
|
64
|
+
response: JSON.stringify(data),
|
|
65
|
+
url: url.toString(),
|
|
66
|
+
params: params.toString(),
|
|
67
|
+
body: JSON.stringify(options.body),
|
|
68
|
+
} as unknown as Record<string, any>,
|
|
69
|
+
response.status
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private makeInit(options: APIRequestInit): {
|
|
77
|
+
init: RequestInit;
|
|
78
|
+
params: URLSearchParams;
|
|
79
|
+
} {
|
|
80
|
+
const init: RequestInit = {
|
|
81
|
+
method: options.method || "GET",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
apikey: this.options.token, // Evolution API uses apikey header
|
|
85
|
+
...this.options.headers,
|
|
86
|
+
...options.headers,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (options.body) {
|
|
91
|
+
init.body = JSON.stringify(options.body);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const params = new URLSearchParams();
|
|
95
|
+
if (options.params) {
|
|
96
|
+
// Convert any object to URLSearchParams
|
|
97
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
98
|
+
if (value !== undefined && value !== null) {
|
|
99
|
+
params.append(key, String(value));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { init, params };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async get<T = unknown>(
|
|
108
|
+
path: string,
|
|
109
|
+
options: Omit<APIRequestInit, "method"> = {}
|
|
110
|
+
): Promise<T> {
|
|
111
|
+
return this.request<T>(path, { ...options, method: "GET" });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async post<T = unknown>(
|
|
115
|
+
path: string,
|
|
116
|
+
options: Omit<APIRequestInit, "method"> = {}
|
|
117
|
+
): Promise<T> {
|
|
118
|
+
return this.request<T>(path, { ...options, method: "POST" });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async put<T = unknown>(
|
|
122
|
+
path: string,
|
|
123
|
+
options: Omit<APIRequestInit, "method"> = {}
|
|
124
|
+
): Promise<T> {
|
|
125
|
+
return this.request<T>(path, { ...options, method: "PUT" });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async patch<T = unknown>(
|
|
129
|
+
path: string,
|
|
130
|
+
options: Omit<APIRequestInit, "method"> = {}
|
|
131
|
+
): Promise<T> {
|
|
132
|
+
return this.request<T>(path, { ...options, method: "PATCH" });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async delete<T = unknown>(
|
|
136
|
+
path: string,
|
|
137
|
+
options: Omit<APIRequestInit, "method"> = {}
|
|
138
|
+
): Promise<T> {
|
|
139
|
+
return this.request<T>(path, { ...options, method: "DELETE" });
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export * from "./types/webhooks";
|
|
2
|
+
|
|
3
|
+
import { ApiService } from "./api/service";
|
|
4
|
+
import {
|
|
5
|
+
ChatsModule,
|
|
6
|
+
GroupsModule,
|
|
7
|
+
InstanceModule,
|
|
8
|
+
MessagesModule,
|
|
9
|
+
ProfileModule,
|
|
10
|
+
SettingsModule,
|
|
11
|
+
WebhookModule,
|
|
12
|
+
} from "./modules";
|
|
13
|
+
import { type ClientOptions } from "./schemas/client";
|
|
14
|
+
|
|
15
|
+
export class EvolutionClient {
|
|
16
|
+
/**
|
|
17
|
+
* API service for directly interacting with the Evolution API (no specific typings)
|
|
18
|
+
*/
|
|
19
|
+
public readonly api: ApiService;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Find and manage chats, send presences and check numbers
|
|
23
|
+
*/
|
|
24
|
+
public readonly chats: ChatsModule;
|
|
25
|
+
/**
|
|
26
|
+
* Find and manage groups
|
|
27
|
+
*/
|
|
28
|
+
public readonly groups: GroupsModule;
|
|
29
|
+
/**
|
|
30
|
+
* Send messages
|
|
31
|
+
*/
|
|
32
|
+
public readonly messages: MessagesModule;
|
|
33
|
+
/**
|
|
34
|
+
* Create and manage instances
|
|
35
|
+
*/
|
|
36
|
+
public readonly instances: InstanceModule;
|
|
37
|
+
/**
|
|
38
|
+
* Manage profile settings
|
|
39
|
+
*/
|
|
40
|
+
public readonly profile: ProfileModule;
|
|
41
|
+
/**
|
|
42
|
+
* Manage webhooks
|
|
43
|
+
*/
|
|
44
|
+
public readonly webhook: WebhookModule;
|
|
45
|
+
/**
|
|
46
|
+
* Manage settings
|
|
47
|
+
*/
|
|
48
|
+
public readonly settings: SettingsModule;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Evolution Client - API client for interacting with the Evolution API
|
|
52
|
+
* @param options - Client options
|
|
53
|
+
*/
|
|
54
|
+
constructor(public options: ClientOptions) {
|
|
55
|
+
this.api = new ApiService(options);
|
|
56
|
+
this.chats = new ChatsModule(this.api);
|
|
57
|
+
this.groups = new GroupsModule(this.api);
|
|
58
|
+
this.messages = new MessagesModule(this.api);
|
|
59
|
+
this.instances = new InstanceModule(this.api);
|
|
60
|
+
this.profile = new ProfileModule(this.api);
|
|
61
|
+
this.webhook = new WebhookModule(this.api);
|
|
62
|
+
this.settings = new SettingsModule(this.api);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setInstance(instance: string) {
|
|
66
|
+
this.options.instance = instance;
|
|
67
|
+
this.api.setInstance(instance);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { EvolutionApiError } from "./api/errors";
|
|
72
|
+
export { phoneNumberFromJid } from "./utils/phone-numer-from-jid";
|
|
73
|
+
export { validatePhoneNumber } from "./schemas/common";
|
|
74
|
+
|
|
75
|
+
export type * from "./modules/chats/schemas";
|
|
76
|
+
export type * from "./modules/groups/schemas";
|
|
77
|
+
export type * from "./modules/messages/schemas";
|
|
78
|
+
export type * from "./modules/instance/schemas";
|
|
79
|
+
export type * from "./modules/profile/schemas";
|
|
80
|
+
export type * from "./modules/webhook/schemas";
|
|
81
|
+
export type * from "./modules/settings/schemas";
|
|
82
|
+
export type { ClientOptions };
|
|
83
|
+
|
|
84
|
+
// API types
|
|
85
|
+
export { APIRequestInit, MethodOptions } from "./types/api";
|
|
86
|
+
export { MessageUpdateStatus } from "./types/messages";
|
|
87
|
+
export { ChatId, GroupJid, Jid, MessageId } from "./types/tags";
|
|
88
|
+
export * from "./types/webhooks";
|
|
89
|
+
export { WebhookEvent, WebhookEventSetup } from "./types/events";
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { Routes } from "@/api/routes";
|
|
2
|
+
import type { ApiService } from "@/api/service";
|
|
3
|
+
import { validateGroupJid, validateJid } from "@/schemas/common";
|
|
4
|
+
import type { MethodOptions } from "@/types/api";
|
|
5
|
+
|
|
6
|
+
import type * as Archive from "./schemas/archive";
|
|
7
|
+
import type * as Check from "./schemas/check";
|
|
8
|
+
import type * as DeleteMessage from "./schemas/delete-message";
|
|
9
|
+
import type * as FetchProfilePicture from "./schemas/fetch-profile-picture";
|
|
10
|
+
import type * as FindAll from "./schemas/find-all";
|
|
11
|
+
import type * as FindContacts from "./schemas/find-contacts";
|
|
12
|
+
import type * as FindMessages from "./schemas/find-messages";
|
|
13
|
+
import type * as FindStatusMessage from "./schemas/find-status-message";
|
|
14
|
+
import type * as GetBase64FromMediaMessage from "./schemas/get-base64-from-media-message";
|
|
15
|
+
import type * as MarkAsRead from "./schemas/mark-as-read";
|
|
16
|
+
import type * as MarkAsUnread from "./schemas/mark-as-unread";
|
|
17
|
+
import type * as Presence from "./schemas/presence";
|
|
18
|
+
import type * as UpdateMessage from "./schemas/update-message";
|
|
19
|
+
|
|
20
|
+
export class ChatsModule {
|
|
21
|
+
constructor(private readonly api: ApiService) {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks if phone numbers are registered on WhatsApp
|
|
25
|
+
* @param numbers - Array of phone numbers to check
|
|
26
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
27
|
+
*/
|
|
28
|
+
async check(
|
|
29
|
+
numbers: Check.CheckOptions,
|
|
30
|
+
methodOptions?: MethodOptions
|
|
31
|
+
): Promise<Check.CheckResponse> {
|
|
32
|
+
const body = {
|
|
33
|
+
numbers: Array.isArray(numbers) ? numbers : [numbers],
|
|
34
|
+
};
|
|
35
|
+
const response = await this.api.post(Routes.Chats.Check, {
|
|
36
|
+
body,
|
|
37
|
+
...methodOptions,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return response as Check.CheckResponse;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Gets all chats
|
|
45
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
46
|
+
*/
|
|
47
|
+
async findAll(
|
|
48
|
+
methodOptions?: MethodOptions
|
|
49
|
+
): Promise<FindAll.FindAllChatsResponse> {
|
|
50
|
+
const response = await this.api.post(Routes.Chats.FindAll, {
|
|
51
|
+
body: {},
|
|
52
|
+
...methodOptions,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response as FindAll.FindAllChatsResponse;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Updates presence status
|
|
60
|
+
* @param params - Presence parameters
|
|
61
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
62
|
+
*/
|
|
63
|
+
async updatePresence(
|
|
64
|
+
options: Presence.PresenceOptions,
|
|
65
|
+
methodOptions?: MethodOptions
|
|
66
|
+
): Promise<void> {
|
|
67
|
+
if (!options.number) {
|
|
68
|
+
throw new Error("Number is required");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!validateJid(options.number) && !validateGroupJid(options.number)) {
|
|
72
|
+
options.number = `${options.number}@s.whatsapp.net`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await this.api.post(Routes.Chats.SendPresence, {
|
|
76
|
+
body: options,
|
|
77
|
+
...methodOptions,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Marks messages as read
|
|
83
|
+
* @param options - Mark as read options
|
|
84
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
85
|
+
*/
|
|
86
|
+
async markAsRead(
|
|
87
|
+
options: MarkAsRead.MarkAsReadRequest,
|
|
88
|
+
methodOptions?: MethodOptions
|
|
89
|
+
): Promise<MarkAsRead.MarkAsReadResponse> {
|
|
90
|
+
const response = await this.api.post(Routes.Chats.MarkAsRead, {
|
|
91
|
+
body: options,
|
|
92
|
+
...methodOptions,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return response as MarkAsRead.MarkAsReadResponse;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Marks messages as unread
|
|
100
|
+
* @param options - Mark as unread options
|
|
101
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
102
|
+
*/
|
|
103
|
+
async markAsUnread(
|
|
104
|
+
options: MarkAsUnread.MarkAsUnreadRequest,
|
|
105
|
+
methodOptions?: MethodOptions
|
|
106
|
+
): Promise<MarkAsUnread.MarkAsUnreadResponse> {
|
|
107
|
+
const response = await this.api.post(Routes.Chats.MarkAsUnread, {
|
|
108
|
+
body: options,
|
|
109
|
+
...methodOptions,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return response as MarkAsUnread.MarkAsUnreadResponse;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Archives a chat
|
|
117
|
+
* @param options - Archive options
|
|
118
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
119
|
+
*/
|
|
120
|
+
async archive(
|
|
121
|
+
options: Archive.ArchiveRequest,
|
|
122
|
+
methodOptions?: MethodOptions
|
|
123
|
+
): Promise<Archive.ArchiveResponse> {
|
|
124
|
+
const response = await this.api.post(Routes.Chats.Archive, {
|
|
125
|
+
body: options,
|
|
126
|
+
...methodOptions,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return response as Archive.ArchiveResponse;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Deletes a message
|
|
134
|
+
* @param options - Delete message options
|
|
135
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
136
|
+
*/
|
|
137
|
+
async deleteMessage(
|
|
138
|
+
options: DeleteMessage.DeleteMessageRequest,
|
|
139
|
+
methodOptions?: MethodOptions
|
|
140
|
+
): Promise<DeleteMessage.DeleteMessageResponse> {
|
|
141
|
+
const response = await this.api.delete(Routes.Chats.DeleteMessage, {
|
|
142
|
+
body: options,
|
|
143
|
+
...methodOptions,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return response as DeleteMessage.DeleteMessageResponse;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Fetches profile picture
|
|
151
|
+
* @param options - Fetch profile picture options
|
|
152
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
153
|
+
*/
|
|
154
|
+
async fetchProfilePicture(
|
|
155
|
+
options: FetchProfilePicture.FetchProfilePictureRequest,
|
|
156
|
+
methodOptions?: MethodOptions
|
|
157
|
+
): Promise<FetchProfilePicture.FetchProfilePictureResponse> {
|
|
158
|
+
const response = await this.api.post(Routes.Chats.FetchProfilePicture, {
|
|
159
|
+
body: options,
|
|
160
|
+
...methodOptions,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return response as FetchProfilePicture.FetchProfilePictureResponse;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Finds contacts
|
|
168
|
+
* @param options - Find contacts options
|
|
169
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
170
|
+
*/
|
|
171
|
+
async findContacts(
|
|
172
|
+
options: FindContacts.FindContactsRequest,
|
|
173
|
+
methodOptions?: MethodOptions
|
|
174
|
+
): Promise<FindContacts.FindContactsResponse> {
|
|
175
|
+
const response = await this.api.post(Routes.Chats.FindContacts, {
|
|
176
|
+
body: options,
|
|
177
|
+
...methodOptions,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return response as FindContacts.FindContactsResponse;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Finds messages
|
|
185
|
+
* @param options - Find messages options
|
|
186
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
187
|
+
*/
|
|
188
|
+
async findMessages(
|
|
189
|
+
options: FindMessages.FindMessagesRequest,
|
|
190
|
+
methodOptions?: MethodOptions
|
|
191
|
+
): Promise<FindMessages.FindMessagesResponse> {
|
|
192
|
+
const response = await this.api.post(Routes.Chats.FindMessages, {
|
|
193
|
+
body: options,
|
|
194
|
+
...methodOptions,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return response as FindMessages.FindMessagesResponse;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Finds status messages
|
|
202
|
+
* @param options - Find status message options
|
|
203
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
204
|
+
*/
|
|
205
|
+
async findStatusMessage(
|
|
206
|
+
options: FindStatusMessage.FindStatusMessageRequest,
|
|
207
|
+
methodOptions?: MethodOptions
|
|
208
|
+
): Promise<FindStatusMessage.FindStatusMessageResponse> {
|
|
209
|
+
const response = await this.api.post(Routes.Chats.FindStatusMessage, {
|
|
210
|
+
body: options,
|
|
211
|
+
...methodOptions,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return response as FindStatusMessage.FindStatusMessageResponse;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Updates a message
|
|
219
|
+
* @param options - Update message options
|
|
220
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
221
|
+
*/
|
|
222
|
+
async updateMessage(
|
|
223
|
+
options: UpdateMessage.UpdateMessageRequest,
|
|
224
|
+
methodOptions?: MethodOptions
|
|
225
|
+
): Promise<UpdateMessage.UpdateMessageResponse> {
|
|
226
|
+
const response = await this.api.put(Routes.Chats.UpdateMessage, {
|
|
227
|
+
body: options,
|
|
228
|
+
...methodOptions,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return response as UpdateMessage.UpdateMessageResponse;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Gets base64 representation of media from a message
|
|
236
|
+
* @param options - Get base64 from media message options
|
|
237
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
238
|
+
*/
|
|
239
|
+
async getBase64FromMediaMessage(
|
|
240
|
+
options: GetBase64FromMediaMessage.GetBase64FromMediaMessageRequest,
|
|
241
|
+
methodOptions?: MethodOptions
|
|
242
|
+
): Promise<GetBase64FromMediaMessage.GetBase64FromMediaMessageResponse> {
|
|
243
|
+
const response = await this.api.post(
|
|
244
|
+
Routes.Chats.GetBase64FromMediaMessage,
|
|
245
|
+
{
|
|
246
|
+
body: options,
|
|
247
|
+
...methodOptions,
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return response as GetBase64FromMediaMessage.GetBase64FromMediaMessageResponse;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface ArchiveRequest {
|
|
5
|
+
number: ChatId;
|
|
6
|
+
archive: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ArchiveResponse {
|
|
10
|
+
status: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Backward compatibility aliases
|
|
15
|
+
export type ArchiveOptions = ArchiveRequest;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { parsePhoneNumber } from "libphonenumber-js";
|
|
3
|
+
import { Jid } from "@/types/tags";
|
|
4
|
+
|
|
5
|
+
// Raw response interface from API
|
|
6
|
+
export interface CheckResponseRaw {
|
|
7
|
+
exists: boolean;
|
|
8
|
+
jid: string;
|
|
9
|
+
number: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Transformed response interface
|
|
13
|
+
export interface CheckResponseItem {
|
|
14
|
+
exists: boolean;
|
|
15
|
+
jid: Jid;
|
|
16
|
+
number: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CheckOptions = string | string[];
|
|
20
|
+
export type CheckResponse = CheckResponseItem[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId, MessageId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface DeleteMessageRequest {
|
|
5
|
+
number: ChatId;
|
|
6
|
+
messageId: MessageId;
|
|
7
|
+
owner: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DeleteMessageResponse {
|
|
11
|
+
status: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Backward compatibility aliases
|
|
16
|
+
export type DeleteMessageOptions = DeleteMessageRequest;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface FetchProfilePictureRequest {
|
|
5
|
+
number: ChatId;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface FetchProfilePictureResponse {
|
|
9
|
+
profilePictureUrl: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Backward compatibility aliases
|
|
13
|
+
export type FetchProfilePictureOptions = FetchProfilePictureRequest;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { ChatId, GroupJid, Jid } from "@/types/tags";
|
|
3
|
+
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
|
|
4
|
+
|
|
5
|
+
// Raw response interface from API
|
|
6
|
+
export interface FindAllChatsResponseRaw {
|
|
7
|
+
id: string;
|
|
8
|
+
remoteJid: string;
|
|
9
|
+
name?: string | null;
|
|
10
|
+
labels?: string[] | null;
|
|
11
|
+
createdAt: string | Date;
|
|
12
|
+
updatedAt: string | Date;
|
|
13
|
+
pushName?: string | null;
|
|
14
|
+
profilePicUrl?: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Transformed response interface
|
|
18
|
+
export interface FindAllChatsResponseItem {
|
|
19
|
+
id: ChatId;
|
|
20
|
+
jid: GroupJid | Jid;
|
|
21
|
+
phoneNumber: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
labels?: string[];
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
pushName?: string;
|
|
27
|
+
pictureUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type FindAllChatsResponse = FindAllChatsResponseItem[];
|
|
31
|
+
|
|
32
|
+
// Transform function
|
|
33
|
+
export const FindAllChatsResponseTransform = (chats: FindAllChatsResponseRaw[]): FindAllChatsResponse =>
|
|
34
|
+
chats.map((chat) => ({
|
|
35
|
+
id: ChatId(chat.id),
|
|
36
|
+
jid: chat.remoteJid.endsWith("@g.us")
|
|
37
|
+
? GroupJid(chat.remoteJid)
|
|
38
|
+
: Jid(chat.remoteJid),
|
|
39
|
+
phoneNumber: phoneNumberFromJid(chat.remoteJid),
|
|
40
|
+
name: chat.name || undefined,
|
|
41
|
+
labels: chat.labels || undefined,
|
|
42
|
+
createdAt: new Date(chat.createdAt),
|
|
43
|
+
updatedAt: new Date(chat.updatedAt),
|
|
44
|
+
pushName: chat.pushName || undefined,
|
|
45
|
+
pictureUrl: chat.profilePicUrl || undefined,
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
// Backward compatibility alias
|
|
49
|
+
export const ResponseSchema = { parse: FindAllChatsResponseTransform };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface FindContactsRequest {
|
|
5
|
+
number: ChatId;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Contact {
|
|
9
|
+
id: ChatId;
|
|
10
|
+
name: string;
|
|
11
|
+
pushname: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type FindContactsResponse = Contact[];
|
|
15
|
+
|
|
16
|
+
// Backward compatibility aliases
|
|
17
|
+
export type FindContactsOptions = FindContactsRequest;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { Jid } from "@/types/tags";
|
|
3
|
+
import type {
|
|
4
|
+
ContextInfo,
|
|
5
|
+
MessageContent,
|
|
6
|
+
MessageUpdate,
|
|
7
|
+
} from "@/types/webhooks";
|
|
8
|
+
|
|
9
|
+
export interface FindMessagesRequest {
|
|
10
|
+
where: {
|
|
11
|
+
key: {
|
|
12
|
+
id?: string;
|
|
13
|
+
fromMe?: boolean;
|
|
14
|
+
remoteJid?: string;
|
|
15
|
+
participants?: string;
|
|
16
|
+
messageTimestamp?: {
|
|
17
|
+
lte: string;
|
|
18
|
+
gte: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
page?: number;
|
|
23
|
+
offset?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ResponseMessage {
|
|
27
|
+
id: string;
|
|
28
|
+
key: {
|
|
29
|
+
id: string;
|
|
30
|
+
fromMe: boolean;
|
|
31
|
+
remoteJid: Jid;
|
|
32
|
+
senderLid?: string;
|
|
33
|
+
};
|
|
34
|
+
pushName?: string;
|
|
35
|
+
messageType: string;
|
|
36
|
+
message: MessageContent;
|
|
37
|
+
messageTimestamp: number;
|
|
38
|
+
instanceId: string;
|
|
39
|
+
source: string;
|
|
40
|
+
contextInfo?: ContextInfo | null;
|
|
41
|
+
MessageUpdate: MessageUpdate[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface FindMessagesResponse {
|
|
45
|
+
messages: {
|
|
46
|
+
total: number;
|
|
47
|
+
pages: number;
|
|
48
|
+
currentPage: number;
|
|
49
|
+
records: ResponseMessage[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Backward compatibility aliases
|
|
54
|
+
export type FindMessagesOptions = FindMessagesRequest;
|
|
55
|
+
export type Message = ResponseMessage;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface FindStatusMessageRequest {
|
|
5
|
+
number: ChatId;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type FindStatusMessageResponse = any[];
|
|
9
|
+
|
|
10
|
+
// Backward compatibility aliases
|
|
11
|
+
export type FindStatusMessageOptions = FindStatusMessageRequest;
|