@in.pulse-crm/sdk 2.4.6 → 2.4.7
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.
|
@@ -8,6 +8,14 @@ export interface WppContact {
|
|
|
8
8
|
isBlocked: boolean;
|
|
9
9
|
isOnlyAdmin: boolean;
|
|
10
10
|
}
|
|
11
|
+
export interface WppSchedule {
|
|
12
|
+
id: number;
|
|
13
|
+
instance: string;
|
|
14
|
+
contactId: number;
|
|
15
|
+
scheduleDate: string;
|
|
16
|
+
scheduledBy: string;
|
|
17
|
+
scheduledFor: string;
|
|
18
|
+
}
|
|
11
19
|
export interface WppContactWithCustomer {
|
|
12
20
|
id: number;
|
|
13
21
|
name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
2
|
import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
3
3
|
export default class WhatsappClient extends ApiClient {
|
|
4
|
-
getChatsBySession(
|
|
4
|
+
getChatsBySession(messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
|
|
5
5
|
getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
|
|
6
6
|
getMessageById(id: string): Promise<WppMessage>;
|
|
7
7
|
getUserWallets(instance: string, userId: number): Promise<WppWallet[]>;
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -6,13 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const api_client_1 = __importDefault(require("./api-client"));
|
|
7
7
|
const form_data_1 = __importDefault(require("form-data"));
|
|
8
8
|
class WhatsappClient extends api_client_1.default {
|
|
9
|
-
async getChatsBySession(
|
|
9
|
+
async getChatsBySession(messages = false, contact = false) {
|
|
10
10
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Authorization: `Bearer ${token}`,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
11
|
+
console.log(this.httpClient.defaults.headers.common["Authorization"]);
|
|
12
|
+
const { data: res } = await this.httpClient.get(url);
|
|
16
13
|
return res.data;
|
|
17
14
|
}
|
|
18
15
|
async getChatById(id) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
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;
|
|
@@ -10,6 +10,15 @@ export interface WppContact {
|
|
|
10
10
|
isOnlyAdmin: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface WppSchedule {
|
|
14
|
+
id: number;
|
|
15
|
+
instance: string;
|
|
16
|
+
contactId: number;
|
|
17
|
+
scheduleDate: string;
|
|
18
|
+
scheduledBy: string;
|
|
19
|
+
scheduledFor: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
export interface WppContactWithCustomer {
|
|
14
23
|
id: number;
|
|
15
24
|
name: string;
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -18,17 +18,13 @@ type MarkChatAsReadResponse = DataResponse<WppMessage[]>;
|
|
|
18
18
|
|
|
19
19
|
export default class WhatsappClient extends ApiClient {
|
|
20
20
|
public async getChatsBySession(
|
|
21
|
-
token: string,
|
|
22
21
|
messages = false,
|
|
23
22
|
contact = false,
|
|
24
23
|
) {
|
|
25
24
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Authorization: `Bearer ${token}`,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
26
|
+
console.log(this.httpClient.defaults.headers.common["Authorization"]);
|
|
27
|
+
const { data: res } = await this.httpClient.get<GetChatsResponse>(url);
|
|
32
28
|
|
|
33
29
|
return res.data;
|
|
34
30
|
}
|