@in.pulse-crm/sdk 2.6.0 → 2.6.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.
- package/dist/types/whatsapp.types.d.ts +17 -0
- package/dist/whatsapp.client.d.ts +28 -1
- package/dist/whatsapp.client.js +65 -0
- package/package.json +1 -1
- package/src/types/whatsapp.types.ts +29 -10
- package/src/whatsapp.client.ts +88 -5
- package/src/schedules.client.ts +0 -100
|
@@ -120,3 +120,20 @@ export interface MonitorChat {
|
|
|
120
120
|
endDate: string;
|
|
121
121
|
result: string;
|
|
122
122
|
}
|
|
123
|
+
export interface CreateScheduleDTO {
|
|
124
|
+
contactId: number;
|
|
125
|
+
date: Date;
|
|
126
|
+
scheduledFor: number;
|
|
127
|
+
sectorId: number;
|
|
128
|
+
}
|
|
129
|
+
export interface Schedule {
|
|
130
|
+
id: number;
|
|
131
|
+
instance: string;
|
|
132
|
+
sectorId: number;
|
|
133
|
+
description: string | null;
|
|
134
|
+
contactId: number;
|
|
135
|
+
scheduleDate: string;
|
|
136
|
+
scheduledBy: number;
|
|
137
|
+
scheduledFor: number;
|
|
138
|
+
contact: WppContact;
|
|
139
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import {
|
|
2
|
+
import { RequestFilters } from "./types";
|
|
3
|
+
import { CreateScheduleDTO, MonitorChat, SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppSchedule, WppWallet } from "./types/whatsapp.types";
|
|
3
4
|
export default class WhatsappClient extends ApiClient {
|
|
4
5
|
getChatsBySession(messages?: boolean, contact?: boolean, token?: string | null): Promise<WppChatsAndMessages>;
|
|
5
6
|
getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
|
|
@@ -25,4 +26,30 @@ export default class WhatsappClient extends ApiClient {
|
|
|
25
26
|
setAuth(token: string): void;
|
|
26
27
|
getChatsMonitor(): Promise<MonitorChat[]>;
|
|
27
28
|
transferAttendance(id: number, userId: number): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Obtém os detalhes de um agendamento.
|
|
31
|
+
* @param filters - keys de WppSchedule.
|
|
32
|
+
* @param userId/sectorId filtrar por usúario/setor
|
|
33
|
+
* @returns Uma Promise que resolve para um array de objetos wppSchedule.
|
|
34
|
+
*/
|
|
35
|
+
getSchedules(userId?: string, sectorId?: string, filters?: RequestFilters<WppSchedule>): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* Cria um novo agendamento.
|
|
38
|
+
* @param scheduleData - Os dados do agendamento, keys de wppSchedule.
|
|
39
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
40
|
+
*/
|
|
41
|
+
createSchedule(data: CreateScheduleDTO): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Edita um agendamento existente.
|
|
44
|
+
* @param scheduleId - O ID do agendamento a ser editado.
|
|
45
|
+
* @param updatedData - Os dados atualizados do agendamento.
|
|
46
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
47
|
+
*/
|
|
48
|
+
updateSchedule(scheduleId: number, updatedData: Record<string, WppSchedule>): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Exclui um agendamento.
|
|
51
|
+
* @param scheduleId - O ID do agendamento a ser excluído.
|
|
52
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
53
|
+
*/
|
|
54
|
+
deleteSchedule(scheduleId: number): Promise<any>;
|
|
28
55
|
}
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -115,5 +115,70 @@ class WhatsappClient extends api_client_1.default {
|
|
|
115
115
|
const body = { userId };
|
|
116
116
|
await this.httpClient.post(url, body);
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Obtém os detalhes de um agendamento.
|
|
120
|
+
* @param filters - keys de WppSchedule.
|
|
121
|
+
* @param userId/sectorId filtrar por usúario/setor
|
|
122
|
+
* @returns Uma Promise que resolve para um array de objetos wppSchedule.
|
|
123
|
+
*/
|
|
124
|
+
async getSchedules(userId, sectorId, filters) {
|
|
125
|
+
let baseUrl = `/api/whatsapp/schedules`;
|
|
126
|
+
const params = new URLSearchParams(filters);
|
|
127
|
+
if (params.toString()) {
|
|
128
|
+
if (userId && sectorId) {
|
|
129
|
+
baseUrl += `?userId=${userId}§orId=${sectorId}&${params.toString()}`;
|
|
130
|
+
}
|
|
131
|
+
else if (userId) {
|
|
132
|
+
baseUrl += `?userId=${userId}&${params.toString()}`;
|
|
133
|
+
}
|
|
134
|
+
else if (sectorId) {
|
|
135
|
+
baseUrl += `?sectorId=${sectorId}&${params.toString()}`;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
baseUrl += `?${params.toString()}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (userId || sectorId) {
|
|
142
|
+
if (userId && sectorId) {
|
|
143
|
+
baseUrl += `?userId=${userId}§orId=${sectorId}`;
|
|
144
|
+
}
|
|
145
|
+
else if (userId) {
|
|
146
|
+
baseUrl += `?userId=${userId}`;
|
|
147
|
+
}
|
|
148
|
+
else if (sectorId) {
|
|
149
|
+
baseUrl += `?sectorId=${sectorId}`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const response = await this.httpClient.get(baseUrl);
|
|
153
|
+
return response.data;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Cria um novo agendamento.
|
|
157
|
+
* @param scheduleData - Os dados do agendamento, keys de wppSchedule.
|
|
158
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
159
|
+
*/
|
|
160
|
+
async createSchedule(data) {
|
|
161
|
+
const response = await this.httpClient.post(`/api/whatsapp/schedules`, data);
|
|
162
|
+
return response.data;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Edita um agendamento existente.
|
|
166
|
+
* @param scheduleId - O ID do agendamento a ser editado.
|
|
167
|
+
* @param updatedData - Os dados atualizados do agendamento.
|
|
168
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
169
|
+
*/
|
|
170
|
+
async updateSchedule(scheduleId, updatedData) {
|
|
171
|
+
const response = await this.httpClient.patch(`/api/whatsapp/schedules/${scheduleId}`, updatedData);
|
|
172
|
+
return response.data;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Exclui um agendamento.
|
|
176
|
+
* @param scheduleId - O ID do agendamento a ser excluído.
|
|
177
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
178
|
+
*/
|
|
179
|
+
async deleteSchedule(scheduleId) {
|
|
180
|
+
const response = await this.httpClient.delete(`/api/whatsapp/schedules/${scheduleId}`);
|
|
181
|
+
return response.data;
|
|
182
|
+
}
|
|
118
183
|
}
|
|
119
184
|
exports.default = WhatsappClient;
|
package/package.json
CHANGED
|
@@ -129,14 +129,33 @@ export interface SendMessageData {
|
|
|
129
129
|
fileId?: number;
|
|
130
130
|
}
|
|
131
131
|
export interface MonitorChat {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
id: string;
|
|
133
|
+
erpCode: string;
|
|
134
|
+
companyName: string;
|
|
135
|
+
contactName: string;
|
|
136
|
+
whatsappNumber: string;
|
|
137
|
+
sectorName: string;
|
|
138
|
+
attendantName: string;
|
|
139
|
+
startDate: string;
|
|
140
|
+
endDate: string;
|
|
141
|
+
result: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface CreateScheduleDTO {
|
|
145
|
+
contactId: number;
|
|
146
|
+
date: Date;
|
|
147
|
+
scheduledFor: number;
|
|
148
|
+
sectorId: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface Schedule {
|
|
152
|
+
id: number;
|
|
153
|
+
instance: string;
|
|
154
|
+
sectorId: number;
|
|
155
|
+
description: string | null;
|
|
156
|
+
contactId: number;
|
|
157
|
+
scheduleDate: string;
|
|
158
|
+
scheduledBy: number;
|
|
159
|
+
scheduledFor: number;
|
|
160
|
+
contact: WppContact;
|
|
142
161
|
}
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
+
import { RequestFilters } from "./types";
|
|
2
3
|
import { DataResponse, MessageResponse } from "./types/response.types";
|
|
3
4
|
import {
|
|
5
|
+
CreateScheduleDTO,
|
|
4
6
|
MonitorChat,
|
|
5
7
|
SendMessageData,
|
|
6
8
|
WppChatsAndMessages,
|
|
@@ -8,6 +10,7 @@ import {
|
|
|
8
10
|
WppContact,
|
|
9
11
|
WppContactWithCustomer,
|
|
10
12
|
WppMessage,
|
|
13
|
+
WppSchedule,
|
|
11
14
|
WppWallet,
|
|
12
15
|
} from "./types/whatsapp.types";
|
|
13
16
|
import FormData from "form-data";
|
|
@@ -28,7 +31,7 @@ export default class WhatsappClient extends ApiClient {
|
|
|
28
31
|
? { Authorization: `Bearer ${token}` }
|
|
29
32
|
: undefined;
|
|
30
33
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
31
|
-
|
|
34
|
+
|
|
32
35
|
const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
|
|
33
36
|
headers,
|
|
34
37
|
});
|
|
@@ -187,11 +190,11 @@ export default class WhatsappClient extends ApiClient {
|
|
|
187
190
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
188
191
|
`Bearer ${token}`;
|
|
189
192
|
}
|
|
190
|
-
public async getChatsMonitor(
|
|
191
|
-
) {
|
|
193
|
+
public async getChatsMonitor() {
|
|
192
194
|
const url = `/api/whatsapp/session/monitor`;
|
|
193
|
-
|
|
194
|
-
const { data: res } =
|
|
195
|
+
|
|
196
|
+
const { data: res } =
|
|
197
|
+
await this.httpClient.get<GetMonitorChatsResponse>(url);
|
|
195
198
|
|
|
196
199
|
return res.data;
|
|
197
200
|
}
|
|
@@ -201,4 +204,84 @@ export default class WhatsappClient extends ApiClient {
|
|
|
201
204
|
|
|
202
205
|
await this.httpClient.post<MessageResponse>(url, body);
|
|
203
206
|
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Obtém os detalhes de um agendamento.
|
|
210
|
+
* @param filters - keys de WppSchedule.
|
|
211
|
+
* @param userId/sectorId filtrar por usúario/setor
|
|
212
|
+
* @returns Uma Promise que resolve para um array de objetos wppSchedule.
|
|
213
|
+
*/
|
|
214
|
+
public async getSchedules(
|
|
215
|
+
userId?: string,
|
|
216
|
+
sectorId?: string,
|
|
217
|
+
filters?: RequestFilters<WppSchedule>,
|
|
218
|
+
) {
|
|
219
|
+
let baseUrl = `/api/whatsapp/schedules`;
|
|
220
|
+
const params = new URLSearchParams(filters);
|
|
221
|
+
|
|
222
|
+
if (params.toString()) {
|
|
223
|
+
if (userId && sectorId) {
|
|
224
|
+
baseUrl += `?userId=${userId}§orId=${sectorId}&${params.toString()}`;
|
|
225
|
+
} else if (userId) {
|
|
226
|
+
baseUrl += `?userId=${userId}&${params.toString()}`;
|
|
227
|
+
} else if (sectorId) {
|
|
228
|
+
baseUrl += `?sectorId=${sectorId}&${params.toString()}`;
|
|
229
|
+
} else {
|
|
230
|
+
baseUrl += `?${params.toString()}`;
|
|
231
|
+
}
|
|
232
|
+
} else if (userId || sectorId) {
|
|
233
|
+
if (userId && sectorId) {
|
|
234
|
+
baseUrl += `?userId=${userId}§orId=${sectorId}`;
|
|
235
|
+
} else if (userId) {
|
|
236
|
+
baseUrl += `?userId=${userId}`;
|
|
237
|
+
} else if (sectorId) {
|
|
238
|
+
baseUrl += `?sectorId=${sectorId}`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const response = await this.httpClient.get(baseUrl);
|
|
243
|
+
return response.data;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Cria um novo agendamento.
|
|
248
|
+
* @param scheduleData - Os dados do agendamento, keys de wppSchedule.
|
|
249
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
250
|
+
*/
|
|
251
|
+
public async createSchedule(data: CreateScheduleDTO) {
|
|
252
|
+
const response = await this.httpClient.post(
|
|
253
|
+
`/api/whatsapp/schedules`,
|
|
254
|
+
data,
|
|
255
|
+
);
|
|
256
|
+
return response.data;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Edita um agendamento existente.
|
|
261
|
+
* @param scheduleId - O ID do agendamento a ser editado.
|
|
262
|
+
* @param updatedData - Os dados atualizados do agendamento.
|
|
263
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
264
|
+
*/
|
|
265
|
+
public async updateSchedule(
|
|
266
|
+
scheduleId: number,
|
|
267
|
+
updatedData: Record<string, WppSchedule>,
|
|
268
|
+
) {
|
|
269
|
+
const response = await this.httpClient.patch(
|
|
270
|
+
`/api/whatsapp/schedules/${scheduleId}`,
|
|
271
|
+
updatedData,
|
|
272
|
+
);
|
|
273
|
+
return response.data;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Exclui um agendamento.
|
|
278
|
+
* @param scheduleId - O ID do agendamento a ser excluído.
|
|
279
|
+
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
280
|
+
*/
|
|
281
|
+
public async deleteSchedule(scheduleId: number) {
|
|
282
|
+
const response = await this.httpClient.delete(
|
|
283
|
+
`/api/whatsapp/schedules/${scheduleId}`,
|
|
284
|
+
);
|
|
285
|
+
return response.data;
|
|
286
|
+
}
|
|
204
287
|
}
|
package/src/schedules.client.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import ApiClient from "./api-client";
|
|
2
|
-
import { RequestFilters, WppSchedule } from "./types";
|
|
3
|
-
import {} from "./types/customers.types";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Cliente para interação com a API de agendamento de clientes do WhatsApp.
|
|
7
|
-
* Extende a classe ApiClient para fornecer métodos específicos para operações relacionadas a clientes.
|
|
8
|
-
*/
|
|
9
|
-
class WhatsappSchedules extends ApiClient {
|
|
10
|
-
/**
|
|
11
|
-
* Obtém os detalhes de um agendamento.
|
|
12
|
-
* @param filters - keys de WppSchedule.
|
|
13
|
-
* @param userId/sectorId filtrar por usúario/setor
|
|
14
|
-
* @returns Uma Promise que resolve para um array de objetos wppSchedule.
|
|
15
|
-
*/
|
|
16
|
-
public async getWppSchedules(
|
|
17
|
-
userId?: string,
|
|
18
|
-
sectorId?: string,
|
|
19
|
-
filters?: RequestFilters<WppSchedule>,
|
|
20
|
-
) {
|
|
21
|
-
let baseUrl = `/api/whatsapp/schedules`;
|
|
22
|
-
const params = new URLSearchParams(filters);
|
|
23
|
-
|
|
24
|
-
if (params.toString()) {
|
|
25
|
-
if (userId && sectorId) {
|
|
26
|
-
baseUrl += `?userId=${userId}§orId=${sectorId}&${params.toString()}`;
|
|
27
|
-
} else if (userId) {
|
|
28
|
-
baseUrl += `?userId=${userId}&${params.toString()}`;
|
|
29
|
-
} else if (sectorId) {
|
|
30
|
-
baseUrl += `?sectorId=${sectorId}&${params.toString()}`;
|
|
31
|
-
} else {
|
|
32
|
-
baseUrl += `?${params.toString()}`;
|
|
33
|
-
}
|
|
34
|
-
} else if (userId || sectorId) {
|
|
35
|
-
if (userId && sectorId) {
|
|
36
|
-
baseUrl += `?userId=${userId}§orId=${sectorId}`;
|
|
37
|
-
} else if (userId) {
|
|
38
|
-
baseUrl += `?userId=${userId}`;
|
|
39
|
-
} else if (sectorId) {
|
|
40
|
-
baseUrl += `?sectorId=${sectorId}`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const response = await this.httpClient.get(baseUrl);
|
|
45
|
-
return response.data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Cria um novo agendamento.
|
|
50
|
-
* @param scheduleData - Os dados do agendamento, keys de wppSchedule.
|
|
51
|
-
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
52
|
-
*/
|
|
53
|
-
public async createWppSchedules(scheduleData: Record<string, any>) {
|
|
54
|
-
const response = await this.httpClient.post(
|
|
55
|
-
`/api/whatsapp/schedules`,
|
|
56
|
-
scheduleData,
|
|
57
|
-
);
|
|
58
|
-
return response.data;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Edita um agendamento existente.
|
|
63
|
-
* @param scheduleId - O ID do agendamento a ser editado.
|
|
64
|
-
* @param updatedData - Os dados atualizados do agendamento.
|
|
65
|
-
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
66
|
-
*/
|
|
67
|
-
public async editWppSchedules(
|
|
68
|
-
scheduleId: number,
|
|
69
|
-
updatedData: Record<string, WppSchedule>,
|
|
70
|
-
) {
|
|
71
|
-
const response = await this.httpClient.patch(
|
|
72
|
-
`/api/whatsapp/schedules/${scheduleId}`,
|
|
73
|
-
updatedData,
|
|
74
|
-
);
|
|
75
|
-
return response.data;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Exclui um agendamento.
|
|
80
|
-
* @param scheduleId - O ID do agendamento a ser excluído.
|
|
81
|
-
* @returns Uma Promise que resolve para um objeto wppSchedule.
|
|
82
|
-
*/
|
|
83
|
-
public async deleteWppSchedules(scheduleId: number) {
|
|
84
|
-
const response = await this.httpClient.delete(
|
|
85
|
-
`/api/whatsapp/schedules/${scheduleId}`,
|
|
86
|
-
);
|
|
87
|
-
return response.data;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Define o token de autenticação para as requisições.
|
|
92
|
-
* @param token - O token de autenticação a ser definido.
|
|
93
|
-
*/
|
|
94
|
-
public setAuth(token: string) {
|
|
95
|
-
this.httpClient.defaults.headers.common["Authorization"] =
|
|
96
|
-
`Bearer ${token}`;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default WhatsappSchedules;
|