@in.pulse-crm/sdk 2.4.13 → 2.5.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.
- package/.prettierrc +4 -4
- package/dist/files.client.d.ts +2 -0
- package/dist/internal.client.d.ts +14 -7
- package/dist/internal.client.js +30 -22
- package/dist/types/files.types.d.ts +2 -0
- package/dist/types/internal.types.d.ts +17 -81
- package/dist/types/internal.types.js +0 -14
- package/dist/types/socket-events.types.d.ts +10 -8
- package/dist/types/socket-rooms.types.d.ts +7 -4
- package/dist/whatsapp.client.d.ts +1 -1
- package/dist/whatsapp.client.js +7 -3
- package/package.json +1 -1
- package/src/internal.client.ts +91 -61
- package/src/types/internal.types.ts +18 -97
- package/src/types/socket-events.types.ts +64 -62
- package/src/types/socket-rooms.types.ts +12 -5
- package/src/whatsapp.client.ts +9 -4
- package/tsconfig.json +16 -16
package/.prettierrc
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tabWidth": 4,
|
|
3
|
-
"useTabs": true
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"tabWidth": 4,
|
|
3
|
+
"useTabs": true
|
|
4
|
+
}
|
package/dist/files.client.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import { InternalChat,
|
|
2
|
+
import { InternalChat, InternalMessage, InternalSendMessageData } from "./types/internal.types";
|
|
3
3
|
export default class InternalChatClient extends ApiClient {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
createInternalChat(participants: number[], isGroup?: boolean, groupName?: string): Promise<InternalChat>;
|
|
5
|
+
getInternalChatsBySession(token?: string | null): Promise<{
|
|
6
|
+
chats: (InternalChat & {
|
|
7
|
+
participants: number[];
|
|
8
|
+
})[];
|
|
9
|
+
messages: InternalMessage[];
|
|
10
|
+
}>;
|
|
11
|
+
sendMessageToChat(data: InternalSendMessageData): Promise<void>;
|
|
9
12
|
updateGroupMembers(groupId: number, add: number[], remove: number[]): Promise<any>;
|
|
10
|
-
|
|
13
|
+
startChatByContactId(contactId: number): Promise<{
|
|
14
|
+
chat: InternalChat & {
|
|
15
|
+
messages: InternalMessage[];
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
11
18
|
setAuth(token: string): void;
|
|
12
19
|
}
|
package/dist/internal.client.js
CHANGED
|
@@ -4,39 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const api_client_1 = __importDefault(require("./api-client"));
|
|
7
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
7
8
|
class InternalChatClient extends api_client_1.default {
|
|
8
|
-
async
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const { data: res } = await this.httpClient.get(url);
|
|
9
|
+
async createInternalChat(participants, isGroup = false, groupName = "") {
|
|
10
|
+
const body = { participants, isGroup, groupName };
|
|
11
|
+
const { data: res } = await this.httpClient.post(`/api/internal/chats`, body);
|
|
12
12
|
return res.data;
|
|
13
13
|
}
|
|
14
|
-
async
|
|
15
|
-
const url = `/api/internal/chats
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
async getInternalChatsBySession(token = null) {
|
|
15
|
+
const url = `/api/internal/session/chats`;
|
|
16
|
+
const headers = token
|
|
17
|
+
? { Authorization: `Bearer ${token}` }
|
|
18
|
+
: undefined;
|
|
19
|
+
const { data: res } = await this.httpClient.get(url, {
|
|
20
|
+
headers,
|
|
21
|
+
});
|
|
21
22
|
return res.data;
|
|
22
23
|
}
|
|
23
|
-
async sendMessageToChat(
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
async sendMessageToChat(data) {
|
|
25
|
+
const url = `/api/internal/chats/${data.chatId}/messages`;
|
|
26
|
+
const formData = new form_data_1.default();
|
|
27
|
+
formData.append("chatId", data.chatId.toString());
|
|
28
|
+
formData.append("text", data.text);
|
|
29
|
+
data.quotedId && formData.append("quotedId", data.quotedId.toString());
|
|
30
|
+
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
31
|
+
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
32
|
+
data.file && formData.append("file", data.file);
|
|
33
|
+
data.fileId && formData.append("fileId", data.fileId.toString());
|
|
34
|
+
await this.httpClient.post(url, formData, {
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "multipart/form-data",
|
|
37
|
+
},
|
|
26
38
|
});
|
|
27
|
-
return res;
|
|
28
|
-
}
|
|
29
|
-
async createGroup(name, participantIds, userId) {
|
|
30
|
-
const { data: res } = await this.httpClient.post(`/api/internal/chats/group?userId=${userId}`, { name, participantIds });
|
|
31
|
-
return res.data;
|
|
32
39
|
}
|
|
33
40
|
async updateGroupMembers(groupId, add, remove) {
|
|
34
41
|
const { data: res } = await this.httpClient.put(`/api/internal/chats/group/${groupId}/members`, { add, remove });
|
|
35
42
|
return res.data;
|
|
36
43
|
}
|
|
37
|
-
async
|
|
38
|
-
const url = `/api/internal/
|
|
39
|
-
const {
|
|
44
|
+
async startChatByContactId(contactId) {
|
|
45
|
+
const url = `/api/internal/chats`;
|
|
46
|
+
const body = { contactId };
|
|
47
|
+
const { data: res } = await this.httpClient.post(url, body);
|
|
40
48
|
return res.data;
|
|
41
49
|
}
|
|
42
50
|
setAuth(token) {
|
|
@@ -1,47 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface InternalContact {
|
|
3
|
-
id: number;
|
|
4
|
-
name: string;
|
|
5
|
-
phone: string;
|
|
6
|
-
userId?: number;
|
|
7
|
-
instance: string;
|
|
8
|
-
isDeleted: boolean;
|
|
9
|
-
isBlocked: boolean;
|
|
10
|
-
isOnlyAdmin: boolean;
|
|
11
|
-
}
|
|
1
|
+
import { WppMessageStatus } from "./whatsapp.types";
|
|
12
2
|
export interface InternalMessage {
|
|
13
3
|
id: number;
|
|
14
4
|
instance: string;
|
|
15
5
|
from: string;
|
|
16
|
-
to: string;
|
|
17
6
|
type: string;
|
|
18
|
-
quotedId
|
|
19
|
-
|
|
20
|
-
internalcontactId?: number | null;
|
|
7
|
+
quotedId: number | null;
|
|
8
|
+
internalChatId: number;
|
|
21
9
|
body: string;
|
|
22
10
|
timestamp: string;
|
|
23
|
-
status:
|
|
24
|
-
fileId
|
|
25
|
-
fileName
|
|
26
|
-
fileType
|
|
27
|
-
fileSize
|
|
11
|
+
status: WppMessageStatus;
|
|
12
|
+
fileId: number | null;
|
|
13
|
+
fileName: string | null;
|
|
14
|
+
fileType: string | null;
|
|
15
|
+
fileSize: string | null;
|
|
28
16
|
}
|
|
29
17
|
export interface InternalChat {
|
|
30
18
|
id: number;
|
|
31
19
|
instance: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
sectorId?: number | null;
|
|
35
|
-
avatarUrl?: string | null;
|
|
20
|
+
creatorId: number | null;
|
|
21
|
+
sectorId: number | null;
|
|
36
22
|
isFinished: boolean;
|
|
37
|
-
startedAt
|
|
38
|
-
finishedAt
|
|
39
|
-
finishedBy
|
|
23
|
+
startedAt: Date;
|
|
24
|
+
finishedAt: Date | null;
|
|
25
|
+
finishedBy: number | null;
|
|
40
26
|
isGroup: boolean;
|
|
41
|
-
groupName
|
|
42
|
-
groupDescription
|
|
43
|
-
groupCreatedBy?: number | null;
|
|
44
|
-
groupCreatedAt?: string | null;
|
|
27
|
+
groupName: string | null;
|
|
28
|
+
groupDescription: string | null;
|
|
45
29
|
}
|
|
46
30
|
export interface InternalChatMember {
|
|
47
31
|
internalchatId: number;
|
|
@@ -49,60 +33,12 @@ export interface InternalChatMember {
|
|
|
49
33
|
joinedAt: string;
|
|
50
34
|
lastReadAt?: string | null;
|
|
51
35
|
}
|
|
52
|
-
export interface InternalChatTag {
|
|
53
|
-
internalchatId: number;
|
|
54
|
-
tagId: number;
|
|
55
|
-
}
|
|
56
|
-
export interface InternalContactWithUser {
|
|
57
|
-
id: number;
|
|
58
|
-
name: string;
|
|
59
|
-
phone: string;
|
|
60
|
-
userId?: number;
|
|
61
|
-
instance: string;
|
|
62
|
-
isBlocked: boolean;
|
|
63
|
-
isOnlyAdmin: boolean;
|
|
64
|
-
user: User | null;
|
|
65
|
-
chatingWith: string | null;
|
|
66
|
-
}
|
|
67
|
-
export interface Sector {
|
|
68
|
-
id: number;
|
|
69
|
-
name: string;
|
|
70
|
-
instanceName: string;
|
|
71
|
-
wppInstanceId?: number;
|
|
72
|
-
startChats: boolean;
|
|
73
|
-
receiveChats: boolean;
|
|
74
|
-
}
|
|
75
|
-
export type InternalMessageStatus = "PENDING" | "SENT" | "RECEIVED" | "READ" | "DOWNLOADED" | "ERROR" | "REVOKED";
|
|
76
|
-
export declare enum InternalChatType {
|
|
77
|
-
RECEPTIVE = "RECEPTIVE",
|
|
78
|
-
ACTIVE = "ACTIVE"
|
|
79
|
-
}
|
|
80
|
-
export declare enum IntenalChatPriority {
|
|
81
|
-
LOW = "LOW",
|
|
82
|
-
NORMAL = "NORMAL",
|
|
83
|
-
HIGH = "HIGH",
|
|
84
|
-
VERY_HIGH = "VERY_HIGH",
|
|
85
|
-
URGENCY = "URGENCY"
|
|
86
|
-
}
|
|
87
|
-
export type InternalChatWithDetails = InternalChat & {
|
|
88
|
-
contact: InternalContact | null;
|
|
89
|
-
user: User | null;
|
|
90
|
-
};
|
|
91
|
-
export type InternalChatsAndMessages = {
|
|
92
|
-
chats: InternalChatWithDetails[];
|
|
93
|
-
messages: InternalMessage[];
|
|
94
|
-
};
|
|
95
|
-
export type InternalChatWithDetailsAndMessages = InternalChatWithDetails & {
|
|
96
|
-
messages: InternalMessage[];
|
|
97
|
-
};
|
|
98
36
|
export interface InternalSendMessageData {
|
|
99
|
-
sendAsChatOwner?: boolean;
|
|
100
37
|
sendAsAudio?: boolean;
|
|
101
38
|
sendAsDocument?: boolean;
|
|
102
|
-
contactId: number;
|
|
103
39
|
quotedId?: number | null;
|
|
104
|
-
chatId
|
|
105
|
-
text
|
|
40
|
+
chatId: number;
|
|
41
|
+
text: string;
|
|
106
42
|
file?: File;
|
|
107
43
|
fileId?: number;
|
|
108
44
|
}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IntenalChatPriority = exports.InternalChatType = void 0;
|
|
4
|
-
var InternalChatType;
|
|
5
|
-
(function (InternalChatType) {
|
|
6
|
-
InternalChatType["RECEPTIVE"] = "RECEPTIVE";
|
|
7
|
-
InternalChatType["ACTIVE"] = "ACTIVE";
|
|
8
|
-
})(InternalChatType || (exports.InternalChatType = InternalChatType = {}));
|
|
9
|
-
var IntenalChatPriority;
|
|
10
|
-
(function (IntenalChatPriority) {
|
|
11
|
-
IntenalChatPriority["LOW"] = "LOW";
|
|
12
|
-
IntenalChatPriority["NORMAL"] = "NORMAL";
|
|
13
|
-
IntenalChatPriority["HIGH"] = "HIGH";
|
|
14
|
-
IntenalChatPriority["VERY_HIGH"] = "VERY_HIGH";
|
|
15
|
-
IntenalChatPriority["URGENCY"] = "URGENCY";
|
|
16
|
-
})(IntenalChatPriority || (exports.IntenalChatPriority = IntenalChatPriority = {}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SocketServerAdminRoom, SocketServerChatRoom, SocketServerReportsRoom, SocketServerRoom } from "./socket-rooms.types";
|
|
1
|
+
import { SocketServerAdminRoom, SocketServerChatRoom, SocketServerInternalChatRoom, SocketServerReportsRoom, SocketServerRoom } from "./socket-rooms.types";
|
|
2
2
|
import { MessageResponse } from "./response.types";
|
|
3
3
|
import { WppMessage, WppMessageStatus } from "./whatsapp.types";
|
|
4
|
-
import {
|
|
4
|
+
import { InternalChat, InternalMessage } from "./internal.types";
|
|
5
5
|
export declare enum SocketEventType {
|
|
6
6
|
WppChatStarted = "wpp_chat_started",
|
|
7
7
|
WppChatFinished = "wpp_chat_finished",
|
|
@@ -27,8 +27,8 @@ export interface EmitSocketEventFn {
|
|
|
27
27
|
(type: SocketEventType.WppContactMessagesRead, room: SocketServerChatRoom, data: WppContactMessagesReadEventData): Promise<MessageResponse>;
|
|
28
28
|
(type: SocketEventType.WppMessageReaction, room: SocketServerChatRoom, data: WppMessageReactionEventData): Promise<MessageResponse>;
|
|
29
29
|
(type: SocketEventType.ReportStatus, room: SocketServerReportsRoom, data: ReportStatusEventData): Promise<MessageResponse>;
|
|
30
|
-
(type: SocketEventType.InternalMessage, room:
|
|
31
|
-
(type: SocketEventType.InternalMessageStatus, room:
|
|
30
|
+
(type: SocketEventType.InternalMessage, room: SocketServerInternalChatRoom, data: InternalMessageEventData): Promise<MessageResponse>;
|
|
31
|
+
(type: SocketEventType.InternalMessageStatus, room: SocketServerInternalChatRoom, data: InternalMessageEventData): Promise<MessageResponse>;
|
|
32
32
|
(type: SocketEventType.InternalChatStarted, room: SocketServerRoom, data: InternalChatStartedEventData): Promise<MessageResponse>;
|
|
33
33
|
(type: SocketEventType.InternalChatFinished, room: SocketServerRoom, data: InternalChatFinishedEventData): Promise<MessageResponse>;
|
|
34
34
|
}
|
|
@@ -81,7 +81,9 @@ export interface WppMessageReactionEventData {
|
|
|
81
81
|
reaction: string;
|
|
82
82
|
}
|
|
83
83
|
export interface InternalChatStartedEventData {
|
|
84
|
-
|
|
84
|
+
chat: InternalChat & {
|
|
85
|
+
participants: number[];
|
|
86
|
+
};
|
|
85
87
|
}
|
|
86
88
|
export interface InternalChatFinishedEventData {
|
|
87
89
|
chatId: number;
|
|
@@ -93,9 +95,9 @@ export interface InternalMessageEventData {
|
|
|
93
95
|
message: InternalMessage;
|
|
94
96
|
}
|
|
95
97
|
export interface InternalMessageStatusEventData {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
status:
|
|
98
|
+
chatId: number;
|
|
99
|
+
internalMessageId: number;
|
|
100
|
+
status: WppMessageStatus;
|
|
99
101
|
}
|
|
100
102
|
export type ReportStatusEventData = {
|
|
101
103
|
id: number;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
type ReportType = "chats";
|
|
2
|
-
type
|
|
2
|
+
type ChatId = number;
|
|
3
|
+
type InternalChatId = number;
|
|
3
4
|
type WalletId = number;
|
|
4
5
|
type UserId = number;
|
|
5
6
|
type SectorId = number;
|
|
6
7
|
type InstanceName = string;
|
|
7
|
-
export type SocketClientChatRoom = `chat:${
|
|
8
|
+
export type SocketClientChatRoom = `chat:${ChatId}`;
|
|
8
9
|
export type SocketClientAdminRoom = "admin";
|
|
9
10
|
export type SocketClientMonitorRoom = `monitor`;
|
|
10
11
|
export type SocketClientReportsRoom = `reports:${ReportType}`;
|
|
11
12
|
export type SocketClientWalletRoom = `wallet:${WalletId}`;
|
|
12
13
|
export type SocketClientUserRoom = `user:${UserId}`;
|
|
13
|
-
export type
|
|
14
|
+
export type SocketClientInternalChatRoom = `internal-chat:${InternalChatId}`;
|
|
15
|
+
export type SocketClientRoom = SocketClientChatRoom | SocketClientAdminRoom | SocketClientReportsRoom | SocketClientMonitorRoom | SocketClientWalletRoom | SocketClientUserRoom | SocketClientInternalChatRoom;
|
|
14
16
|
type SocketRoomWithInstance<T extends string> = `${InstanceName}:${T}`;
|
|
15
17
|
type SocketRoomWithSector<T extends string> = SocketRoomWithInstance<`${SectorId}:${T}`>;
|
|
16
18
|
export type SocketServerAdminRoom = SocketRoomWithSector<SocketClientAdminRoom>;
|
|
@@ -19,7 +21,8 @@ export type SocketServerReportsRoom = SocketRoomWithSector<SocketClientReportsRo
|
|
|
19
21
|
export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
|
|
20
22
|
export type SocketServerWalletRoom = SocketRoomWithInstance<SocketClientWalletRoom>;
|
|
21
23
|
export type SocketServerUserRoom = SocketRoomWithInstance<SocketClientUserRoom>;
|
|
22
|
-
export type
|
|
24
|
+
export type SocketServerInternalChatRoom = SocketRoomWithInstance<SocketClientInternalChatRoom>;
|
|
25
|
+
export type SocketServerRoom = SocketServerChatRoom | SocketServerAdminRoom | SocketServerMonitorRoom | SocketServerReportsRoom | SocketServerWalletRoom | SocketServerUserRoom | SocketServerInternalChatRoom;
|
|
23
26
|
export interface JoinRoomFn {
|
|
24
27
|
(room: SocketClientRoom): void;
|
|
25
28
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
2
|
import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
3
3
|
export default class WhatsappClient extends ApiClient {
|
|
4
|
-
getChatsBySession(messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
|
|
4
|
+
getChatsBySession(messages?: boolean, contact?: boolean, token?: string | null): 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[]>;
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const api_client_1 = __importDefault(require("./api-client"));
|
|
7
7
|
const form_data_1 = __importDefault(require("form-data"));
|
|
8
8
|
class WhatsappClient extends api_client_1.default {
|
|
9
|
-
async getChatsBySession(messages = false, contact = false) {
|
|
9
|
+
async getChatsBySession(messages = false, contact = false, token = null) {
|
|
10
|
+
const headers = token
|
|
11
|
+
? { Authorization: `Bearer ${token}` }
|
|
12
|
+
: undefined;
|
|
10
13
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const { data: res } = await this.httpClient.get(url, {
|
|
15
|
+
headers,
|
|
16
|
+
});
|
|
13
17
|
return res.data;
|
|
14
18
|
}
|
|
15
19
|
async getChatById(id) {
|
package/package.json
CHANGED
package/src/internal.client.ts
CHANGED
|
@@ -1,67 +1,97 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
2
|
import { DataResponse } from "./types/response.types";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
InternalChat,
|
|
5
|
+
InternalMessage,
|
|
6
|
+
InternalSendMessageData,
|
|
7
|
+
} from "./types/internal.types";
|
|
8
|
+
import FormData from "form-data";
|
|
4
9
|
|
|
5
|
-
type GetChatsResponse = DataResponse<
|
|
10
|
+
type GetChatsResponse = DataResponse<{
|
|
11
|
+
chats: (InternalChat & { participants: number[] })[];
|
|
12
|
+
messages: InternalMessage[];
|
|
13
|
+
}>;
|
|
14
|
+
type StartChatResponse = DataResponse<{
|
|
15
|
+
chat: InternalChat & { messages: InternalMessage[] };
|
|
16
|
+
}>;
|
|
6
17
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.log(this.httpClient.defaults.headers.common["Authorization"]);
|
|
15
|
-
const { data: res } = await this.httpClient.get<GetChatsResponse>(url);
|
|
16
|
-
|
|
17
|
-
return res.data;
|
|
18
|
-
}
|
|
19
|
-
public async getChatsForUser(userId: number, instance: string) {
|
|
20
|
-
const url = `/api/internal/chats?userId=${userId}&instance=${instance}`;
|
|
21
|
-
const { data: res } = await this.httpClient.get<DataResponse<InternalChat[]>>(url);
|
|
22
|
-
return res.data;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public async getChatById(id: number) {
|
|
26
|
-
const { data: res } = await this.httpClient.get<DataResponse<InternalChat>>(`/api/internal/chats/${id}`);
|
|
27
|
-
return res.data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async sendMessageToChat(chatId: number, userId: number, content: string) {
|
|
31
|
-
const { data: res } = await this.httpClient.post(`/api/internal/chats/${chatId}/messages?userId=${userId}`, {
|
|
32
|
-
content,
|
|
33
|
-
});
|
|
34
|
-
return res;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public async createGroup(name: string, participantIds: number[], userId: number) {
|
|
38
|
-
const { data: res } = await this.httpClient.post<DataResponse<InternalChat>>(
|
|
39
|
-
`/api/internal/chats/group?userId=${userId}`,
|
|
40
|
-
{ name, participantIds }
|
|
41
|
-
);
|
|
42
|
-
return res.data;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public async updateGroupMembers(groupId: number, add: number[], remove: number[]) {
|
|
46
|
-
const { data: res } = await this.httpClient.put<DataResponse<any>>(
|
|
47
|
-
`/api/internal/chats/group/${groupId}/members`,
|
|
48
|
-
{ add, remove }
|
|
49
|
-
);
|
|
50
|
-
return res.data;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async getContactsWithUser() {
|
|
54
|
-
const url = `/api/internal/contacts`;
|
|
55
|
-
const { data: res } =
|
|
56
|
-
await this.httpClient.get<DataResponse<InternalContactWithUser[]>>(
|
|
57
|
-
url,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return res.data;
|
|
61
|
-
}
|
|
18
|
+
export default class InternalChatClient extends ApiClient {
|
|
19
|
+
public async createInternalChat(
|
|
20
|
+
participants: number[],
|
|
21
|
+
isGroup: boolean = false,
|
|
22
|
+
groupName: string = "",
|
|
23
|
+
) {
|
|
24
|
+
const body = { participants, isGroup, groupName };
|
|
62
25
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
26
|
+
const { data: res } = await this.httpClient.post<
|
|
27
|
+
DataResponse<InternalChat>
|
|
28
|
+
>(`/api/internal/chats`, body);
|
|
29
|
+
|
|
30
|
+
return res.data;
|
|
31
|
+
}
|
|
32
|
+
public async getInternalChatsBySession(token: string | null = null) {
|
|
33
|
+
const url = `/api/internal/session/chats`;
|
|
34
|
+
|
|
35
|
+
const headers = token
|
|
36
|
+
? { Authorization: `Bearer ${token}` }
|
|
37
|
+
: undefined;
|
|
38
|
+
|
|
39
|
+
const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
|
|
40
|
+
headers,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return res.data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async sendMessageToChat(data: InternalSendMessageData) {
|
|
47
|
+
const url = `/api/internal/chats/${data.chatId}/messages`;
|
|
48
|
+
const formData = new FormData();
|
|
49
|
+
|
|
50
|
+
formData.append("chatId", data.chatId.toString());
|
|
51
|
+
formData.append("text", data.text);
|
|
52
|
+
data.quotedId && formData.append("quotedId", data.quotedId.toString());
|
|
53
|
+
data.sendAsAudio && formData.append("sendAsAudio", "true");
|
|
54
|
+
data.sendAsDocument && formData.append("sendAsDocument", "true");
|
|
55
|
+
data.file && formData.append("file", data.file);
|
|
56
|
+
data.fileId && formData.append("fileId", data.fileId.toString());
|
|
57
|
+
|
|
58
|
+
await this.httpClient.post<DataResponse<InternalMessage>>(
|
|
59
|
+
url,
|
|
60
|
+
formData,
|
|
61
|
+
{
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "multipart/form-data",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public async updateGroupMembers(
|
|
70
|
+
groupId: number,
|
|
71
|
+
add: number[],
|
|
72
|
+
remove: number[],
|
|
73
|
+
) {
|
|
74
|
+
const { data: res } = await this.httpClient.put<DataResponse<any>>(
|
|
75
|
+
`/api/internal/chats/group/${groupId}/members`,
|
|
76
|
+
{ add, remove },
|
|
77
|
+
);
|
|
78
|
+
return res.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async startChatByContactId(contactId: number) {
|
|
82
|
+
const url = `/api/internal/chats`;
|
|
83
|
+
const body = { contactId };
|
|
84
|
+
|
|
85
|
+
const { data: res } = await this.httpClient.post<StartChatResponse>(
|
|
86
|
+
url,
|
|
87
|
+
body,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return res.data;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public setAuth(token: string) {
|
|
94
|
+
this.httpClient.defaults.headers.common["Authorization"] =
|
|
95
|
+
`Bearer ${token}`;
|
|
96
|
+
}
|
|
67
97
|
}
|
|
@@ -1,50 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface InternalContact {
|
|
4
|
-
id: number;
|
|
5
|
-
name: string;
|
|
6
|
-
phone: string;
|
|
7
|
-
userId?: number;
|
|
8
|
-
instance: string;
|
|
9
|
-
isDeleted: boolean;
|
|
10
|
-
isBlocked: boolean;
|
|
11
|
-
isOnlyAdmin: boolean;
|
|
12
|
-
}
|
|
1
|
+
import { WppMessageStatus } from "./whatsapp.types";
|
|
13
2
|
|
|
14
3
|
export interface InternalMessage {
|
|
15
4
|
id: number;
|
|
16
5
|
instance: string;
|
|
17
6
|
from: string;
|
|
18
|
-
to: string;
|
|
19
7
|
type: string;
|
|
20
|
-
quotedId
|
|
21
|
-
|
|
22
|
-
internalcontactId?: number | null;
|
|
8
|
+
quotedId: number | null;
|
|
9
|
+
internalChatId: number;
|
|
23
10
|
body: string;
|
|
24
|
-
timestamp: string;
|
|
25
|
-
status:
|
|
26
|
-
fileId
|
|
27
|
-
fileName
|
|
28
|
-
fileType
|
|
29
|
-
fileSize
|
|
11
|
+
timestamp: string;
|
|
12
|
+
status: WppMessageStatus;
|
|
13
|
+
fileId: number | null;
|
|
14
|
+
fileName: string | null;
|
|
15
|
+
fileType: string | null;
|
|
16
|
+
fileSize: string | null;
|
|
30
17
|
}
|
|
31
18
|
|
|
32
19
|
export interface InternalChat {
|
|
33
20
|
id: number;
|
|
34
21
|
instance: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
sectorId?: number | null;
|
|
38
|
-
avatarUrl?: string | null;
|
|
22
|
+
creatorId: number | null;
|
|
23
|
+
sectorId: number | null;
|
|
39
24
|
isFinished: boolean;
|
|
40
|
-
startedAt
|
|
41
|
-
finishedAt
|
|
42
|
-
finishedBy
|
|
25
|
+
startedAt: Date;
|
|
26
|
+
finishedAt: Date | null;
|
|
27
|
+
finishedBy: number | null;
|
|
43
28
|
isGroup: boolean;
|
|
44
|
-
groupName
|
|
45
|
-
groupDescription
|
|
46
|
-
groupCreatedBy?: number | null;
|
|
47
|
-
groupCreatedAt?: string | null;
|
|
29
|
+
groupName: string | null;
|
|
30
|
+
groupDescription: string | null;
|
|
48
31
|
}
|
|
49
32
|
|
|
50
33
|
export interface InternalChatMember {
|
|
@@ -54,74 +37,12 @@ export interface InternalChatMember {
|
|
|
54
37
|
lastReadAt?: string | null;
|
|
55
38
|
}
|
|
56
39
|
|
|
57
|
-
export interface InternalChatTag {
|
|
58
|
-
internalchatId: number;
|
|
59
|
-
tagId: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface InternalContactWithUser {
|
|
63
|
-
id: number;
|
|
64
|
-
name: string;
|
|
65
|
-
phone: string;
|
|
66
|
-
userId?: number;
|
|
67
|
-
instance: string;
|
|
68
|
-
isBlocked: boolean;
|
|
69
|
-
isOnlyAdmin: boolean;
|
|
70
|
-
user: User | null;
|
|
71
|
-
chatingWith: string | null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface Sector {
|
|
75
|
-
id: number;
|
|
76
|
-
name: string;
|
|
77
|
-
instanceName: string;
|
|
78
|
-
wppInstanceId?: number;
|
|
79
|
-
startChats: boolean;
|
|
80
|
-
receiveChats: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export type InternalMessageStatus =
|
|
84
|
-
| "PENDING"
|
|
85
|
-
| "SENT"
|
|
86
|
-
| "RECEIVED"
|
|
87
|
-
| "READ"
|
|
88
|
-
| "DOWNLOADED"
|
|
89
|
-
| "ERROR"
|
|
90
|
-
| "REVOKED";
|
|
91
|
-
|
|
92
|
-
export enum InternalChatType {
|
|
93
|
-
RECEPTIVE = "RECEPTIVE",
|
|
94
|
-
ACTIVE = "ACTIVE",
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export enum IntenalChatPriority {
|
|
98
|
-
LOW = "LOW",
|
|
99
|
-
NORMAL = "NORMAL",
|
|
100
|
-
HIGH = "HIGH",
|
|
101
|
-
VERY_HIGH = "VERY_HIGH",
|
|
102
|
-
URGENCY = "URGENCY",
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export type InternalChatWithDetails = InternalChat & {
|
|
106
|
-
contact: InternalContact | null;
|
|
107
|
-
user: User | null;
|
|
108
|
-
};
|
|
109
|
-
export type InternalChatsAndMessages = {
|
|
110
|
-
chats: InternalChatWithDetails[];
|
|
111
|
-
messages: InternalMessage[];
|
|
112
|
-
};
|
|
113
|
-
export type InternalChatWithDetailsAndMessages = InternalChatWithDetails & {
|
|
114
|
-
messages: InternalMessage[];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
40
|
export interface InternalSendMessageData {
|
|
118
|
-
sendAsChatOwner?: boolean;
|
|
119
41
|
sendAsAudio?: boolean;
|
|
120
42
|
sendAsDocument?: boolean;
|
|
121
|
-
contactId: number;
|
|
122
43
|
quotedId?: number | null;
|
|
123
|
-
chatId
|
|
124
|
-
text
|
|
44
|
+
chatId: number;
|
|
45
|
+
text: string;
|
|
125
46
|
file?: File;
|
|
126
47
|
fileId?: number;
|
|
127
48
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SocketServerAdminRoom,
|
|
3
3
|
SocketServerChatRoom,
|
|
4
|
+
SocketServerInternalChatRoom,
|
|
4
5
|
SocketServerReportsRoom,
|
|
5
6
|
SocketServerRoom,
|
|
6
7
|
} from "./socket-rooms.types";
|
|
7
8
|
import { MessageResponse } from "./response.types";
|
|
8
9
|
import { WppMessage, WppMessageStatus } from "./whatsapp.types";
|
|
9
|
-
import {
|
|
10
|
+
import { InternalChat, InternalMessage } from "./internal.types";
|
|
10
11
|
|
|
11
12
|
export enum SocketEventType {
|
|
12
13
|
WppChatStarted = "wpp_chat_started",
|
|
@@ -26,59 +27,59 @@ export enum SocketEventType {
|
|
|
26
27
|
|
|
27
28
|
export interface EmitSocketEventFn {
|
|
28
29
|
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
type: SocketEventType.WwebjsQr,
|
|
31
|
+
room: SocketServerAdminRoom,
|
|
32
|
+
data: WWEBJSQrEventData,
|
|
32
33
|
): Promise<MessageResponse>;
|
|
33
34
|
(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
type: SocketEventType.WwebjsAuth,
|
|
36
|
+
room: SocketServerAdminRoom,
|
|
37
|
+
data: WWEBJSAuthEventData,
|
|
37
38
|
): Promise<MessageResponse>;
|
|
38
39
|
(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
type: SocketEventType.WppChatStarted,
|
|
41
|
+
room: SocketServerRoom,
|
|
42
|
+
data: WppChatStartedEventData,
|
|
42
43
|
): Promise<MessageResponse>;
|
|
43
44
|
(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
type: SocketEventType.WppChatFinished,
|
|
46
|
+
room: SocketServerRoom,
|
|
47
|
+
data: WppChatFinishedEventData,
|
|
47
48
|
): Promise<MessageResponse>;
|
|
48
49
|
(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
type: SocketEventType.WppMessage,
|
|
51
|
+
room: SocketServerChatRoom,
|
|
52
|
+
data: WppMessageEventData,
|
|
52
53
|
): Promise<MessageResponse>;
|
|
53
54
|
(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
type: SocketEventType.WppMessageStatus,
|
|
56
|
+
room: SocketServerChatRoom,
|
|
57
|
+
data: WppMessageStatusEventData,
|
|
57
58
|
): Promise<MessageResponse>;
|
|
58
59
|
(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
type: SocketEventType.WppContactMessagesRead,
|
|
61
|
+
room: SocketServerChatRoom,
|
|
62
|
+
data: WppContactMessagesReadEventData,
|
|
62
63
|
): Promise<MessageResponse>;
|
|
63
64
|
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
type: SocketEventType.WppMessageReaction,
|
|
66
|
+
room: SocketServerChatRoom,
|
|
67
|
+
data: WppMessageReactionEventData,
|
|
67
68
|
): Promise<MessageResponse>;
|
|
68
69
|
(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
type: SocketEventType.ReportStatus,
|
|
71
|
+
room: SocketServerReportsRoom,
|
|
72
|
+
data: ReportStatusEventData,
|
|
72
73
|
): Promise<MessageResponse>;
|
|
73
74
|
(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
type: SocketEventType.InternalMessage,
|
|
76
|
+
room: SocketServerInternalChatRoom,
|
|
77
|
+
data: InternalMessageEventData,
|
|
77
78
|
): Promise<MessageResponse>;
|
|
78
79
|
(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
type: SocketEventType.InternalMessageStatus,
|
|
81
|
+
room: SocketServerInternalChatRoom,
|
|
82
|
+
data: InternalMessageEventData,
|
|
82
83
|
): Promise<MessageResponse>;
|
|
83
84
|
(
|
|
84
85
|
type: SocketEventType.InternalChatStarted,
|
|
@@ -94,56 +95,56 @@ export interface EmitSocketEventFn {
|
|
|
94
95
|
|
|
95
96
|
export interface ListenSocketEventFn {
|
|
96
97
|
(
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
type: SocketEventType.WwebjsQr,
|
|
99
|
+
callback: (data: WWEBJSQrEventData) => void,
|
|
99
100
|
): void;
|
|
100
101
|
(
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
type: SocketEventType.WwebjsAuth,
|
|
103
|
+
callback: (data: WWEBJSAuthEventData) => void,
|
|
103
104
|
): void;
|
|
104
105
|
(
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
type: SocketEventType.WppChatStarted,
|
|
107
|
+
callback: (data: WppChatStartedEventData) => void,
|
|
107
108
|
): void;
|
|
108
109
|
(
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
type: SocketEventType.WppChatFinished,
|
|
111
|
+
callback: (data: WppChatFinishedEventData) => void,
|
|
111
112
|
): void;
|
|
112
113
|
(
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
type: SocketEventType.WppMessage,
|
|
115
|
+
callback: (data: WppMessageEventData) => void,
|
|
115
116
|
): void;
|
|
116
117
|
(
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
type: SocketEventType.WppMessageStatus,
|
|
119
|
+
callback: (data: WppMessageStatusEventData) => void,
|
|
119
120
|
): void;
|
|
120
121
|
(
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
type: SocketEventType.WppContactMessagesRead,
|
|
123
|
+
callback: (data: WppContactMessagesReadEventData) => void,
|
|
123
124
|
): void;
|
|
124
125
|
(
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
type: SocketEventType.WppMessageReaction,
|
|
127
|
+
callback: (data: WppMessageReactionEventData) => void,
|
|
127
128
|
): void;
|
|
128
129
|
(
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
type: SocketEventType.ReportStatus,
|
|
131
|
+
callback: (data: ReportStatusEventData) => void,
|
|
131
132
|
): void;
|
|
132
133
|
(
|
|
133
134
|
type: SocketEventType.InternalChatStarted,
|
|
134
135
|
callback: (data: InternalChatStartedEventData) => void,
|
|
135
136
|
): void;
|
|
136
137
|
(
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
type: SocketEventType.InternalChatFinished,
|
|
139
|
+
callback: (data: InternalChatFinishedEventData) => void,
|
|
139
140
|
): void;
|
|
140
141
|
(
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
type: SocketEventType.InternalMessage,
|
|
143
|
+
callback: (data: InternalMessageEventData) => void,
|
|
143
144
|
): void;
|
|
144
145
|
(
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
type: SocketEventType.InternalMessageStatus,
|
|
147
|
+
callback: (data: InternalMessageStatusEventData) => void,
|
|
147
148
|
): void;
|
|
148
149
|
}
|
|
149
150
|
|
|
@@ -183,7 +184,7 @@ export interface WppMessageReactionEventData {
|
|
|
183
184
|
reaction: string;
|
|
184
185
|
}
|
|
185
186
|
export interface InternalChatStartedEventData {
|
|
186
|
-
|
|
187
|
+
chat: InternalChat & { participants: number[] };
|
|
187
188
|
}
|
|
188
189
|
export interface InternalChatFinishedEventData {
|
|
189
190
|
chatId: number;
|
|
@@ -195,10 +196,11 @@ export interface InternalMessageEventData {
|
|
|
195
196
|
message: InternalMessage;
|
|
196
197
|
}
|
|
197
198
|
export interface InternalMessageStatusEventData {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
status:
|
|
199
|
+
chatId: number;
|
|
200
|
+
internalMessageId: number;
|
|
201
|
+
status: WppMessageStatus;
|
|
201
202
|
}
|
|
203
|
+
|
|
202
204
|
export type ReportStatusEventData = {
|
|
203
205
|
id: number;
|
|
204
206
|
type: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/types/socket-rooms.types.ts
|
|
2
2
|
type ReportType = "chats";
|
|
3
|
-
type
|
|
3
|
+
type ChatId = number;
|
|
4
|
+
type InternalChatId = number;
|
|
4
5
|
type WalletId = number;
|
|
5
6
|
type UserId = number;
|
|
6
7
|
type SectorId = number;
|
|
@@ -11,19 +12,21 @@ type InstanceName = string;
|
|
|
11
12
|
Essas salas omitem o nome da instancia e/ou id do setor,
|
|
12
13
|
pois isso é controlado pelo servidor;
|
|
13
14
|
*/
|
|
14
|
-
export type SocketClientChatRoom = `chat:${
|
|
15
|
+
export type SocketClientChatRoom = `chat:${ChatId}`;
|
|
15
16
|
export type SocketClientAdminRoom = "admin";
|
|
16
17
|
export type SocketClientMonitorRoom = `monitor`;
|
|
17
18
|
export type SocketClientReportsRoom = `reports:${ReportType}`;
|
|
18
19
|
export type SocketClientWalletRoom = `wallet:${WalletId}`;
|
|
19
20
|
export type SocketClientUserRoom = `user:${UserId}`;
|
|
21
|
+
export type SocketClientInternalChatRoom = `internal-chat:${InternalChatId}`;
|
|
20
22
|
export type SocketClientRoom =
|
|
21
23
|
| SocketClientChatRoom
|
|
22
24
|
| SocketClientAdminRoom
|
|
23
25
|
| SocketClientReportsRoom
|
|
24
26
|
| SocketClientMonitorRoom
|
|
25
27
|
| SocketClientWalletRoom
|
|
26
|
-
| SocketClientUserRoom
|
|
28
|
+
| SocketClientUserRoom
|
|
29
|
+
| SocketClientInternalChatRoom;
|
|
27
30
|
|
|
28
31
|
// Interface que incluí o nome da instancia na sala de socket;
|
|
29
32
|
type SocketRoomWithInstance<T extends string> = `${InstanceName}:${T}`;
|
|
@@ -44,15 +47,19 @@ export type SocketServerMonitorRoom =
|
|
|
44
47
|
export type SocketServerReportsRoom =
|
|
45
48
|
SocketRoomWithSector<SocketClientReportsRoom>;
|
|
46
49
|
export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
|
|
47
|
-
export type SocketServerWalletRoom =
|
|
50
|
+
export type SocketServerWalletRoom =
|
|
51
|
+
SocketRoomWithInstance<SocketClientWalletRoom>;
|
|
48
52
|
export type SocketServerUserRoom = SocketRoomWithInstance<SocketClientUserRoom>;
|
|
53
|
+
export type SocketServerInternalChatRoom =
|
|
54
|
+
SocketRoomWithInstance<SocketClientInternalChatRoom>;
|
|
49
55
|
export type SocketServerRoom =
|
|
50
56
|
| SocketServerChatRoom
|
|
51
57
|
| SocketServerAdminRoom
|
|
52
58
|
| SocketServerMonitorRoom
|
|
53
59
|
| SocketServerReportsRoom
|
|
54
60
|
| SocketServerWalletRoom
|
|
55
|
-
| SocketServerUserRoom
|
|
61
|
+
| SocketServerUserRoom
|
|
62
|
+
| SocketServerInternalChatRoom;
|
|
56
63
|
|
|
57
64
|
export interface JoinRoomFn {
|
|
58
65
|
(room: SocketClientRoom): void;
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -20,11 +20,16 @@ export default class WhatsappClient extends ApiClient {
|
|
|
20
20
|
public async getChatsBySession(
|
|
21
21
|
messages = false,
|
|
22
22
|
contact = false,
|
|
23
|
+
token: string | null = null,
|
|
23
24
|
) {
|
|
25
|
+
const headers = token
|
|
26
|
+
? { Authorization: `Bearer ${token}` }
|
|
27
|
+
: undefined;
|
|
24
28
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
|
|
31
|
+
headers,
|
|
32
|
+
});
|
|
28
33
|
|
|
29
34
|
return res.data;
|
|
30
35
|
}
|
|
@@ -64,8 +69,8 @@ export default class WhatsappClient extends ApiClient {
|
|
|
64
69
|
|
|
65
70
|
public async sendMessage(to: string, data: SendMessageData) {
|
|
66
71
|
const url = "/api/whatsapp/messages";
|
|
67
|
-
|
|
68
72
|
const formData = new FormData();
|
|
73
|
+
|
|
69
74
|
formData.append("to", to);
|
|
70
75
|
data.text && formData.append("text", data.text);
|
|
71
76
|
data.file && formData.append("file", data.file);
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
4
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
5
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
6
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
7
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
8
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
9
|
-
"noUnusedLocals": false,
|
|
10
|
-
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
11
|
-
"declaration": true
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"src/index.ts",
|
|
15
|
-
"src/**/*.{ts}"
|
|
16
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
4
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
|
5
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
6
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
7
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
8
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
9
|
+
"noUnusedLocals": false,
|
|
10
|
+
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/index.ts",
|
|
15
|
+
"src/**/*.{ts}"
|
|
16
|
+
]
|
|
17
17
|
}
|