@in.pulse-crm/sdk 2.11.2 → 2.11.4
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/.prettierrc +4 -4
- package/dist/files.client.d.ts +1 -0
- package/dist/files.client.js +4 -0
- package/dist/whatsapp.client.d.ts +1 -1
- package/dist/whatsapp.client.js +2 -2
- package/package.json +36 -36
- package/src/api-client.ts +32 -32
- package/src/auth.client.ts +119 -119
- package/src/customers.client.ts +78 -78
- package/src/files.client.ts +85 -79
- package/src/index.ts +12 -12
- package/src/instance.client.ts +42 -42
- package/src/internal.client.ts +142 -142
- package/src/ready-message.client.ts +72 -72
- package/src/reports.client.ts +111 -111
- package/src/socket-server.client.ts +33 -33
- package/src/socket.client.ts +91 -91
- package/src/types/auth.types.ts +42 -42
- package/src/types/customers.types.ts +78 -78
- package/src/types/files.types.ts +82 -82
- package/src/types/index.ts +12 -12
- package/src/types/internal.types.ts +79 -79
- package/src/types/ready-messages.types.ts +10 -10
- package/src/types/reports.types.ts +49 -49
- package/src/types/request.types.ts +5 -5
- package/src/types/response.types.ts +26 -26
- package/src/types/socket-events.types.ts +308 -308
- package/src/types/socket-rooms.types.ts +66 -66
- package/src/types/user.types.ts +162 -162
- package/src/types/wallet.types.ts +5 -5
- package/src/types/whatsapp.types.ts +232 -232
- package/src/users.client.ts +88 -88
- package/src/wallets.client.ts +124 -124
- package/src/whatsapp.client.ts +374 -374
- package/tsconfig.json +16 -16
package/src/files.client.ts
CHANGED
|
@@ -1,79 +1,85 @@
|
|
|
1
|
-
import FormData from "form-data";
|
|
2
|
-
import ApiClient from "./api-client";
|
|
3
|
-
import { File, UploadFileOptions } from "./types/files.types";
|
|
4
|
-
import { DataResponse } from "./types/response.types";
|
|
5
|
-
|
|
6
|
-
class FilesClient extends ApiClient {
|
|
7
|
-
/**
|
|
8
|
-
* Busca um arquivo pelo ID.
|
|
9
|
-
* @param {number} id - ID do arquivo.
|
|
10
|
-
* @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
|
|
11
|
-
*/
|
|
12
|
-
public async fetchFile(id: number): Promise<Buffer> {
|
|
13
|
-
const response = await this.ax.get(`/api/files/${id}`, {
|
|
14
|
-
responseType: "arraybuffer",
|
|
15
|
-
});
|
|
16
|
-
const buffer = Buffer.from(response.data, "binary");
|
|
17
|
-
|
|
18
|
-
return buffer;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Fetches the metadata of a file by its ID.
|
|
23
|
-
*
|
|
24
|
-
* @param id - The unique identifier of the file.
|
|
25
|
-
* @returns A promise that resolves to the file metadata.
|
|
26
|
-
* @throws Will throw an error if the HTTP request fails.
|
|
27
|
-
*/
|
|
28
|
-
public async fetchFileMetadata(id: number): Promise<File> {
|
|
29
|
-
const { data: res } = await this.ax.get<DataResponse<File>>(
|
|
30
|
-
`/api/files/${id}/metadata`,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return res.data;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Obtém a URL de download de um arquivo.
|
|
38
|
-
* @param {number} id - ID do arquivo.
|
|
39
|
-
* @returns {string} URL de download do arquivo.
|
|
40
|
-
*/
|
|
41
|
-
public getFileDownloadUrl(id: number, baseUrl?: string): string {
|
|
42
|
-
return (baseUrl || this.ax.defaults.baseURL) + `/api/files/${id}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Faz o upload de um arquivo.
|
|
47
|
-
* @param {UploadFileOptions} props - Opções para o upload do arquivo.
|
|
48
|
-
* @returns {Promise<File>} Os dados do arquivo enviado.
|
|
49
|
-
*/
|
|
50
|
-
public async uploadFile(props: UploadFileOptions): Promise<File> {
|
|
51
|
-
// Node: use 'form-data' (evita conflito de tipos com Blob)
|
|
52
|
-
const form = new FormData();
|
|
53
|
-
form.append("instance", props.instance);
|
|
54
|
-
form.append("dirType", props.dirType);
|
|
55
|
-
|
|
56
|
-
form.append("file", props.buffer, {
|
|
57
|
-
filename: props.fileName,
|
|
58
|
-
contentType: props.mimeType,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const response = await this.ax.post<DataResponse<File>>("/api/files", form, {
|
|
62
|
-
// deixe o boundary correto
|
|
63
|
-
headers: form.getHeaders(),
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return response.data.data;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Deleta um arquivo pelo ID.
|
|
71
|
-
* @param {number} id - ID do arquivo.
|
|
72
|
-
* @returns {Promise<void>}
|
|
73
|
-
*/
|
|
74
|
-
public async deleteFile(id: number): Promise<void> {
|
|
75
|
-
await this.ax.delete(`/api/files/${id}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
import ApiClient from "./api-client";
|
|
3
|
+
import { File, UploadFileOptions } from "./types/files.types";
|
|
4
|
+
import { DataResponse } from "./types/response.types";
|
|
5
|
+
|
|
6
|
+
class FilesClient extends ApiClient {
|
|
7
|
+
/**
|
|
8
|
+
* Busca um arquivo pelo ID.
|
|
9
|
+
* @param {number} id - ID do arquivo.
|
|
10
|
+
* @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
|
|
11
|
+
*/
|
|
12
|
+
public async fetchFile(id: number): Promise<Buffer> {
|
|
13
|
+
const response = await this.ax.get(`/api/files/${id}`, {
|
|
14
|
+
responseType: "arraybuffer",
|
|
15
|
+
});
|
|
16
|
+
const buffer = Buffer.from(response.data, "binary");
|
|
17
|
+
|
|
18
|
+
return buffer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Fetches the metadata of a file by its ID.
|
|
23
|
+
*
|
|
24
|
+
* @param id - The unique identifier of the file.
|
|
25
|
+
* @returns A promise that resolves to the file metadata.
|
|
26
|
+
* @throws Will throw an error if the HTTP request fails.
|
|
27
|
+
*/
|
|
28
|
+
public async fetchFileMetadata(id: number): Promise<File> {
|
|
29
|
+
const { data: res } = await this.ax.get<DataResponse<File>>(
|
|
30
|
+
`/api/files/${id}/metadata`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return res.data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Obtém a URL de download de um arquivo.
|
|
38
|
+
* @param {number} id - ID do arquivo.
|
|
39
|
+
* @returns {string} URL de download do arquivo.
|
|
40
|
+
*/
|
|
41
|
+
public getFileDownloadUrl(id: number, baseUrl?: string): string {
|
|
42
|
+
return (baseUrl || this.ax.defaults.baseURL) + `/api/files/${id}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Faz o upload de um arquivo.
|
|
47
|
+
* @param {UploadFileOptions} props - Opções para o upload do arquivo.
|
|
48
|
+
* @returns {Promise<File>} Os dados do arquivo enviado.
|
|
49
|
+
*/
|
|
50
|
+
public async uploadFile(props: UploadFileOptions): Promise<File> {
|
|
51
|
+
// Node: use 'form-data' (evita conflito de tipos com Blob)
|
|
52
|
+
const form = new FormData();
|
|
53
|
+
form.append("instance", props.instance);
|
|
54
|
+
form.append("dirType", props.dirType);
|
|
55
|
+
|
|
56
|
+
form.append("file", props.buffer, {
|
|
57
|
+
filename: props.fileName,
|
|
58
|
+
contentType: props.mimeType,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const response = await this.ax.post<DataResponse<File>>("/api/files", form, {
|
|
62
|
+
// deixe o boundary correto
|
|
63
|
+
headers: form.getHeaders(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return response.data.data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Deleta um arquivo pelo ID.
|
|
71
|
+
* @param {number} id - ID do arquivo.
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
public async deleteFile(id: number): Promise<void> {
|
|
75
|
+
await this.ax.delete(`/api/files/${id}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public async uploadWabaMedia(instance: string, wabaMediaId: string): Promise<File> {
|
|
79
|
+
const response = await this.ax.post<DataResponse<File>>(`/api/waba`, { instance, wabaMediaId });
|
|
80
|
+
return response.data.data;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default FilesClient;
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export { default as AuthClient } from "./auth.client";
|
|
3
|
-
export { default as CustomersClient } from "./customers.client";
|
|
4
|
-
export { default as FilesClient } from "./files.client";
|
|
5
|
-
export { default as InstancesClient } from "./instance.client";
|
|
6
|
-
export { default as ReportsClient } from "./reports.client";
|
|
7
|
-
export { default as SocketServerClient } from "./socket-server.client";
|
|
8
|
-
export { default as SocketClient } from "./socket.client";
|
|
9
|
-
export { default as UsersClient } from "./users.client";
|
|
10
|
-
export { default as WhatsappClient } from "./whatsapp.client";
|
|
11
|
-
export { default as WalletsClient } from "./wallets.client";
|
|
12
|
-
export { default as InternalChatClient } from "./internal.client";
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export { default as AuthClient } from "./auth.client";
|
|
3
|
+
export { default as CustomersClient } from "./customers.client";
|
|
4
|
+
export { default as FilesClient } from "./files.client";
|
|
5
|
+
export { default as InstancesClient } from "./instance.client";
|
|
6
|
+
export { default as ReportsClient } from "./reports.client";
|
|
7
|
+
export { default as SocketServerClient } from "./socket-server.client";
|
|
8
|
+
export { default as SocketClient } from "./socket.client";
|
|
9
|
+
export { default as UsersClient } from "./users.client";
|
|
10
|
+
export { default as WhatsappClient } from "./whatsapp.client";
|
|
11
|
+
export { default as WalletsClient } from "./wallets.client";
|
|
12
|
+
export { default as InternalChatClient } from "./internal.client";
|
|
13
13
|
export { default as ReadyMessageClient} from "./ready-message.client"
|
package/src/instance.client.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { QueryResponse } from "./types/response.types";
|
|
3
|
-
import ApiClient from "./api-client";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Classe InstanceSDK para interagir com a API de instâncias.
|
|
7
|
-
*/
|
|
8
|
-
class InstancesClient extends ApiClient {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Executa uma consulta na instância especificada.
|
|
12
|
-
* @param {string} instance Nome da instância do Inpulse.
|
|
13
|
-
* @param {string} query Consulta a ser executada.
|
|
14
|
-
* @param {any[]} parameters Parâmetros da consulta.
|
|
15
|
-
* @returns {Promise<T>} Resultado da consulta.
|
|
16
|
-
*/
|
|
17
|
-
public async executeQuery<T>(
|
|
18
|
-
instance: string,
|
|
19
|
-
query: string,
|
|
20
|
-
parameters: any[],
|
|
21
|
-
): Promise<T> {
|
|
22
|
-
const response = await this.ax
|
|
23
|
-
.post<
|
|
24
|
-
QueryResponse<T>
|
|
25
|
-
>(`/api/instances/${instance}/query`, { query, parameters })
|
|
26
|
-
.catch((error) => {
|
|
27
|
-
if (error.response?.data?.message) {
|
|
28
|
-
throw new Error(error.response.data.message);
|
|
29
|
-
}
|
|
30
|
-
if (error.response?.status) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Failed to execute query, status: ${error.response.status}`,
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
throw new Error(error.message);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return response.data.result;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default InstancesClient;
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { QueryResponse } from "./types/response.types";
|
|
3
|
+
import ApiClient from "./api-client";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Classe InstanceSDK para interagir com a API de instâncias.
|
|
7
|
+
*/
|
|
8
|
+
class InstancesClient extends ApiClient {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Executa uma consulta na instância especificada.
|
|
12
|
+
* @param {string} instance Nome da instância do Inpulse.
|
|
13
|
+
* @param {string} query Consulta a ser executada.
|
|
14
|
+
* @param {any[]} parameters Parâmetros da consulta.
|
|
15
|
+
* @returns {Promise<T>} Resultado da consulta.
|
|
16
|
+
*/
|
|
17
|
+
public async executeQuery<T>(
|
|
18
|
+
instance: string,
|
|
19
|
+
query: string,
|
|
20
|
+
parameters: any[],
|
|
21
|
+
): Promise<T> {
|
|
22
|
+
const response = await this.ax
|
|
23
|
+
.post<
|
|
24
|
+
QueryResponse<T>
|
|
25
|
+
>(`/api/instances/${instance}/query`, { query, parameters })
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
if (error.response?.data?.message) {
|
|
28
|
+
throw new Error(error.response.data.message);
|
|
29
|
+
}
|
|
30
|
+
if (error.response?.status) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Failed to execute query, status: ${error.response.status}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
throw new Error(error.message);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return response.data.result;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default InstancesClient;
|
package/src/internal.client.ts
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import ApiClient from "./api-client";
|
|
2
|
-
import { DataResponse } from "./types/response.types";
|
|
3
|
-
import {
|
|
4
|
-
InternalChat,
|
|
5
|
-
InternalChatMember,
|
|
6
|
-
InternalGroup,
|
|
7
|
-
InternalMessage,
|
|
8
|
-
InternalSendMessageData,
|
|
9
|
-
} from "./types/internal.types";
|
|
10
|
-
import FormData from "form-data";
|
|
11
|
-
|
|
12
|
-
type GetChatsResponse = DataResponse<{
|
|
13
|
-
chats: (InternalChat & { participants: InternalChatMember[] })[];
|
|
14
|
-
messages: InternalMessage[];
|
|
15
|
-
}>;
|
|
16
|
-
export default class InternalChatClient extends ApiClient {
|
|
17
|
-
public async createInternalChat(
|
|
18
|
-
participants: number[],
|
|
19
|
-
isGroup: boolean = false,
|
|
20
|
-
groupName: string | null = null,
|
|
21
|
-
groupId: string | null = null,
|
|
22
|
-
groupImage: File | null = null,
|
|
23
|
-
) {
|
|
24
|
-
const form = new FormData();
|
|
25
|
-
|
|
26
|
-
if (groupImage) {
|
|
27
|
-
form.append("file", groupImage);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
form.append(
|
|
31
|
-
"data",
|
|
32
|
-
JSON.stringify({ participants, isGroup, groupName, groupId }),
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const { data: res } = await this.ax.post<
|
|
36
|
-
DataResponse<InternalChat>
|
|
37
|
-
>(`/api/internal/chats`, form, {
|
|
38
|
-
headers: {
|
|
39
|
-
"Content-Type": "multipart/form-data",
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return res.data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public async deleteInternalChat(chatId: number) {
|
|
47
|
-
const url = `/api/internal/chats/${chatId}`;
|
|
48
|
-
await this.ax.delete<DataResponse<InternalChat>>(url);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async getInternalChatsBySession(token: string | null = null) {
|
|
52
|
-
const url = `/api/internal/session/chats`;
|
|
53
|
-
|
|
54
|
-
const headers = token
|
|
55
|
-
? { Authorization: `Bearer ${token}` }
|
|
56
|
-
: undefined;
|
|
57
|
-
|
|
58
|
-
const { data: res } = await this.ax.get<GetChatsResponse>(url, {
|
|
59
|
-
headers,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return res.data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public async getInternalGroups() {
|
|
66
|
-
const url = `/api/internal/groups`;
|
|
67
|
-
const { data: res } =
|
|
68
|
-
await this.ax.get<DataResponse<InternalGroup[]>>(url);
|
|
69
|
-
|
|
70
|
-
return res.data;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public async sendMessageToInternalChat(data: InternalSendMessageData) {
|
|
74
|
-
const url = `/api/internal/chats/${data.chatId}/messages`;
|
|
75
|
-
const formData = new FormData();
|
|
76
|
-
|
|
77
|
-
formData.append("chatId", data.chatId.toString());
|
|
78
|
-
formData.append("text", data.text);
|
|
79
|
-
data.quotedId && formData.append("quotedId", data.quotedId.toString());
|
|
80
|
-
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
81
|
-
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
82
|
-
data.file && formData.append("file", data.file);
|
|
83
|
-
data.fileId && formData.append("fileId", data.fileId.toString());
|
|
84
|
-
if (data.mentions && data.mentions.length > 0) {
|
|
85
|
-
formData.append("mentions", JSON.stringify(data.mentions));
|
|
86
|
-
}
|
|
87
|
-
await this.ax.post<DataResponse<InternalMessage>>(
|
|
88
|
-
url,
|
|
89
|
-
formData,
|
|
90
|
-
{
|
|
91
|
-
headers: {
|
|
92
|
-
"Content-Type": "multipart/form-data",
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public async updateInternalGroup(
|
|
99
|
-
groupId: number,
|
|
100
|
-
data: {
|
|
101
|
-
name: string;
|
|
102
|
-
participants: number[];
|
|
103
|
-
wppGroupId: string | null;
|
|
104
|
-
},
|
|
105
|
-
) {
|
|
106
|
-
const { data: res } = await this.ax.put<
|
|
107
|
-
DataResponse<InternalGroup>
|
|
108
|
-
>(`/api/internal/groups/${groupId}`, data);
|
|
109
|
-
return res.data;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public async updateInternalGroupImage(groupId: number, file: File) {
|
|
113
|
-
const formData = new FormData();
|
|
114
|
-
formData.append("file", file);
|
|
115
|
-
|
|
116
|
-
const { data: res } = await this.ax.put<
|
|
117
|
-
DataResponse<InternalGroup>
|
|
118
|
-
>(`/api/internal/groups/${groupId}/image`, formData, {
|
|
119
|
-
headers: {
|
|
120
|
-
"Content-Type": "multipart/form-data",
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
return res.data;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public async markChatMessagesAsRead(chatId: number) {
|
|
127
|
-
const url = `/api/internal/chat/${chatId}/mark-as-read`;
|
|
128
|
-
await this.ax.patch(url);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public async getInternalChatsMonitor() {
|
|
132
|
-
const url = `/api/internal/monitor/chats`;
|
|
133
|
-
const { data: res } = await this.ax.get<GetChatsResponse>(url);
|
|
134
|
-
|
|
135
|
-
return res.data;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public setAuth(token: string) {
|
|
139
|
-
this.ax.defaults.headers.common["Authorization"] =
|
|
140
|
-
`Bearer ${token}`;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
1
|
+
import ApiClient from "./api-client";
|
|
2
|
+
import { DataResponse } from "./types/response.types";
|
|
3
|
+
import {
|
|
4
|
+
InternalChat,
|
|
5
|
+
InternalChatMember,
|
|
6
|
+
InternalGroup,
|
|
7
|
+
InternalMessage,
|
|
8
|
+
InternalSendMessageData,
|
|
9
|
+
} from "./types/internal.types";
|
|
10
|
+
import FormData from "form-data";
|
|
11
|
+
|
|
12
|
+
type GetChatsResponse = DataResponse<{
|
|
13
|
+
chats: (InternalChat & { participants: InternalChatMember[] })[];
|
|
14
|
+
messages: InternalMessage[];
|
|
15
|
+
}>;
|
|
16
|
+
export default class InternalChatClient extends ApiClient {
|
|
17
|
+
public async createInternalChat(
|
|
18
|
+
participants: number[],
|
|
19
|
+
isGroup: boolean = false,
|
|
20
|
+
groupName: string | null = null,
|
|
21
|
+
groupId: string | null = null,
|
|
22
|
+
groupImage: File | null = null,
|
|
23
|
+
) {
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
|
|
26
|
+
if (groupImage) {
|
|
27
|
+
form.append("file", groupImage);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
form.append(
|
|
31
|
+
"data",
|
|
32
|
+
JSON.stringify({ participants, isGroup, groupName, groupId }),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const { data: res } = await this.ax.post<
|
|
36
|
+
DataResponse<InternalChat>
|
|
37
|
+
>(`/api/internal/chats`, form, {
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "multipart/form-data",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return res.data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async deleteInternalChat(chatId: number) {
|
|
47
|
+
const url = `/api/internal/chats/${chatId}`;
|
|
48
|
+
await this.ax.delete<DataResponse<InternalChat>>(url);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async getInternalChatsBySession(token: string | null = null) {
|
|
52
|
+
const url = `/api/internal/session/chats`;
|
|
53
|
+
|
|
54
|
+
const headers = token
|
|
55
|
+
? { Authorization: `Bearer ${token}` }
|
|
56
|
+
: undefined;
|
|
57
|
+
|
|
58
|
+
const { data: res } = await this.ax.get<GetChatsResponse>(url, {
|
|
59
|
+
headers,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return res.data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public async getInternalGroups() {
|
|
66
|
+
const url = `/api/internal/groups`;
|
|
67
|
+
const { data: res } =
|
|
68
|
+
await this.ax.get<DataResponse<InternalGroup[]>>(url);
|
|
69
|
+
|
|
70
|
+
return res.data;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public async sendMessageToInternalChat(data: InternalSendMessageData) {
|
|
74
|
+
const url = `/api/internal/chats/${data.chatId}/messages`;
|
|
75
|
+
const formData = new FormData();
|
|
76
|
+
|
|
77
|
+
formData.append("chatId", data.chatId.toString());
|
|
78
|
+
formData.append("text", data.text);
|
|
79
|
+
data.quotedId && formData.append("quotedId", data.quotedId.toString());
|
|
80
|
+
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
81
|
+
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
82
|
+
data.file && formData.append("file", data.file);
|
|
83
|
+
data.fileId && formData.append("fileId", data.fileId.toString());
|
|
84
|
+
if (data.mentions && data.mentions.length > 0) {
|
|
85
|
+
formData.append("mentions", JSON.stringify(data.mentions));
|
|
86
|
+
}
|
|
87
|
+
await this.ax.post<DataResponse<InternalMessage>>(
|
|
88
|
+
url,
|
|
89
|
+
formData,
|
|
90
|
+
{
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "multipart/form-data",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async updateInternalGroup(
|
|
99
|
+
groupId: number,
|
|
100
|
+
data: {
|
|
101
|
+
name: string;
|
|
102
|
+
participants: number[];
|
|
103
|
+
wppGroupId: string | null;
|
|
104
|
+
},
|
|
105
|
+
) {
|
|
106
|
+
const { data: res } = await this.ax.put<
|
|
107
|
+
DataResponse<InternalGroup>
|
|
108
|
+
>(`/api/internal/groups/${groupId}`, data);
|
|
109
|
+
return res.data;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public async updateInternalGroupImage(groupId: number, file: File) {
|
|
113
|
+
const formData = new FormData();
|
|
114
|
+
formData.append("file", file);
|
|
115
|
+
|
|
116
|
+
const { data: res } = await this.ax.put<
|
|
117
|
+
DataResponse<InternalGroup>
|
|
118
|
+
>(`/api/internal/groups/${groupId}/image`, formData, {
|
|
119
|
+
headers: {
|
|
120
|
+
"Content-Type": "multipart/form-data",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
return res.data;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public async markChatMessagesAsRead(chatId: number) {
|
|
127
|
+
const url = `/api/internal/chat/${chatId}/mark-as-read`;
|
|
128
|
+
await this.ax.patch(url);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public async getInternalChatsMonitor() {
|
|
132
|
+
const url = `/api/internal/monitor/chats`;
|
|
133
|
+
const { data: res } = await this.ax.get<GetChatsResponse>(url);
|
|
134
|
+
|
|
135
|
+
return res.data;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public setAuth(token: string) {
|
|
139
|
+
this.ax.defaults.headers.common["Authorization"] =
|
|
140
|
+
`Bearer ${token}`;
|
|
141
|
+
}
|
|
142
|
+
}
|