@in.pulse-crm/sdk 2.3.5 → 2.3.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.
|
@@ -77,3 +77,14 @@ export type WppChatsAndMessages = {
|
|
|
77
77
|
export type WppChatWithDetailsAndMessages = WppChatWithDetails & {
|
|
78
78
|
messages: WppMessage[];
|
|
79
79
|
};
|
|
80
|
+
export interface SendMessageData {
|
|
81
|
+
sendAsChatOwner?: boolean;
|
|
82
|
+
sendAsAudio?: boolean;
|
|
83
|
+
sendAsDocument?: boolean;
|
|
84
|
+
contactId: number;
|
|
85
|
+
quotedId?: number | null;
|
|
86
|
+
chatId?: number | null;
|
|
87
|
+
text?: string | null;
|
|
88
|
+
file?: File;
|
|
89
|
+
fileId?: number;
|
|
90
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
2
|
+
import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, 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>;
|
|
6
6
|
getMessageById(id: string): Promise<WppMessage>;
|
|
7
7
|
getUserWallets(instance: string, userId: number): Promise<WppWallet[]>;
|
|
8
8
|
markContactMessagesAsRead(contactId: number): Promise<WppMessage[]>;
|
|
9
|
+
sendMessage(to: string, data: SendMessageData): Promise<void>;
|
|
9
10
|
setAuth(token: string): void;
|
|
10
11
|
}
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -32,6 +32,21 @@ class WhatsappClient extends api_client_1.default {
|
|
|
32
32
|
const { data: res } = await this.httpClient.patch(url, body);
|
|
33
33
|
return res.data;
|
|
34
34
|
}
|
|
35
|
+
async sendMessage(to, data) {
|
|
36
|
+
const url = "/api/whatsapp/messages";
|
|
37
|
+
const formData = new FormData();
|
|
38
|
+
formData.append("to", to);
|
|
39
|
+
data.text && formData.append("text", data.text);
|
|
40
|
+
data.file && formData.append("file", data.file);
|
|
41
|
+
data.quotedId && formData.append("quotedId", String(data.quotedId));
|
|
42
|
+
data.chatId && formData.append("chatId", String(data.chatId));
|
|
43
|
+
data.contactId && formData.append("contactId", String(data.contactId));
|
|
44
|
+
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
45
|
+
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
46
|
+
data.sendAsChatOwner &&
|
|
47
|
+
formData.append("sendAsChatOwner", String(data.sendAsChatOwner));
|
|
48
|
+
await this.httpClient.post(url, formData);
|
|
49
|
+
}
|
|
35
50
|
setAuth(token) {
|
|
36
51
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
37
52
|
`Bearer ${token}`;
|
package/package.json
CHANGED
|
@@ -93,3 +93,15 @@ export type WppChatsAndMessages = {
|
|
|
93
93
|
export type WppChatWithDetailsAndMessages = WppChatWithDetails & {
|
|
94
94
|
messages: WppMessage[];
|
|
95
95
|
};
|
|
96
|
+
|
|
97
|
+
export interface SendMessageData {
|
|
98
|
+
sendAsChatOwner?: boolean;
|
|
99
|
+
sendAsAudio?: boolean;
|
|
100
|
+
sendAsDocument?: boolean;
|
|
101
|
+
contactId: number;
|
|
102
|
+
quotedId?: number | null;
|
|
103
|
+
chatId?: number | null;
|
|
104
|
+
text?: string | null;
|
|
105
|
+
file?: File;
|
|
106
|
+
fileId?: number;
|
|
107
|
+
}
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
2
|
import { DataResponse } from "./types/response.types";
|
|
3
3
|
import {
|
|
4
|
+
SendMessageData,
|
|
4
5
|
WppChatsAndMessages,
|
|
5
6
|
WppChatWithDetailsAndMessages,
|
|
6
7
|
WppMessage,
|
|
@@ -62,6 +63,24 @@ export default class WhatsappClient extends ApiClient {
|
|
|
62
63
|
return res.data;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
public async sendMessage(to: string, data: SendMessageData): Promise<void> {
|
|
67
|
+
const url = "/api/whatsapp/messages";
|
|
68
|
+
|
|
69
|
+
const formData = new FormData();
|
|
70
|
+
formData.append("to", to);
|
|
71
|
+
data.text && formData.append("text", data.text);
|
|
72
|
+
data.file && formData.append("file", data.file);
|
|
73
|
+
data.quotedId && formData.append("quotedId", String(data.quotedId));
|
|
74
|
+
data.chatId && formData.append("chatId", String(data.chatId));
|
|
75
|
+
data.contactId && formData.append("contactId", String(data.contactId));
|
|
76
|
+
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
77
|
+
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
78
|
+
data.sendAsChatOwner &&
|
|
79
|
+
formData.append("sendAsChatOwner", String(data.sendAsChatOwner));
|
|
80
|
+
|
|
81
|
+
await this.httpClient.post<DataResponse<WppMessage>>(url, formData);
|
|
82
|
+
}
|
|
83
|
+
|
|
65
84
|
public setAuth(token: string) {
|
|
66
85
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
67
86
|
`Bearer ${token}`;
|