@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.
|
@@ -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,
|
|
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>;
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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,
|
|
64
|
+
async finishChatById(id, resultId, scheduleDate) {
|
|
65
65
|
const url = `/api/whatsapp/chats/${id}/finish`;
|
|
66
|
-
const body = { resultId,
|
|
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[
|
|
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 =
|
|
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
package/src/whatsapp.client.ts
CHANGED
|
@@ -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 =
|
|
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(
|
|
81
|
-
|
|
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
|
-
|
|
125
|
+
scheduleDate?: Date | null,
|
|
122
126
|
) {
|
|
123
127
|
const url = `/api/whatsapp/chats/${id}/finish`;
|
|
124
|
-
const body = { resultId,
|
|
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[
|
|
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 =
|
|
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
|
}
|