@in.pulse-crm/sdk 2.3.4 → 2.3.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/files.client.d.ts +8 -0
- package/dist/files.client.js +11 -0
- package/dist/types/whatsapp.types.d.ts +11 -0
- package/dist/whatsapp.client.d.ts +2 -1
- package/dist/whatsapp.client.js +4 -0
- package/package.json +1 -1
- package/src/files.client.ts +20 -1
- package/src/types/whatsapp.types.ts +12 -0
- package/src/whatsapp.client.ts +6 -0
package/dist/files.client.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ declare class FilesClient extends ApiClient {
|
|
|
9
9
|
* @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
|
|
10
10
|
*/
|
|
11
11
|
fetchFile(id: number): Promise<Buffer>;
|
|
12
|
+
/**
|
|
13
|
+
* Fetches the metadata of a file by its ID.
|
|
14
|
+
*
|
|
15
|
+
* @param id - The unique identifier of the file.
|
|
16
|
+
* @returns A promise that resolves to the file metadata.
|
|
17
|
+
* @throws Will throw an error if the HTTP request fails.
|
|
18
|
+
*/
|
|
19
|
+
fetchFileMetadata(id: number): Promise<File>;
|
|
12
20
|
/**
|
|
13
21
|
* Obtém a URL de download de um arquivo.
|
|
14
22
|
* @param {number} id - ID do arquivo.
|
package/dist/files.client.js
CHANGED
|
@@ -17,6 +17,17 @@ class FilesClient extends api_client_1.default {
|
|
|
17
17
|
const buffer = Buffer.from(response.data, "binary");
|
|
18
18
|
return buffer;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the metadata of a file by its ID.
|
|
22
|
+
*
|
|
23
|
+
* @param id - The unique identifier of the file.
|
|
24
|
+
* @returns A promise that resolves to the file metadata.
|
|
25
|
+
* @throws Will throw an error if the HTTP request fails.
|
|
26
|
+
*/
|
|
27
|
+
async fetchFileMetadata(id) {
|
|
28
|
+
const { data: res } = await this.httpClient.get(`/api/files/${id}/metadata`);
|
|
29
|
+
return res.data;
|
|
30
|
+
}
|
|
20
31
|
/**
|
|
21
32
|
* Obtém a URL de download de um arquivo.
|
|
22
33
|
* @param {number} id - ID do arquivo.
|
|
@@ -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(data: SendMessageData): Promise<void>;
|
|
9
10
|
setAuth(token: string): void;
|
|
10
11
|
}
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -32,6 +32,10 @@ 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(data) {
|
|
36
|
+
const url = "/api/whatsapp/messages";
|
|
37
|
+
await this.httpClient.post(url, data);
|
|
38
|
+
}
|
|
35
39
|
setAuth(token) {
|
|
36
40
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
37
41
|
`Bearer ${token}`;
|
package/package.json
CHANGED
package/src/files.client.ts
CHANGED
|
@@ -17,6 +17,21 @@ class FilesClient extends ApiClient {
|
|
|
17
17
|
return buffer;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the metadata of a file by its ID.
|
|
22
|
+
*
|
|
23
|
+
* @param id - The unique identifier of the file.
|
|
24
|
+
* @returns A promise that resolves to the file metadata.
|
|
25
|
+
* @throws Will throw an error if the HTTP request fails.
|
|
26
|
+
*/
|
|
27
|
+
public async fetchFileMetadata(id: number): Promise<File> {
|
|
28
|
+
const { data: res } = await this.httpClient.get<DataResponse<File>>(
|
|
29
|
+
`/api/files/${id}/metadata`,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return res.data;
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
/**
|
|
21
36
|
* Obtém a URL de download de um arquivo.
|
|
22
37
|
* @param {number} id - ID do arquivo.
|
|
@@ -35,7 +50,11 @@ class FilesClient extends ApiClient {
|
|
|
35
50
|
const form = new FormData();
|
|
36
51
|
form.append("instance", props.instance);
|
|
37
52
|
form.append("dirType", props.dirType);
|
|
38
|
-
form.append(
|
|
53
|
+
form.append(
|
|
54
|
+
"file",
|
|
55
|
+
new Blob([props.buffer], { type: props.mimeType }),
|
|
56
|
+
props.fileName,
|
|
57
|
+
);
|
|
39
58
|
|
|
40
59
|
const response = await this.httpClient.post<DataResponse<File>>(
|
|
41
60
|
"/api/files",
|
|
@@ -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,11 @@ export default class WhatsappClient extends ApiClient {
|
|
|
62
63
|
return res.data;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
public async sendMessage(data: SendMessageData): Promise<void> {
|
|
67
|
+
const url = "/api/whatsapp/messages";
|
|
68
|
+
await this.httpClient.post<DataResponse<WppMessage>>(url, data);
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
public setAuth(token: string) {
|
|
66
72
|
this.httpClient.defaults.headers.common["Authorization"] =
|
|
67
73
|
`Bearer ${token}`;
|