@in.pulse-crm/sdk 2.13.0 → 2.14.0

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.
@@ -70,6 +70,7 @@ export interface WppMessage {
70
70
  sentAt: Date;
71
71
  userId: number | null;
72
72
  billingCategory: string | null;
73
+ clientId: number | null;
73
74
  }
74
75
  export interface ForwardMessagesData {
75
76
  sourceType: "whatsapp" | "internal";
@@ -13,9 +13,9 @@ export default class WhatsappClient extends ApiClient {
13
13
  getMessageById(id: string): Promise<WppMessage>;
14
14
  getUserWallets(instance: string, userId: number): Promise<WppWallet[]>;
15
15
  markContactMessagesAsRead(contactId: number): Promise<WppMessage[]>;
16
- sendMessage(to: string, data: SendMessageData): Promise<WppMessage>;
17
- editMessage(messageId: string, newText: string, isInternal?: boolean): Promise<void>;
18
- finishChatById(id: number, resultId: number, triggerSatisfactionBot?: boolean): Promise<void>;
16
+ sendMessage(clientId: string, to: string, data: SendMessageData): Promise<WppMessage>;
17
+ editMessage(clientId: string, messageId: string, newText: string, isInternal?: boolean): Promise<void>;
18
+ finishChatById(id: number, resultId: number, scheduleDate?: Date | null): Promise<void>;
19
19
  startChatByContactId(contactId: number, template?: any): Promise<void>;
20
20
  getResults(): Promise<{
21
21
  id: number;
@@ -35,7 +35,7 @@ export default class WhatsappClient extends ApiClient {
35
35
  }): Promise<PaginatedContactsResponse>;
36
36
  getContacts(): Promise<WppContact[]>;
37
37
  createContact(name: string, phone: string, customerId?: number, sectorIds?: number[]): Promise<WppContact>;
38
- forwardMessages(data: ForwardMessagesData): Promise<void>;
38
+ forwardMessages(clientId: string, data: ForwardMessagesData): Promise<void>;
39
39
  updateContact(contactId: number, name?: string, customerId?: number | null, sectorIds?: number[] | null): Promise<WppContact>;
40
40
  addSectorToContact(contactId: number, sectorId: number): Promise<WppContact>;
41
41
  deleteContact(contactId: number): Promise<void>;
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const api_client_1 = __importDefault(require("./api-client"));
7
6
  const form_data_1 = __importDefault(require("form-data"));
7
+ const api_client_1 = __importDefault(require("./api-client"));
8
8
  class WhatsappClient extends api_client_1.default {
9
9
  async getChatsBySession(messages = false, contact = false, token = null) {
10
10
  const headers = token
@@ -29,13 +29,13 @@ class WhatsappClient extends api_client_1.default {
29
29
  return res.data;
30
30
  }
31
31
  async markContactMessagesAsRead(contactId) {
32
- const url = "/api/whatsapp/messages/mark-as-read";
32
+ const url = `/api/whatsapp/messages/mark-as-read`;
33
33
  const body = { contactId };
34
34
  const { data: res } = await this.ax.patch(url, body);
35
35
  return res.data;
36
36
  }
37
- async sendMessage(to, data) {
38
- const url = "/api/whatsapp/messages";
37
+ async sendMessage(clientId, to, data) {
38
+ const url = `/api/whatsapp/${clientId}/messages`;
39
39
  const formData = new form_data_1.default();
40
40
  formData.append("to", to);
41
41
  data.text && formData.append("text", data.text);
@@ -55,15 +55,15 @@ class WhatsappClient extends api_client_1.default {
55
55
  });
56
56
  return res.data;
57
57
  }
58
- async editMessage(messageId, newText, isInternal = false) {
58
+ async editMessage(clientId, messageId, newText, isInternal = false) {
59
59
  const type = isInternal ? "internal" : "whatsapp";
60
- const url = `/api/${type}/messages/${messageId}`;
60
+ const url = `/api/${type}/${clientId}/messages/${messageId}`;
61
61
  const body = { newText };
62
62
  await this.ax.put(url, body);
63
63
  }
64
- async finishChatById(id, resultId, triggerSatisfactionBot = false) {
64
+ async finishChatById(id, resultId, scheduleDate) {
65
65
  const url = `/api/whatsapp/chats/${id}/finish`;
66
- const body = { resultId, triggerSatisfactionBot };
66
+ const body = { resultId, scheduleDate };
67
67
  await this.ax.post(url, body);
68
68
  }
69
69
  async startChatByContactId(contactId, template) {
@@ -122,12 +122,12 @@ class WhatsappClient extends api_client_1.default {
122
122
  : `${baseUrl}/contacts`;
123
123
  const body = { name, phone };
124
124
  if (sectorIds !== undefined)
125
- body['sectorIds'] = sectorIds;
125
+ body["sectorIds"] = sectorIds;
126
126
  const { data: res } = await this.ax.post(url, body);
127
127
  return res.data;
128
128
  }
129
- async forwardMessages(data) {
130
- const url = "/api/whatsapp/messages/forward";
129
+ async forwardMessages(clientId, data) {
130
+ const url = `/api/whatsapp/${clientId}/messages/forward`;
131
131
  const body = data;
132
132
  await this.ax.post(url, body);
133
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
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",
@@ -72,6 +72,7 @@ export interface WppMessage {
72
72
  sentAt: Date;
73
73
  userId: number | null;
74
74
  billingCategory: string | null;
75
+ clientId: number | null;
75
76
  }
76
77
  export interface ForwardMessagesData {
77
78
  sourceType: "whatsapp" | "internal";
@@ -1,3 +1,4 @@
1
+ import FormData from "form-data";
1
2
  import ApiClient from "./api-client";
2
3
  import { RequestFilters } from "./types";
3
4
  import { DataResponse, MessageResponse } from "./types/response.types";
@@ -17,7 +18,6 @@ import {
17
18
  WppSchedule,
18
19
  WppWallet,
19
20
  } from "./types/whatsapp.types";
20
- import FormData from "form-data";
21
21
 
22
22
  type GetChatsResponse = DataResponse<WppChatsAndMessages>;
23
23
  type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
@@ -68,7 +68,7 @@ export default class WhatsappClient extends ApiClient {
68
68
  }
69
69
 
70
70
  public async markContactMessagesAsRead(contactId: number) {
71
- const url = "/api/whatsapp/messages/mark-as-read";
71
+ const url = `/api/whatsapp/messages/mark-as-read`;
72
72
  const body = { contactId };
73
73
  const { data: res } = await this.ax.patch<MarkChatAsReadResponse>(
74
74
  url,
@@ -77,8 +77,12 @@ export default class WhatsappClient extends ApiClient {
77
77
  return res.data;
78
78
  }
79
79
 
80
- public async sendMessage(to: string, data: SendMessageData) {
81
- const url = "/api/whatsapp/messages";
80
+ public async sendMessage(
81
+ clientId: string,
82
+ to: string,
83
+ data: SendMessageData,
84
+ ) {
85
+ const url = `/api/whatsapp/${clientId}/messages`;
82
86
  const formData = new FormData();
83
87
  formData.append("to", to);
84
88
  data.text && formData.append("text", data.text);
@@ -104,13 +108,13 @@ export default class WhatsappClient extends ApiClient {
104
108
  }
105
109
 
106
110
  public async editMessage(
111
+ clientId: string,
107
112
  messageId: string,
108
113
  newText: string,
109
114
  isInternal = false,
110
115
  ) {
111
116
  const type = isInternal ? "internal" : "whatsapp";
112
-
113
- const url = `/api/${type}/messages/${messageId}`;
117
+ const url = `/api/${type}/${clientId}/messages/${messageId}`;
114
118
  const body = { newText };
115
119
  await this.ax.put(url, body);
116
120
  }
@@ -118,17 +122,16 @@ export default class WhatsappClient extends ApiClient {
118
122
  public async finishChatById(
119
123
  id: number,
120
124
  resultId: number,
121
- triggerSatisfactionBot = false,
125
+ scheduleDate?: Date | null,
122
126
  ) {
123
127
  const url = `/api/whatsapp/chats/${id}/finish`;
124
- const body = { resultId, triggerSatisfactionBot };
128
+ const body = { resultId, scheduleDate };
125
129
  await this.ax.post<MessageResponse>(url, body);
126
130
  }
127
131
 
128
132
  public async startChatByContactId(contactId: number, template?: any) {
129
133
  const url = `/api/whatsapp/chats`;
130
134
  const body = { contactId, template };
131
-
132
135
  await this.ax.post<DataResponse<WppChatWithDetailsAndMessages>>(
133
136
  url,
134
137
  body,
@@ -184,9 +187,7 @@ export default class WhatsappClient extends ApiClient {
184
187
  const queryString = params.toString();
185
188
  if (queryString) url += `?${queryString}`;
186
189
  }
187
-
188
190
  const res = await this.ax.get<PaginatedContactsResponse>(url);
189
-
190
191
  return res.data;
191
192
  }
192
193
 
@@ -208,7 +209,7 @@ export default class WhatsappClient extends ApiClient {
208
209
  ? `${baseUrl}/customers/${customerId}/contacts`
209
210
  : `${baseUrl}/contacts`;
210
211
  const body: Record<string, any> = { name, phone };
211
- if (sectorIds !== undefined) body['sectorIds'] = sectorIds;
212
+ if (sectorIds !== undefined) body["sectorIds"] = sectorIds;
212
213
  const { data: res } = await this.ax.post<DataResponse<WppContact>>(
213
214
  url,
214
215
  body,
@@ -216,8 +217,8 @@ export default class WhatsappClient extends ApiClient {
216
217
  return res.data;
217
218
  }
218
219
 
219
- public async forwardMessages(data: ForwardMessagesData) {
220
- const url = "/api/whatsapp/messages/forward";
220
+ public async forwardMessages(clientId: string, data: ForwardMessagesData) {
221
+ const url = `/api/whatsapp/${clientId}/messages/forward`;
221
222
  const body = data;
222
223
  await this.ax.post<MessageResponse>(url, body);
223
224
  }