@in.pulse-crm/sdk 2.4.5 → 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,13 +1,14 @@
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(token: string, messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
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[]>;
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;
@@ -17,5 +18,9 @@ export default class WhatsappClient extends ApiClient {
17
18
  createContact(name: string, phone: string, customerId: number): Promise<WppContact>;
18
19
  updateContact(contactId: number, name: string): Promise<WppContact>;
19
20
  deleteContact(contactId: number): Promise<void>;
21
+ getSectors(): Promise<{
22
+ id: number;
23
+ name: string;
24
+ }[]>;
20
25
  setAuth(token: string): void;
21
26
  }
@@ -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(token, messages = false, contact = false) {
9
+ async getChatsBySession(messages = false, contact = false) {
10
10
  const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
11
- const { data: res } = await this.httpClient.get(url, {
12
- headers: {
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) {
@@ -58,6 +55,12 @@ class WhatsappClient extends api_client_1.default {
58
55
  const body = { resultId };
59
56
  await this.httpClient.post(url, body);
60
57
  }
58
+ async startChatByContactId(contactId) {
59
+ const url = `/api/whatsapp/chats`;
60
+ const body = { contactId };
61
+ const { data: res } = await this.httpClient.post(url, body);
62
+ return res.data;
63
+ }
61
64
  async getResults() {
62
65
  const url = `/api/whatsapp/results`;
63
66
  const { data: res } = await this.httpClient.get(url);
@@ -89,6 +92,11 @@ class WhatsappClient extends api_client_1.default {
89
92
  const url = `/api/whatsapp/contacts/${contactId}`;
90
93
  await this.httpClient.delete(url);
91
94
  }
95
+ async getSectors() {
96
+ const url = `/api/whatsapp/sectors`;
97
+ const { data: res } = await this.httpClient.get(url);
98
+ return res.data;
99
+ }
92
100
  setAuth(token) {
93
101
  this.httpClient.defaults.headers.common["Authorization"] =
94
102
  `Bearer ${token}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.4.5",
3
+ "version": "2.4.7",
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",
@@ -59,7 +59,8 @@ class CustomersClient extends ApiClient {
59
59
  baseUrl += `?${params.toString()}`;
60
60
  }
61
61
 
62
- const response = await this.httpClient.get<PaginatedResponse<Customer>>(baseUrl);
62
+ const response =
63
+ await this.httpClient.get<PaginatedResponse<Customer>>(baseUrl);
63
64
 
64
65
  return response.data;
65
66
  }
@@ -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}&sectorId=${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}&sectorId=${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;
@@ -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
- const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
28
- headers: {
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
  }
@@ -99,6 +95,17 @@ export default class WhatsappClient extends ApiClient {
99
95
  await this.httpClient.post<MessageResponse>(url, body);
100
96
  }
101
97
 
98
+ public async startChatByContactId(contactId: number) {
99
+ const url = `/api/whatsapp/chats`;
100
+ const body = { contactId };
101
+
102
+ const { data: res } = await this.httpClient.post<
103
+ DataResponse<WppChatWithDetailsAndMessages>
104
+ >(url, body);
105
+
106
+ return res.data;
107
+ }
108
+
102
109
  public async getResults() {
103
110
  const url = `/api/whatsapp/results`;
104
111
  const { data: res } =
@@ -120,7 +127,9 @@ export default class WhatsappClient extends ApiClient {
120
127
  public async getContactsWithCustomer() {
121
128
  const url = `/api/whatsapp/contacts`;
122
129
  const { data: res } =
123
- await this.httpClient.get<DataResponse<WppContactWithCustomer[]>>(url);
130
+ await this.httpClient.get<DataResponse<WppContactWithCustomer[]>>(
131
+ url,
132
+ );
124
133
 
125
134
  return res.data;
126
135
  }
@@ -157,6 +166,16 @@ export default class WhatsappClient extends ApiClient {
157
166
  await this.httpClient.delete<MessageResponse>(url);
158
167
  }
159
168
 
169
+ public async getSectors() {
170
+ const url = `/api/whatsapp/sectors`;
171
+ const { data: res } =
172
+ await this.httpClient.get<
173
+ DataResponse<{ id: number; name: string }[]>
174
+ >(url);
175
+
176
+ return res.data;
177
+ }
178
+
160
179
  public setAuth(token: string) {
161
180
  this.httpClient.defaults.headers.common["Authorization"] =
162
181
  `Bearer ${token}`;