@in.pulse-crm/sdk 2.4.3 → 2.4.5
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/customers.client.d.ts +2 -2
- package/dist/types/response.types.d.ts +1 -1
- package/dist/types/whatsapp.types.d.ts +11 -0
- package/dist/whatsapp.client.d.ts +11 -1
- package/dist/whatsapp.client.js +36 -0
- package/package.json +1 -1
- package/src/customers.client.ts +2 -2
- package/src/types/response.types.ts +1 -1
- package/src/types/whatsapp.types.ts +13 -1
- package/src/whatsapp.client.ts +68 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { RequestFilters } from "./types";
|
|
2
|
+
import { PaginatedResponse, RequestFilters } from "./types";
|
|
3
3
|
import { CreateCustomerDTO, Customer, UpdateCustomerDTO } from "./types/customers.types";
|
|
4
4
|
declare class CustomersClient extends ApiClient {
|
|
5
5
|
/**
|
|
@@ -28,7 +28,7 @@ declare class CustomersClient extends ApiClient {
|
|
|
28
28
|
* @todo Implementar tipagem para os filtros.
|
|
29
29
|
* @returns Uma Promise que resolve para uma lista de clientes.
|
|
30
30
|
*/
|
|
31
|
-
getCustomers(filters?: RequestFilters<Customer>): Promise<
|
|
31
|
+
getCustomers(filters?: RequestFilters<Customer>): Promise<PaginatedResponse<Customer>>;
|
|
32
32
|
/**
|
|
33
33
|
* Define o token de autenticação para as requisições.
|
|
34
34
|
* @param token - O token de autenticação a ser definido.
|
|
@@ -8,6 +8,17 @@ export interface WppContact {
|
|
|
8
8
|
isBlocked: boolean;
|
|
9
9
|
isOnlyAdmin: boolean;
|
|
10
10
|
}
|
|
11
|
+
export interface WppContactWithCustomer {
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
phone: string;
|
|
15
|
+
customerId?: number;
|
|
16
|
+
instance: string;
|
|
17
|
+
isBlocked: boolean;
|
|
18
|
+
isOnlyAdmin: boolean;
|
|
19
|
+
customer: Customer | null;
|
|
20
|
+
chatingWith: string | null;
|
|
21
|
+
}
|
|
11
22
|
export interface WppMessage {
|
|
12
23
|
id: number;
|
|
13
24
|
instance: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
2
|
+
import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
3
3
|
export default class WhatsappClient extends ApiClient {
|
|
4
4
|
getChatsBySession(token: string, messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
|
|
5
5
|
getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
|
|
@@ -7,5 +7,15 @@ export default class WhatsappClient extends ApiClient {
|
|
|
7
7
|
getUserWallets(instance: string, userId: number): Promise<WppWallet[]>;
|
|
8
8
|
markContactMessagesAsRead(contactId: number): Promise<WppMessage[]>;
|
|
9
9
|
sendMessage(to: string, data: SendMessageData): Promise<WppMessage>;
|
|
10
|
+
finishChatById(id: number, resultId: number): Promise<void>;
|
|
11
|
+
getResults(): Promise<{
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
}[]>;
|
|
15
|
+
getCustomerContacts(customerId: number): Promise<WppContact[]>;
|
|
16
|
+
getContactsWithCustomer(): Promise<WppContactWithCustomer[]>;
|
|
17
|
+
createContact(name: string, phone: string, customerId: number): Promise<WppContact>;
|
|
18
|
+
updateContact(contactId: number, name: string): Promise<WppContact>;
|
|
19
|
+
deleteContact(contactId: number): Promise<void>;
|
|
10
20
|
setAuth(token: string): void;
|
|
11
21
|
}
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -53,6 +53,42 @@ class WhatsappClient extends api_client_1.default {
|
|
|
53
53
|
});
|
|
54
54
|
return res.data;
|
|
55
55
|
}
|
|
56
|
+
async finishChatById(id, resultId) {
|
|
57
|
+
const url = `/api/whatsapp/chats/${id}/finish`;
|
|
58
|
+
const body = { resultId };
|
|
59
|
+
await this.httpClient.post(url, body);
|
|
60
|
+
}
|
|
61
|
+
async getResults() {
|
|
62
|
+
const url = `/api/whatsapp/results`;
|
|
63
|
+
const { data: res } = await this.httpClient.get(url);
|
|
64
|
+
return res.data;
|
|
65
|
+
}
|
|
66
|
+
async getCustomerContacts(customerId) {
|
|
67
|
+
const url = `/api/whatsapp/customer/${customerId}/contacts`;
|
|
68
|
+
const { data: res } = await this.httpClient.get(url);
|
|
69
|
+
return res.data;
|
|
70
|
+
}
|
|
71
|
+
async getContactsWithCustomer() {
|
|
72
|
+
const url = `/api/whatsapp/contacts`;
|
|
73
|
+
const { data: res } = await this.httpClient.get(url);
|
|
74
|
+
return res.data;
|
|
75
|
+
}
|
|
76
|
+
async createContact(name, phone, customerId) {
|
|
77
|
+
const url = `/api/whatsapp/customers/${customerId}/contacts`;
|
|
78
|
+
const body = { name, phone };
|
|
79
|
+
const { data: res } = await this.httpClient.post(url, body);
|
|
80
|
+
return res.data;
|
|
81
|
+
}
|
|
82
|
+
async updateContact(contactId, name) {
|
|
83
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
84
|
+
const body = { name };
|
|
85
|
+
const { data: res } = await this.httpClient.put(url, body);
|
|
86
|
+
return res.data;
|
|
87
|
+
}
|
|
88
|
+
async deleteContact(contactId) {
|
|
89
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
90
|
+
await this.httpClient.delete(url);
|
|
91
|
+
}
|
|
56
92
|
setAuth(token) {
|
|
57
93
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
58
94
|
`Bearer ${token}`;
|
package/package.json
CHANGED
package/src/customers.client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { RequestFilters } from "./types";
|
|
2
|
+
import { PaginatedResponse, RequestFilters } from "./types";
|
|
3
3
|
import {
|
|
4
4
|
CreateCustomerDTO,
|
|
5
5
|
Customer,
|
|
@@ -59,7 +59,7 @@ class CustomersClient extends ApiClient {
|
|
|
59
59
|
baseUrl += `?${params.toString()}`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const response = await this.httpClient.get(baseUrl);
|
|
62
|
+
const response = await this.httpClient.get<PaginatedResponse<Customer>>(baseUrl);
|
|
63
63
|
|
|
64
64
|
return response.data;
|
|
65
65
|
}
|
|
@@ -10,6 +10,18 @@ export interface WppContact {
|
|
|
10
10
|
isOnlyAdmin: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface WppContactWithCustomer {
|
|
14
|
+
id: number;
|
|
15
|
+
name: string;
|
|
16
|
+
phone: string;
|
|
17
|
+
customerId?: number;
|
|
18
|
+
instance: string;
|
|
19
|
+
isBlocked: boolean;
|
|
20
|
+
isOnlyAdmin: boolean;
|
|
21
|
+
customer: Customer | null;
|
|
22
|
+
chatingWith: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
export interface WppMessage {
|
|
14
26
|
id: number;
|
|
15
27
|
instance: string;
|
|
@@ -58,7 +70,7 @@ export interface WppWallet {
|
|
|
58
70
|
instance: string;
|
|
59
71
|
id: number;
|
|
60
72
|
name: string;
|
|
61
|
-
userIds: number[]
|
|
73
|
+
userIds: number[];
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
// Enums
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { DataResponse } from "./types/response.types";
|
|
2
|
+
import { DataResponse, MessageResponse } from "./types/response.types";
|
|
3
3
|
import {
|
|
4
4
|
SendMessageData,
|
|
5
5
|
WppChatsAndMessages,
|
|
6
6
|
WppChatWithDetailsAndMessages,
|
|
7
|
+
WppContact,
|
|
8
|
+
WppContactWithCustomer,
|
|
7
9
|
WppMessage,
|
|
8
10
|
WppWallet,
|
|
9
11
|
} from "./types/whatsapp.types";
|
|
@@ -90,6 +92,71 @@ export default class WhatsappClient extends ApiClient {
|
|
|
90
92
|
return res.data;
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
public async finishChatById(id: number, resultId: number) {
|
|
96
|
+
const url = `/api/whatsapp/chats/${id}/finish`;
|
|
97
|
+
const body = { resultId };
|
|
98
|
+
|
|
99
|
+
await this.httpClient.post<MessageResponse>(url, body);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async getResults() {
|
|
103
|
+
const url = `/api/whatsapp/results`;
|
|
104
|
+
const { data: res } =
|
|
105
|
+
await this.httpClient.get<
|
|
106
|
+
DataResponse<{ id: number; name: string }[]>
|
|
107
|
+
>(url);
|
|
108
|
+
|
|
109
|
+
return res.data;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public async getCustomerContacts(customerId: number) {
|
|
113
|
+
const url = `/api/whatsapp/customer/${customerId}/contacts`;
|
|
114
|
+
const { data: res } =
|
|
115
|
+
await this.httpClient.get<DataResponse<WppContact[]>>(url);
|
|
116
|
+
|
|
117
|
+
return res.data;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public async getContactsWithCustomer() {
|
|
121
|
+
const url = `/api/whatsapp/contacts`;
|
|
122
|
+
const { data: res } =
|
|
123
|
+
await this.httpClient.get<DataResponse<WppContactWithCustomer[]>>(url);
|
|
124
|
+
|
|
125
|
+
return res.data;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public async createContact(
|
|
129
|
+
name: string,
|
|
130
|
+
phone: string,
|
|
131
|
+
customerId: number,
|
|
132
|
+
) {
|
|
133
|
+
const url = `/api/whatsapp/customers/${customerId}/contacts`;
|
|
134
|
+
const body = { name, phone };
|
|
135
|
+
|
|
136
|
+
const { data: res } = await this.httpClient.post<
|
|
137
|
+
DataResponse<WppContact>
|
|
138
|
+
>(url, body);
|
|
139
|
+
|
|
140
|
+
return res.data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public async updateContact(contactId: number, name: string) {
|
|
144
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
145
|
+
const body = { name };
|
|
146
|
+
|
|
147
|
+
const { data: res } = await this.httpClient.put<
|
|
148
|
+
DataResponse<WppContact>
|
|
149
|
+
>(url, body);
|
|
150
|
+
|
|
151
|
+
return res.data;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public async deleteContact(contactId: number) {
|
|
155
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
156
|
+
|
|
157
|
+
await this.httpClient.delete<MessageResponse>(url);
|
|
158
|
+
}
|
|
159
|
+
|
|
93
160
|
public setAuth(token: string) {
|
|
94
161
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
95
162
|
`Bearer ${token}`;
|