@in.pulse-crm/sdk 2.9.7 → 2.10.1

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.
@@ -20,7 +20,7 @@ declare class FilesClient extends ApiClient {
20
20
  * @param {number} id - ID do arquivo.
21
21
  * @returns {string} URL de download do arquivo.
22
22
  */
23
- getFileDownloadUrl(id: number): string;
23
+ getFileDownloadUrl(id: number, baseUrl?: string): string;
24
24
  /**
25
25
  * Faz o upload de um arquivo.
26
26
  * @param {UploadFileOptions} props - Opções para o upload do arquivo.
@@ -33,8 +33,8 @@ class FilesClient extends api_client_1.default {
33
33
  * @param {number} id - ID do arquivo.
34
34
  * @returns {string} URL de download do arquivo.
35
35
  */
36
- getFileDownloadUrl(id) {
37
- return this.ax.defaults.baseURL + `/api/files/${id}`;
36
+ getFileDownloadUrl(id, baseUrl) {
37
+ return (baseUrl || this.ax.defaults.baseURL) + `/api/files/${id}`;
38
38
  }
39
39
  /**
40
40
  * Faz o upload de um arquivo.
@@ -148,3 +148,19 @@ export interface WppSchedule {
148
148
  chatId: number | null;
149
149
  contact: WppContact;
150
150
  }
151
+ export type NotificationType = "CHAT_AUTO_FINISHED" | "CHAT_TRANSFERRED" | "CHAT_REASSIGNED" | "ALERT" | "INFO" | "WARNING" | "ERROR";
152
+ export interface AppNotification {
153
+ id: number;
154
+ title: string;
155
+ description: string;
156
+ read: boolean;
157
+ instance: string;
158
+ userId: number | null;
159
+ chatId: number | null;
160
+ type: NotificationType;
161
+ createdAt: string;
162
+ }
163
+ export interface PaginatedNotificationsResponse {
164
+ notifications: AppNotification[];
165
+ totalCount: number;
166
+ }
@@ -1,6 +1,12 @@
1
1
  import ApiClient from "./api-client";
2
2
  import { RequestFilters } from "./types";
3
- import { CreateScheduleDTO, ForwardMessagesData, SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppSchedule, WppWallet } from "./types/whatsapp.types";
3
+ import { DataResponse, MessageResponse } from "./types/response.types";
4
+ import { AppNotification, CreateScheduleDTO, ForwardMessagesData, PaginatedNotificationsResponse, SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppSchedule, WppWallet } from "./types/whatsapp.types";
5
+ interface FetchMessagesFilters {
6
+ minDate: string;
7
+ maxDate: string;
8
+ userId?: number | null;
9
+ }
4
10
  export default class WhatsappClient extends ApiClient {
5
11
  getChatsBySession(messages?: boolean, contact?: boolean, token?: string | null): Promise<WppChatsAndMessages>;
6
12
  getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
@@ -28,8 +34,22 @@ export default class WhatsappClient extends ApiClient {
28
34
  setAuth(token: string): void;
29
35
  getChatsMonitor(): Promise<WppChatsAndMessages>;
30
36
  transferAttendance(id: number, userId: number): Promise<void>;
31
- getNotifications(): Promise<any>;
32
- markAllAsReadNotification(): Promise<any>;
37
+ /**
38
+ * Busca as notificações do usuário de forma paginada.
39
+ */
40
+ getNotifications(params: {
41
+ page: number;
42
+ pageSize: number;
43
+ }): Promise<DataResponse<PaginatedNotificationsResponse>>;
44
+ /**
45
+ * Marca todas as notificações do usuário como lidas.
46
+ */
47
+ markAllAsReadNotification(): Promise<MessageResponse>;
48
+ /**
49
+ * Marca uma notificação específica como lida.
50
+ * @param notificationId - O ID (numérico) da notificação a ser marcada.
51
+ */
52
+ markOneAsReadNotification(notificationId: number): Promise<DataResponse<AppNotification>>;
33
53
  /**
34
54
  * Obtém os detalhes de um agendamento.
35
55
  * @param filters - keys de WppSchedule.
@@ -56,4 +76,8 @@ export default class WhatsappClient extends ApiClient {
56
76
  * @returns Uma Promise que resolve para um objeto wppSchedule.
57
77
  */
58
78
  deleteSchedule(scheduleId: number): Promise<any>;
79
+ getMessages(token: string, filters: FetchMessagesFilters): Promise<(WppMessage & {
80
+ WppContact: WppContact | null;
81
+ })[]>;
59
82
  }
83
+ export {};
@@ -128,15 +128,34 @@ class WhatsappClient extends api_client_1.default {
128
128
  const body = { userId };
129
129
  await this.ax.post(url, body);
130
130
  }
131
- async getNotifications() {
132
- const url = `/api/whatsapp/notifications`;
131
+ /**
132
+ * Busca as notificações do usuário de forma paginada.
133
+ */
134
+ async getNotifications(params) {
135
+ const searchParams = new URLSearchParams({
136
+ page: String(params.page),
137
+ pageSize: String(params.pageSize),
138
+ });
139
+ const url = `/api/whatsapp/notifications?${searchParams.toString()}`;
133
140
  const { data: res } = await this.ax.get(url);
134
- return res.data;
141
+ return res;
135
142
  }
143
+ /**
144
+ * Marca todas as notificações do usuário como lidas.
145
+ */
136
146
  async markAllAsReadNotification() {
137
147
  const url = `/api/whatsapp/notifications/mark-all-read`;
138
148
  const { data: res } = await this.ax.patch(url);
139
- return res.data;
149
+ return res;
150
+ }
151
+ /**
152
+ * Marca uma notificação específica como lida.
153
+ * @param notificationId - O ID (numérico) da notificação a ser marcada.
154
+ */
155
+ async markOneAsReadNotification(notificationId) {
156
+ const url = `/api/whatsapp/notifications/${notificationId}/read`;
157
+ const { data: res } = await this.ax.patch(url);
158
+ return res;
140
159
  }
141
160
  /**
142
161
  * Obtém os detalhes de um agendamento.
@@ -203,5 +222,20 @@ class WhatsappClient extends api_client_1.default {
203
222
  const response = await this.ax.delete(`/api/whatsapp/schedules/${scheduleId}`);
204
223
  return response.data;
205
224
  }
225
+ async getMessages(token, filters) {
226
+ const params = new URLSearchParams(Object.entries(filters)
227
+ .filter(([_, v]) => v !== undefined && v !== null)
228
+ .reduce((acc, [k, v]) => {
229
+ acc[k] = String(v);
230
+ return acc;
231
+ }, {}));
232
+ const url = `/api/whatsapp/messages?${params.toString()}`;
233
+ const { data: res } = await this.ax.get(url, {
234
+ headers: {
235
+ Authorization: `Bearer ${token}`,
236
+ },
237
+ });
238
+ return res.data;
239
+ }
206
240
  }
207
241
  exports.default = WhatsappClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.9.7",
3
+ "version": "2.10.1",
4
4
  "description": "SDKs for abstraction of api consumption of in.pulse-crm application",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -37,8 +37,8 @@ class FilesClient extends ApiClient {
37
37
  * @param {number} id - ID do arquivo.
38
38
  * @returns {string} URL de download do arquivo.
39
39
  */
40
- public getFileDownloadUrl(id: number): string {
41
- return this.ax.defaults.baseURL + `/api/files/${id}`;
40
+ public getFileDownloadUrl(id: number, baseUrl?: string): string {
41
+ return (baseUrl || this.ax.defaults.baseURL) + `/api/files/${id}`;
42
42
  }
43
43
 
44
44
  /**
@@ -164,3 +164,29 @@ export interface WppSchedule {
164
164
  chatId: number | null;
165
165
  contact: WppContact;
166
166
  }
167
+ export type NotificationType =
168
+ | "CHAT_AUTO_FINISHED"
169
+ | "CHAT_TRANSFERRED"
170
+ | "CHAT_REASSIGNED"
171
+ | "ALERT"
172
+ | "INFO"
173
+ | "WARNING"
174
+ | "ERROR";
175
+
176
+
177
+ export interface AppNotification {
178
+ id: number;
179
+ title: string;
180
+ description: string;
181
+ read: boolean;
182
+ instance: string;
183
+ userId: number | null;
184
+ chatId: number | null;
185
+ type: NotificationType;
186
+ createdAt: string;
187
+ }
188
+
189
+ export interface PaginatedNotificationsResponse {
190
+ notifications: AppNotification[];
191
+ totalCount: number;
192
+ }
@@ -2,315 +2,341 @@ import ApiClient from "./api-client";
2
2
  import { RequestFilters } from "./types";
3
3
  import { DataResponse, MessageResponse } from "./types/response.types";
4
4
  import {
5
- CreateScheduleDTO,
6
- ForwardMessagesData,
7
- SendMessageData,
8
- WppChatsAndMessages,
9
- WppChatWithDetailsAndMessages,
10
- WppContact,
11
- WppContactWithCustomer,
12
- WppMessage,
13
- WppSchedule,
14
- WppWallet,
5
+ AppNotification,
6
+ CreateScheduleDTO,
7
+ ForwardMessagesData,
8
+ PaginatedNotificationsResponse,
9
+ SendMessageData,
10
+ WppChatsAndMessages,
11
+ WppChatWithDetailsAndMessages,
12
+ WppContact,
13
+ WppContactWithCustomer,
14
+ WppMessage,
15
+ WppSchedule,
16
+ WppWallet,
15
17
  } from "./types/whatsapp.types";
16
18
  import FormData from "form-data";
17
19
 
20
+
18
21
  type GetChatsResponse = DataResponse<WppChatsAndMessages>;
19
22
  type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
20
23
  type GetMessageResponse = DataResponse<WppMessage>;
21
24
  type MarkChatAsReadResponse = DataResponse<WppMessage[]>;
22
25
 
23
- export default class WhatsappClient extends ApiClient {
24
- public async getChatsBySession(
25
- messages = false,
26
- contact = false,
27
- token: string | null = null,
28
- ) {
29
- const headers = token
30
- ? { Authorization: `Bearer ${token}` }
31
- : undefined;
32
- const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
33
-
34
- const { data: res } = await this.ax.get<GetChatsResponse>(url, {
35
- headers,
36
- });
37
-
38
- return res.data;
39
- }
40
-
41
- public async getChatById(id: number) {
42
- const { data: res } = await this.ax.get<GetChatResponse>(
43
- `/api/whatsapp/chats/${id}`,
44
- );
45
-
46
- return res.data;
47
- }
48
-
49
- public async getMessageById(id: string) {
50
- const { data: res } = await this.ax.get<GetMessageResponse>(
51
- `/api/whatsapp/messages/${id}`,
52
- );
53
-
54
- return res.data;
55
- }
56
-
57
- public async getUserWallets(instance: string, userId: number) {
58
- const { data: res } = await this.ax.get<DataResponse<WppWallet[]>>(
59
- `/api/wallets?instance=${instance}&userId=${userId}`,
60
- );
61
-
62
- return res.data;
63
- }
64
-
65
- public async markContactMessagesAsRead(contactId: number) {
66
- const url = "/api/whatsapp/messages/mark-as-read";
67
- const body = { contactId };
68
- const { data: res } = await this.ax.patch<MarkChatAsReadResponse>(
69
- url,
70
- body,
71
- );
72
-
73
- return res.data;
74
- }
75
-
76
- public async sendMessage(to: string, data: SendMessageData) {
77
- const url = "/api/whatsapp/messages";
78
- const formData = new FormData();
79
-
80
- formData.append("to", to);
81
- data.text && formData.append("text", data.text);
82
- data.file && formData.append("file", data.file);
83
- data.quotedId && formData.append("quotedId", String(data.quotedId));
84
- data.chatId && formData.append("chatId", String(data.chatId));
85
- data.contactId && formData.append("contactId", String(data.contactId));
86
- data.sendAsAudio && formData.append("sendAsAudio", "true");
87
- data.sendAsDocument && formData.append("sendAsDocument", "true");
88
- data.sendAsChatOwner &&
89
- formData.append("sendAsChatOwner", String(data.sendAsChatOwner));
90
-
91
- const { data: res } = await this.ax.post<DataResponse<WppMessage>>(
92
- url,
93
- formData,
94
- {
95
- headers: {
96
- "Content-Type": "multipart/form-data",
97
- },
98
- },
99
- );
100
-
101
- return res.data;
102
- }
103
-
104
- public async finishChatById(id: number, resultId: number) {
105
- const url = `/api/whatsapp/chats/${id}/finish`;
106
- const body = { resultId };
26
+ interface FetchMessagesFilters {
27
+ minDate: string;
28
+ maxDate: string;
29
+ userId?: number | null;
30
+ }
107
31
 
108
- await this.ax.post<MessageResponse>(url, body);
109
- }
32
+ export default class WhatsappClient extends ApiClient {
33
+ public async getChatsBySession(
34
+ messages = false,
35
+ contact = false,
36
+ token: string | null = null,
37
+ ) {
38
+ const headers = token
39
+ ? { Authorization: `Bearer ${token}` }
40
+ : undefined;
41
+ const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
42
+ const { data: res } = await this.ax.get<GetChatsResponse>(url, {
43
+ headers,
44
+ });
45
+ return res.data;
46
+ }
110
47
 
111
- public async startChatByContactId(contactId: number, template?: any) {
112
- const url = `/api/whatsapp/chats`;
113
- const body = { contactId, template };
48
+ public async getChatById(id: number) {
49
+ const { data: res } = await this.ax.get<GetChatResponse>(
50
+ `/api/whatsapp/chats/${id}`,
51
+ );
52
+ return res.data;
53
+ }
114
54
 
115
- const { data: res } = await this.ax.post<
116
- DataResponse<WppChatWithDetailsAndMessages>
117
- >(url, body);
55
+ public async getMessageById(id: string) {
56
+ const { data: res } = await this.ax.get<GetMessageResponse>(
57
+ `/api/whatsapp/messages/${id}`,
58
+ );
59
+ return res.data;
60
+ }
118
61
 
119
- return res.data;
120
- }
62
+ public async getUserWallets(instance: string, userId: number) {
63
+ const { data: res } = await this.ax.get<DataResponse<WppWallet[]>>(
64
+ `/api/wallets?instance=${instance}&userId=${userId}`,
65
+ );
66
+ return res.data;
67
+ }
121
68
 
122
- public async getResults() {
123
- const url = `/api/whatsapp/results`;
124
- const { data: res } =
125
- await this.ax.get<DataResponse<{ id: number; name: string }[]>>(
126
- url,
127
- );
69
+ public async markContactMessagesAsRead(contactId: number) {
70
+ const url = "/api/whatsapp/messages/mark-as-read";
71
+ const body = { contactId };
72
+ const { data: res } = await this.ax.patch<MarkChatAsReadResponse>(
73
+ url,
74
+ body,
75
+ );
76
+ return res.data;
77
+ }
128
78
 
129
- return res.data;
130
- }
79
+ public async sendMessage(to: string, data: SendMessageData) {
80
+ const url = "/api/whatsapp/messages";
81
+ const formData = new FormData();
82
+ formData.append("to", to);
83
+ data.text && formData.append("text", data.text);
84
+ data.file && formData.append("file", data.file);
85
+ data.quotedId && formData.append("quotedId", String(data.quotedId));
86
+ data.chatId && formData.append("chatId", String(data.chatId));
87
+ data.contactId && formData.append("contactId", String(data.contactId));
88
+ data.sendAsAudio && formData.append("sendAsAudio", "true");
89
+ data.sendAsDocument && formData.append("sendAsDocument", "true");
90
+ data.sendAsChatOwner &&
91
+ formData.append("sendAsChatOwner", String(data.sendAsChatOwner));
92
+ const { data: res } = await this.ax.post<DataResponse<WppMessage>>(
93
+ url,
94
+ formData,
95
+ {
96
+ headers: {
97
+ "Content-Type": "multipart/form-data",
98
+ },
99
+ },
100
+ );
101
+ return res.data;
102
+ }
131
103
 
132
- public async getCustomerContacts(customerId: number) {
133
- const url = `/api/whatsapp/customer/${customerId}/contacts`;
134
- const { data: res } =
135
- await this.ax.get<DataResponse<WppContact[]>>(url);
104
+ public async finishChatById(id: number, resultId: number) {
105
+ const url = `/api/whatsapp/chats/${id}/finish`;
106
+ const body = { resultId };
107
+ await this.ax.post<MessageResponse>(url, body);
108
+ }
136
109
 
137
- return res.data;
138
- }
110
+ public async startChatByContactId(contactId: number, template?: any) {
111
+ const url = `/api/whatsapp/chats`;
112
+ const body = { contactId, template };
113
+ const { data: res } = await this.ax.post<
114
+ DataResponse<WppChatWithDetailsAndMessages>
115
+ >(url, body);
116
+ return res.data;
117
+ }
139
118
 
140
- public async getContactsWithCustomer() {
141
- const url = `/api/whatsapp/contacts/customer`;
142
- const { data: res } =
143
- await this.ax.get<DataResponse<WppContactWithCustomer[]>>(url);
119
+ public async getResults() {
120
+ const url = `/api/whatsapp/results`;
121
+ const { data: res } =
122
+ await this.ax.get<DataResponse<{ id: number; name: string }[]>>(
123
+ url,
124
+ );
125
+ return res.data;
126
+ }
144
127
 
145
- return res.data;
146
- }
147
- public async getContacts() {
148
- const url = `/api/whatsapp/contacts`;
149
- const { data: res } =
150
- await this.ax.get<DataResponse<WppContact[]>>(url);
128
+ public async getCustomerContacts(customerId: number) {
129
+ const url = `/api/whatsapp/customer/${customerId}/contacts`;
130
+ const { data: res } =
131
+ await this.ax.get<DataResponse<WppContact[]>>(url);
132
+ return res.data;
133
+ }
151
134
 
152
- return res.data;
153
- }
154
- public async createContact(
155
- name: string,
156
- phone: string,
157
- customerId?: number,
158
- ) {
159
- const baseUrl = `/api/whatsapp`;
160
- const url = customerId
161
- ? `${baseUrl}/customers/${customerId}/contacts`
162
- : `${baseUrl}/contacts`;
135
+ public async getContactsWithCustomer() {
136
+ const url = `/api/whatsapp/contacts/customer`;
137
+ const { data: res } =
138
+ await this.ax.get<DataResponse<WppContactWithCustomer[]>>(url);
139
+ return res.data;
140
+ }
163
141
 
164
- const body = { name, phone };
142
+ public async getContacts() {
143
+ const url = `/api/whatsapp/contacts`;
144
+ const { data: res } =
145
+ await this.ax.get<DataResponse<WppContact[]>>(url);
146
+ return res.data;
147
+ }
165
148
 
166
- const { data: res } = await this.ax.post<DataResponse<WppContact>>(
167
- url,
168
- body,
169
- );
149
+ public async createContact(
150
+ name: string,
151
+ phone: string,
152
+ customerId?: number,
153
+ ) {
154
+ const baseUrl = `/api/whatsapp`;
155
+ const url = customerId
156
+ ? `${baseUrl}/customers/${customerId}/contacts`
157
+ : `${baseUrl}/contacts`;
158
+ const body = { name, phone };
159
+ const { data: res } = await this.ax.post<DataResponse<WppContact>>(
160
+ url,
161
+ body,
162
+ );
163
+ return res.data;
164
+ }
170
165
 
171
- return res.data;
172
- }
173
166
  public async forwardMessages(data: ForwardMessagesData) {
174
167
  const url = "/api/whatsapp/messages/forward";
175
-
176
168
  const body = data;
177
-
178
169
  await this.ax.post<MessageResponse>(url, body);
179
170
  }
180
- public async updateContact(contactId: number, name: string, customerId?: number | null) {
181
- const url = `/api/whatsapp/contacts/${contactId}`;
182
- const body: Record<string, any> = { name };
183
-
184
- customerId !== undefined && (body["customerId"] = customerId);
185
-
186
- const { data: res } = await this.ax.put<DataResponse<WppContact>>(
187
- url,
188
- body,
189
- );
190
171
 
191
- return res.data;
192
- }
193
-
194
- public async deleteContact(contactId: number) {
195
- const url = `/api/whatsapp/contacts/${contactId}`;
196
-
197
- await this.ax.delete<MessageResponse>(url);
198
- }
199
-
200
- public async getSectors() {
201
- const url = `/api/whatsapp/sectors`;
202
- const { data: res } =
203
- await this.ax.get<DataResponse<{ id: number; name: string }[]>>(
204
- url,
205
- );
206
-
207
- return res.data;
208
- }
209
-
210
- public setAuth(token: string) {
211
- this.ax.defaults.headers.common["Authorization"] = `Bearer ${token}`;
212
- }
213
- public async getChatsMonitor() {
214
- const url = `/api/whatsapp/session/monitor`;
172
+ public async updateContact(
173
+ contactId: number,
174
+ name: string,
175
+ customerId?: number | null,
176
+ ) {
177
+ const url = `/api/whatsapp/contacts/${contactId}`;
178
+ const body: Record<string, any> = { name };
179
+ customerId !== undefined && (body["customerId"] = customerId);
180
+ const { data: res } = await this.ax.put<DataResponse<WppContact>>(
181
+ url,
182
+ body,
183
+ );
184
+ return res.data;
185
+ }
215
186
 
216
- const { data: res } = await this.ax.get<GetChatsResponse>(url);
187
+ public async deleteContact(contactId: number) {
188
+ const url = `/api/whatsapp/contacts/${contactId}`;
189
+ await this.ax.delete<MessageResponse>(url);
190
+ }
217
191
 
218
- return res.data;
219
- }
220
- public async transferAttendance(id: number, userId: number) {
221
- const url = `/api/whatsapp/chats/${id}/transfer`;
222
- const body = { userId };
192
+ public async getSectors() {
193
+ const url = `/api/whatsapp/sectors`;
194
+ const { data: res } =
195
+ await this.ax.get<DataResponse<{ id: number; name: string }[]>>(
196
+ url,
197
+ );
198
+ return res.data;
199
+ }
223
200
 
224
- await this.ax.post<MessageResponse>(url, body);
225
- }
226
- public async getNotifications() {
227
- const url = `/api/whatsapp/notifications`;
228
- const { data: res } = await this.ax.get<DataResponse<any>>(url);
201
+ public setAuth(token: string) {
202
+ this.ax.defaults.headers.common["Authorization"] = `Bearer ${token}`;
203
+ }
229
204
 
230
- return res.data;
231
- }
205
+ public async getChatsMonitor() {
206
+ const url = `/api/whatsapp/session/monitor`;
207
+ const { data: res } = await this.ax.get<GetChatsResponse>(url);
208
+ return res.data;
209
+ }
232
210
 
233
- public async markAllAsReadNotification() {
234
- const url = `/api/whatsapp/notifications/mark-all-read`;
235
- const { data: res } = await this.ax.patch<DataResponse<any>>(url);
211
+ public async transferAttendance(id: number, userId: number) {
212
+ const url = `/api/whatsapp/chats/${id}/transfer`;
213
+ const body = { userId };
214
+ await this.ax.post<MessageResponse>(url, body);
215
+ }
216
+ /**
217
+ * Busca as notificações do usuário de forma paginada.
218
+ */
219
+ public async getNotifications(params: { page: number; pageSize: number }) {
220
+ const searchParams = new URLSearchParams({
221
+ page: String(params.page),
222
+ pageSize: String(params.pageSize),
223
+ });
224
+ const url = `/api/whatsapp/notifications?${searchParams.toString()}`;
225
+ const { data: res } = await this.ax.get<DataResponse<PaginatedNotificationsResponse>>(url);
226
+ return res;
227
+ }
236
228
 
237
- return res.data;
238
- }
229
+ /**
230
+ * Marca todas as notificações do usuário como lidas.
231
+ */
232
+ public async markAllAsReadNotification() {
233
+ const url = `/api/whatsapp/notifications/mark-all-read`;
234
+ const { data: res } = await this.ax.patch<MessageResponse>(url);
235
+ return res;
236
+ }
239
237
 
240
- /**
241
- * Obtém os detalhes de um agendamento.
242
- * @param filters - keys de WppSchedule.
243
- * @param userId/sectorId filtrar por usúario/setor
244
- * @returns Uma Promise que resolve para um array de objetos wppSchedule.
245
- */
246
- public async getSchedules(
247
- userId?: string,
248
- sectorId?: string,
249
- filters?: RequestFilters<WppSchedule>,
250
- ) {
251
- let baseUrl = `/api/whatsapp/schedules`;
252
- const params = new URLSearchParams(filters);
238
+ /**
239
+ * Marca uma notificação específica como lida.
240
+ * @param notificationId - O ID (numérico) da notificação a ser marcada.
241
+ */
242
+ public async markOneAsReadNotification(notificationId: number) {
243
+ const url = `/api/whatsapp/notifications/${notificationId}/read`;
244
+ const { data: res } = await this.ax.patch<DataResponse<AppNotification>>(url);
245
+ return res;
246
+ }
253
247
 
254
- if (params.toString()) {
255
- if (userId && sectorId) {
256
- baseUrl += `?userId=${userId}&sectorId=${sectorId}&${params.toString()}`;
257
- } else if (userId) {
258
- baseUrl += `?userId=${userId}&${params.toString()}`;
259
- } else if (sectorId) {
260
- baseUrl += `?sectorId=${sectorId}&${params.toString()}`;
261
- } else {
262
- baseUrl += `?${params.toString()}`;
263
- }
264
- } else if (userId || sectorId) {
265
- if (userId && sectorId) {
266
- baseUrl += `?userId=${userId}&sectorId=${sectorId}`;
267
- } else if (userId) {
268
- baseUrl += `?userId=${userId}`;
269
- } else if (sectorId) {
270
- baseUrl += `?sectorId=${sectorId}`;
271
- }
272
- }
248
+ /**
249
+ * Obtém os detalhes de um agendamento.
250
+ * @param filters - keys de WppSchedule.
251
+ * @param userId/sectorId filtrar por usúario/setor
252
+ * @returns Uma Promise que resolve para um array de objetos wppSchedule.
253
+ */
254
+ public async getSchedules(
255
+ userId?: string,
256
+ sectorId?: string,
257
+ filters?: RequestFilters<WppSchedule>,
258
+ ) {
259
+ let baseUrl = `/api/whatsapp/schedules`;
260
+ const params = new URLSearchParams(filters);
261
+ if (params.toString()) {
262
+ if (userId && sectorId) {
263
+ baseUrl += `?userId=${userId}&sectorId=${sectorId}&${params.toString()}`;
264
+ } else if (userId) {
265
+ baseUrl += `?userId=${userId}&${params.toString()}`;
266
+ } else if (sectorId) {
267
+ baseUrl += `?sectorId=${sectorId}&${params.toString()}`;
268
+ } else {
269
+ baseUrl += `?${params.toString()}`;
270
+ }
271
+ } else if (userId || sectorId) {
272
+ if (userId && sectorId) {
273
+ baseUrl += `?userId=${userId}&sectorId=${sectorId}`;
274
+ } else if (userId) {
275
+ baseUrl += `?userId=${userId}`;
276
+ } else if (sectorId) {
277
+ baseUrl += `?sectorId=${sectorId}`;
278
+ }
279
+ }
280
+ const response = await this.ax.get(baseUrl);
281
+ return response.data;
282
+ }
273
283
 
274
- const response = await this.ax.get(baseUrl);
275
- return response.data;
276
- }
284
+ /**
285
+ * Cria um novo agendamento.
286
+ * @param scheduleData - Os dados do agendamento, keys de wppSchedule.
287
+ * @returns Uma Promise que resolve para um objeto wppSchedule.
288
+ */
289
+ public async createSchedule(data: CreateScheduleDTO) {
290
+ const response = await this.ax.post(`/api/whatsapp/schedules`, data);
291
+ return response.data;
292
+ }
277
293
 
278
- /**
279
- * Cria um novo agendamento.
280
- * @param scheduleData - Os dados do agendamento, keys de wppSchedule.
281
- * @returns Uma Promise que resolve para um objeto wppSchedule.
282
- */
283
- public async createSchedule(data: CreateScheduleDTO) {
284
- const response = await this.ax.post(`/api/whatsapp/schedules`, data);
285
- return response.data;
286
- }
294
+ /**
295
+ * Edita um agendamento existente.
296
+ * @param scheduleId - O ID do agendamento a ser editado.
297
+ * @param updatedData - Os dados atualizados do agendamento.
298
+ * @returns Uma Promise que resolve para um objeto wppSchedule.
299
+ */
300
+ public async updateSchedule(
301
+ scheduleId: number,
302
+ updatedData: Record<string, WppSchedule>,
303
+ ) {
304
+ const response = await this.ax.patch(
305
+ `/api/whatsapp/schedules/${scheduleId}`,
306
+ updatedData,
307
+ );
308
+ return response.data;
309
+ }
287
310
 
288
- /**
289
- * Edita um agendamento existente.
290
- * @param scheduleId - O ID do agendamento a ser editado.
291
- * @param updatedData - Os dados atualizados do agendamento.
292
- * @returns Uma Promise que resolve para um objeto wppSchedule.
293
- */
294
- public async updateSchedule(
295
- scheduleId: number,
296
- updatedData: Record<string, WppSchedule>,
297
- ) {
298
- const response = await this.ax.patch(
299
- `/api/whatsapp/schedules/${scheduleId}`,
300
- updatedData,
301
- );
302
- return response.data;
303
- }
311
+ /**
312
+ * Exclui um agendamento.
313
+ * @param scheduleId - O ID do agendamento a ser excluído.
314
+ * @returns Uma Promise que resolve para um objeto wppSchedule.
315
+ */
316
+ public async deleteSchedule(scheduleId: number) {
317
+ const response = await this.ax.delete(
318
+ `/api/whatsapp/schedules/${scheduleId}`,
319
+ );
320
+ return response.data;
321
+ }
304
322
 
305
- /**
306
- * Exclui um agendamento.
307
- * @param scheduleId - O ID do agendamento a ser excluído.
308
- * @returns Uma Promise que resolve para um objeto wppSchedule.
309
- */
310
- public async deleteSchedule(scheduleId: number) {
311
- const response = await this.ax.delete(
312
- `/api/whatsapp/schedules/${scheduleId}`,
313
- );
314
- return response.data;
315
- }
316
- }
323
+ public async getMessages(token: string, filters: FetchMessagesFilters) {
324
+ const params = new URLSearchParams(
325
+ Object.entries(filters)
326
+ .filter(([_, v]) => v !== undefined && v !== null)
327
+ .reduce<Record<string, string>>((acc, [k, v]) => {
328
+ acc[k] = String(v);
329
+ return acc;
330
+ }, {}),
331
+ );
332
+ const url = `/api/whatsapp/messages?${params.toString()}`;
333
+ const { data: res } = await this.ax.get<
334
+ DataResponse<(WppMessage & { WppContact: WppContact | null })[]>
335
+ >(url, {
336
+ headers: {
337
+ Authorization: `Bearer ${token}`,
338
+ },
339
+ });
340
+ return res.data;
341
+ }
342
+ }