@in.pulse-crm/sdk 2.4.4 → 2.4.6
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 +37 -0
- package/package.json +1 -1
- package/src/customers.client.ts +3 -2
- package/src/types/response.types.ts +1 -1
- package/src/types/whatsapp.types.ts +13 -1
- package/src/whatsapp.client.ts +77 -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>;
|
|
@@ -8,9 +8,19 @@ export default class WhatsappClient extends ApiClient {
|
|
|
8
8
|
markContactMessagesAsRead(contactId: number): Promise<WppMessage[]>;
|
|
9
9
|
sendMessage(to: string, data: SendMessageData): Promise<WppMessage>;
|
|
10
10
|
finishChatById(id: number, resultId: number): Promise<void>;
|
|
11
|
+
startChatByContactId(contactId: number): Promise<WppChatWithDetailsAndMessages>;
|
|
11
12
|
getResults(): Promise<{
|
|
12
13
|
id: number;
|
|
13
14
|
name: string;
|
|
14
15
|
}[]>;
|
|
16
|
+
getCustomerContacts(customerId: number): Promise<WppContact[]>;
|
|
17
|
+
getContactsWithCustomer(): Promise<WppContactWithCustomer[]>;
|
|
18
|
+
createContact(name: string, phone: string, customerId: number): Promise<WppContact>;
|
|
19
|
+
updateContact(contactId: number, name: string): Promise<WppContact>;
|
|
20
|
+
deleteContact(contactId: number): Promise<void>;
|
|
21
|
+
getSectors(): Promise<{
|
|
22
|
+
id: number;
|
|
23
|
+
name: string;
|
|
24
|
+
}[]>;
|
|
15
25
|
setAuth(token: string): void;
|
|
16
26
|
}
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -58,11 +58,48 @@ class WhatsappClient extends api_client_1.default {
|
|
|
58
58
|
const body = { resultId };
|
|
59
59
|
await this.httpClient.post(url, body);
|
|
60
60
|
}
|
|
61
|
+
async startChatByContactId(contactId) {
|
|
62
|
+
const url = `/api/whatsapp/chats`;
|
|
63
|
+
const body = { contactId };
|
|
64
|
+
const { data: res } = await this.httpClient.post(url, body);
|
|
65
|
+
return res.data;
|
|
66
|
+
}
|
|
61
67
|
async getResults() {
|
|
62
68
|
const url = `/api/whatsapp/results`;
|
|
63
69
|
const { data: res } = await this.httpClient.get(url);
|
|
64
70
|
return res.data;
|
|
65
71
|
}
|
|
72
|
+
async getCustomerContacts(customerId) {
|
|
73
|
+
const url = `/api/whatsapp/customer/${customerId}/contacts`;
|
|
74
|
+
const { data: res } = await this.httpClient.get(url);
|
|
75
|
+
return res.data;
|
|
76
|
+
}
|
|
77
|
+
async getContactsWithCustomer() {
|
|
78
|
+
const url = `/api/whatsapp/contacts`;
|
|
79
|
+
const { data: res } = await this.httpClient.get(url);
|
|
80
|
+
return res.data;
|
|
81
|
+
}
|
|
82
|
+
async createContact(name, phone, customerId) {
|
|
83
|
+
const url = `/api/whatsapp/customers/${customerId}/contacts`;
|
|
84
|
+
const body = { name, phone };
|
|
85
|
+
const { data: res } = await this.httpClient.post(url, body);
|
|
86
|
+
return res.data;
|
|
87
|
+
}
|
|
88
|
+
async updateContact(contactId, name) {
|
|
89
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
90
|
+
const body = { name };
|
|
91
|
+
const { data: res } = await this.httpClient.put(url, body);
|
|
92
|
+
return res.data;
|
|
93
|
+
}
|
|
94
|
+
async deleteContact(contactId) {
|
|
95
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
96
|
+
await this.httpClient.delete(url);
|
|
97
|
+
}
|
|
98
|
+
async getSectors() {
|
|
99
|
+
const url = `/api/whatsapp/sectors`;
|
|
100
|
+
const { data: res } = await this.httpClient.get(url);
|
|
101
|
+
return res.data;
|
|
102
|
+
}
|
|
66
103
|
setAuth(token) {
|
|
67
104
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
68
105
|
`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,8 @@ class CustomersClient extends ApiClient {
|
|
|
59
59
|
baseUrl += `?${params.toString()}`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const response =
|
|
62
|
+
const response =
|
|
63
|
+
await this.httpClient.get<PaginatedResponse<Customer>>(baseUrl);
|
|
63
64
|
|
|
64
65
|
return response.data;
|
|
65
66
|
}
|
|
@@ -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
|
@@ -4,6 +4,8 @@ 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";
|
|
@@ -97,9 +99,83 @@ export default class WhatsappClient extends ApiClient {
|
|
|
97
99
|
await this.httpClient.post<MessageResponse>(url, body);
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
public async startChatByContactId(contactId: number) {
|
|
103
|
+
const url = `/api/whatsapp/chats`;
|
|
104
|
+
const body = { contactId };
|
|
105
|
+
|
|
106
|
+
const { data: res } = await this.httpClient.post<
|
|
107
|
+
DataResponse<WppChatWithDetailsAndMessages>
|
|
108
|
+
>(url, body);
|
|
109
|
+
|
|
110
|
+
return res.data;
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
public async getResults() {
|
|
101
114
|
const url = `/api/whatsapp/results`;
|
|
102
|
-
const { data: res } =
|
|
115
|
+
const { data: res } =
|
|
116
|
+
await this.httpClient.get<
|
|
117
|
+
DataResponse<{ id: number; name: string }[]>
|
|
118
|
+
>(url);
|
|
119
|
+
|
|
120
|
+
return res.data;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public async getCustomerContacts(customerId: number) {
|
|
124
|
+
const url = `/api/whatsapp/customer/${customerId}/contacts`;
|
|
125
|
+
const { data: res } =
|
|
126
|
+
await this.httpClient.get<DataResponse<WppContact[]>>(url);
|
|
127
|
+
|
|
128
|
+
return res.data;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public async getContactsWithCustomer() {
|
|
132
|
+
const url = `/api/whatsapp/contacts`;
|
|
133
|
+
const { data: res } =
|
|
134
|
+
await this.httpClient.get<DataResponse<WppContactWithCustomer[]>>(
|
|
135
|
+
url,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return res.data;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public async createContact(
|
|
142
|
+
name: string,
|
|
143
|
+
phone: string,
|
|
144
|
+
customerId: number,
|
|
145
|
+
) {
|
|
146
|
+
const url = `/api/whatsapp/customers/${customerId}/contacts`;
|
|
147
|
+
const body = { name, phone };
|
|
148
|
+
|
|
149
|
+
const { data: res } = await this.httpClient.post<
|
|
150
|
+
DataResponse<WppContact>
|
|
151
|
+
>(url, body);
|
|
152
|
+
|
|
153
|
+
return res.data;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public async updateContact(contactId: number, name: string) {
|
|
157
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
158
|
+
const body = { name };
|
|
159
|
+
|
|
160
|
+
const { data: res } = await this.httpClient.put<
|
|
161
|
+
DataResponse<WppContact>
|
|
162
|
+
>(url, body);
|
|
163
|
+
|
|
164
|
+
return res.data;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async deleteContact(contactId: number) {
|
|
168
|
+
const url = `/api/whatsapp/contacts/${contactId}`;
|
|
169
|
+
|
|
170
|
+
await this.httpClient.delete<MessageResponse>(url);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public async getSectors() {
|
|
174
|
+
const url = `/api/whatsapp/sectors`;
|
|
175
|
+
const { data: res } =
|
|
176
|
+
await this.httpClient.get<
|
|
177
|
+
DataResponse<{ id: number; name: string }[]>
|
|
178
|
+
>(url);
|
|
103
179
|
|
|
104
180
|
return res.data;
|
|
105
181
|
}
|