@raphaelvserafim/client-api-whatsapp 1.0.8 → 1.2.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/README.md +512 -297
- package/dist/WhatsApp.d.ts +142 -31
- package/dist/WhatsApp.js +111 -167
- package/dist/WhatsApp.js.map +1 -1
- package/dist/client/HttpClient.d.ts +6 -0
- package/dist/client/HttpClient.js +29 -0
- package/dist/client/HttpClient.js.map +1 -0
- package/dist/client/IHttpClient.d.ts +9 -0
- package/dist/client/IHttpClient.js +3 -0
- package/dist/client/IHttpClient.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/dist/services/ActionService.d.ts +9 -0
- package/dist/services/ActionService.js +32 -0
- package/dist/services/ActionService.js.map +1 -0
- package/dist/services/BusinessService.d.ts +10 -0
- package/dist/services/BusinessService.js +43 -0
- package/dist/services/BusinessService.js.map +1 -0
- package/dist/services/CallService.d.ts +8 -0
- package/dist/services/CallService.js +24 -0
- package/dist/services/CallService.js.map +1 -0
- package/dist/services/ChatService.d.ts +16 -0
- package/dist/services/ChatService.js +38 -0
- package/dist/services/ChatService.js.map +1 -0
- package/dist/services/CommunityService.d.ts +28 -0
- package/dist/services/CommunityService.js +76 -0
- package/dist/services/CommunityService.js.map +1 -0
- package/dist/services/ContactService.d.ts +15 -0
- package/dist/services/ContactService.js +30 -0
- package/dist/services/ContactService.js.map +1 -0
- package/dist/services/GroupService.d.ts +32 -0
- package/dist/services/GroupService.js +104 -0
- package/dist/services/GroupService.js.map +1 -0
- package/dist/services/InstanceService.d.ts +28 -0
- package/dist/services/InstanceService.js +124 -0
- package/dist/services/InstanceService.js.map +1 -0
- package/dist/services/LabelService.d.ts +17 -0
- package/dist/services/LabelService.js +43 -0
- package/dist/services/LabelService.js.map +1 -0
- package/dist/services/MessageService.d.ts +51 -0
- package/dist/services/MessageService.js +106 -0
- package/dist/services/MessageService.js.map +1 -0
- package/dist/types/index.d.ts +155 -11
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +6 -11
- package/.babelrc +0 -3
- package/dist/exemple.d.ts +0 -1
- package/dist/exemple.js +0 -264
- package/dist/exemple.js.map +0 -1
- package/src/WhatsApp.ts +0 -245
- package/src/exemple.ts +0 -312
- package/src/index.ts +0 -2
- package/src/types/index.ts +0 -190
- package/tsconfig.compile.json +0 -15
- package/tsconfig.json +0 -35
package/dist/WhatsApp.d.ts
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
|
-
import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot, Connect,
|
|
1
|
+
import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section, Location, Buttons, Items, HeaderMedia, DownloadableMessage, Product, CommunityCreate, CommunityUpdate, GroupParticipantsAction, ApiResponse, PairingCodeResponse, MobileRegisterData, EventData, InfoInstance, SendMessageRoot, Connect, RegisteredResponse, ContactInfo, GroupInfo, InviteCodeResponse, ChatInfo, LabelInfo, CommunityInfo, CatalogResponse, WebhookStatistics, ListMessagesResponse, DownloadMediaResponse, CallResponse, MessageData, GroupParticipant } from './types';
|
|
2
|
+
import { IHttpClient } from './client/IHttpClient';
|
|
3
|
+
import { InstanceService } from './services/InstanceService';
|
|
4
|
+
import { MessageService } from './services/MessageService';
|
|
5
|
+
import { ChatService } from './services/ChatService';
|
|
6
|
+
import { CallService } from './services/CallService';
|
|
7
|
+
import { LabelService } from './services/LabelService';
|
|
8
|
+
import { ActionService } from './services/ActionService';
|
|
9
|
+
import { ContactService } from './services/ContactService';
|
|
10
|
+
import { GroupService } from './services/GroupService';
|
|
11
|
+
import { CommunityService } from './services/CommunityService';
|
|
12
|
+
import { BusinessService } from './services/BusinessService';
|
|
2
13
|
export declare class WhatsApp {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
readonly instance: InstanceService;
|
|
15
|
+
readonly message: MessageService;
|
|
16
|
+
readonly chat: ChatService;
|
|
17
|
+
readonly call: CallService;
|
|
18
|
+
readonly label: LabelService;
|
|
19
|
+
readonly action: ActionService;
|
|
20
|
+
readonly contact: ContactService;
|
|
21
|
+
readonly group: GroupService;
|
|
22
|
+
readonly community: CommunityService;
|
|
23
|
+
readonly business: BusinessService;
|
|
24
|
+
constructor(data: Init, httpClient?: IHttpClient);
|
|
10
25
|
connect(): Promise<Connect>;
|
|
11
26
|
info(): Promise<InfoInstance>;
|
|
12
|
-
logout(): Promise<
|
|
13
|
-
setting(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
logout(): Promise<ApiResponse>;
|
|
28
|
+
setting(data: {
|
|
29
|
+
markMessageRead: boolean;
|
|
30
|
+
saveMedia: boolean;
|
|
31
|
+
receiveStatusMessage: boolean;
|
|
32
|
+
receivePresence: boolean;
|
|
33
|
+
}): Promise<ApiResponse>;
|
|
34
|
+
updateWebhook(body: WebhookBody): Promise<ApiResponse>;
|
|
35
|
+
pairingCode(phoneNumber: string): Promise<PairingCodeResponse>;
|
|
36
|
+
addMongoDb(uri: string, dbName: string): Promise<ApiResponse>;
|
|
37
|
+
setProxy(proxy: string): Promise<ApiResponse>;
|
|
38
|
+
restart(): Promise<ApiResponse>;
|
|
39
|
+
updateProfileStatus(text: string): Promise<ApiResponse>;
|
|
40
|
+
updateProfilePicture(url: string): Promise<ApiResponse>;
|
|
41
|
+
removeProfilePicture(): Promise<ApiResponse>;
|
|
42
|
+
updateProfileName(name: string): Promise<ApiResponse>;
|
|
43
|
+
mobileRegisterPrepare(data: MobileRegisterData): Promise<ApiResponse>;
|
|
44
|
+
mobileRequestCode(method: string): Promise<ApiResponse>;
|
|
45
|
+
mobileVerifyCode(code: string): Promise<ApiResponse>;
|
|
46
|
+
webhookStatistics(): Promise<WebhookStatistics>;
|
|
47
|
+
listMessages(phoneNumber: string, page?: number, limit?: number): Promise<ListMessagesResponse>;
|
|
18
48
|
sendMessage(data: {
|
|
19
49
|
type: TypeMessage;
|
|
20
50
|
body: {
|
|
21
51
|
to: string;
|
|
22
52
|
msgId?: string;
|
|
23
|
-
header?:
|
|
24
|
-
title?: string;
|
|
25
|
-
};
|
|
53
|
+
header?: HeaderMedia;
|
|
26
54
|
status?: StatusPresence;
|
|
27
55
|
text?: string;
|
|
28
56
|
url?: string;
|
|
@@ -51,19 +79,102 @@ export declare class WhatsApp {
|
|
|
51
79
|
items?: Items[];
|
|
52
80
|
};
|
|
53
81
|
}, reply?: boolean): Promise<SendMessageRoot>;
|
|
54
|
-
forwardingMessage(to: string, msgId: string): Promise<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
forwardingMessage(to: string, msgId: string): Promise<SendMessageRoot>;
|
|
83
|
+
sendSticker(to: string, url: string): Promise<SendMessageRoot>;
|
|
84
|
+
sendVideoNote(to: string, url: string): Promise<SendMessageRoot>;
|
|
85
|
+
sendPoll(to: string, name: string, values: Array<string | number | boolean>, selectableCount?: number): Promise<SendMessageRoot>;
|
|
86
|
+
sendEvent(data: EventData): Promise<SendMessageRoot>;
|
|
87
|
+
pinMessage(id: string, duration?: number): Promise<ApiResponse>;
|
|
88
|
+
sendCallLink(to: string, type: string, caption?: string): Promise<SendMessageRoot>;
|
|
89
|
+
sendImageBase64(to: string, base64: string, caption?: string): Promise<SendMessageRoot>;
|
|
90
|
+
sendAudioBase64(to: string, base64: string): Promise<SendMessageRoot>;
|
|
91
|
+
sendDocumentBase64(to: string, base64: string, mimetype: string, fileName?: string, caption?: string): Promise<SendMessageRoot>;
|
|
92
|
+
getChats(): Promise<{
|
|
93
|
+
status: number;
|
|
94
|
+
data: ChatInfo[];
|
|
95
|
+
}>;
|
|
96
|
+
modifyChat(id: string, action: 'markRead' | 'pin', value: boolean): Promise<ApiResponse>;
|
|
97
|
+
deleteChat(chatId: string): Promise<ApiResponse>;
|
|
98
|
+
getChatMessages(chatId: string): Promise<{
|
|
99
|
+
status: number;
|
|
100
|
+
data: MessageData[];
|
|
101
|
+
}>;
|
|
102
|
+
makeCall(to: string, isVideo?: boolean): Promise<CallResponse>;
|
|
103
|
+
rejectCall(id: string, from: string): Promise<ApiResponse>;
|
|
104
|
+
getLabels(): Promise<{
|
|
105
|
+
status: number;
|
|
106
|
+
data: LabelInfo[];
|
|
107
|
+
}>;
|
|
108
|
+
createLabel(name: string, labelId?: string): Promise<ApiResponse>;
|
|
109
|
+
getChatLabel(labelId: string): Promise<{
|
|
110
|
+
status: number;
|
|
111
|
+
data: ChatInfo[];
|
|
112
|
+
}>;
|
|
113
|
+
addChatLabel(labelId: string, to: string): Promise<ApiResponse>;
|
|
114
|
+
removeChatLabel(labelId: string, to: string): Promise<ApiResponse>;
|
|
115
|
+
checkRegisteredWhatsapp(number: string): Promise<RegisteredResponse>;
|
|
116
|
+
downloadMedia(type: 'image' | 'video' | 'sticker' | 'audio' | 'document', message: DownloadableMessage): Promise<DownloadMediaResponse>;
|
|
117
|
+
deleteStorage(): Promise<ApiResponse>;
|
|
118
|
+
contacts(): Promise<{
|
|
119
|
+
status: number;
|
|
120
|
+
data: ContactInfo[];
|
|
121
|
+
}>;
|
|
122
|
+
contactProfile(id: string): Promise<{
|
|
123
|
+
status: number;
|
|
124
|
+
data: ContactInfo;
|
|
125
|
+
}>;
|
|
126
|
+
blockContact(number: string, action: 'block' | 'unblock'): Promise<ApiResponse>;
|
|
127
|
+
groups(): Promise<{
|
|
128
|
+
status: number;
|
|
129
|
+
data: GroupInfo[];
|
|
130
|
+
}>;
|
|
131
|
+
infoGroup(id: string): Promise<{
|
|
132
|
+
status: number;
|
|
133
|
+
data: GroupInfo;
|
|
134
|
+
}>;
|
|
135
|
+
createGroup(name: string, participants: string[]): Promise<{
|
|
136
|
+
status: number;
|
|
137
|
+
data: GroupInfo;
|
|
138
|
+
}>;
|
|
139
|
+
updateGroup(id: string, name: string, description: string): Promise<ApiResponse>;
|
|
140
|
+
changeGroupSettings(id: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'): Promise<ApiResponse>;
|
|
141
|
+
leaveGroup(id: string): Promise<ApiResponse>;
|
|
142
|
+
getInviteGroup(id: string): Promise<InviteCodeResponse>;
|
|
143
|
+
updateGroupPicture(id: string, url: string): Promise<ApiResponse>;
|
|
144
|
+
removeGroupPicture(id: string): Promise<ApiResponse>;
|
|
145
|
+
addParticipantsGroup(id: string, participants: string[]): Promise<ApiResponse>;
|
|
146
|
+
removeParticipantsGroup(id: string, participants: string[]): Promise<ApiResponse>;
|
|
147
|
+
updateGroupParticipantRole(id: string, action: 'promote' | 'demote', participants: string[]): Promise<ApiResponse>;
|
|
148
|
+
getGroupRequestParticipants(id: string): Promise<{
|
|
149
|
+
status: number;
|
|
150
|
+
data: GroupParticipant[];
|
|
151
|
+
}>;
|
|
152
|
+
updateGroupRequestParticipants(id: string, data: GroupParticipantsAction): Promise<ApiResponse>;
|
|
153
|
+
listCommunities(): Promise<{
|
|
154
|
+
status: number;
|
|
155
|
+
data: CommunityInfo[];
|
|
156
|
+
}>;
|
|
157
|
+
createCommunity(data: CommunityCreate): Promise<{
|
|
158
|
+
status: number;
|
|
159
|
+
data: CommunityInfo;
|
|
160
|
+
}>;
|
|
161
|
+
infoCommunity(id: string): Promise<{
|
|
162
|
+
status: number;
|
|
163
|
+
data: CommunityInfo;
|
|
164
|
+
}>;
|
|
165
|
+
updateCommunity(id: string, data: CommunityUpdate): Promise<ApiResponse>;
|
|
166
|
+
leaveCommunity(id: string): Promise<ApiResponse>;
|
|
167
|
+
updateCommunityPicture(id: string, url: string): Promise<ApiResponse>;
|
|
168
|
+
getCommunityInviteCode(id: string): Promise<InviteCodeResponse>;
|
|
169
|
+
removeCommunityParticipants(id: string, participants: string[]): Promise<ApiResponse>;
|
|
170
|
+
getCommunityRequestParticipants(id: string): Promise<{
|
|
171
|
+
status: number;
|
|
172
|
+
data: GroupParticipant[];
|
|
173
|
+
}>;
|
|
174
|
+
updateCommunityRequestParticipants(id: string, data: GroupParticipantsAction): Promise<ApiResponse>;
|
|
175
|
+
getCatalog(limit?: number, cursor?: string): Promise<CatalogResponse>;
|
|
176
|
+
createProduct(product: Product): Promise<ApiResponse>;
|
|
177
|
+
updateProduct(productId: string, product: Product): Promise<ApiResponse>;
|
|
178
|
+
deleteProduct(productId: string): Promise<ApiResponse>;
|
|
68
179
|
}
|
|
69
180
|
export default WhatsApp;
|
package/dist/WhatsApp.js
CHANGED
|
@@ -1,174 +1,118 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WhatsApp = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const HttpClient_1 = require("./client/HttpClient");
|
|
5
|
+
const InstanceService_1 = require("./services/InstanceService");
|
|
6
|
+
const MessageService_1 = require("./services/MessageService");
|
|
7
|
+
const ChatService_1 = require("./services/ChatService");
|
|
8
|
+
const CallService_1 = require("./services/CallService");
|
|
9
|
+
const LabelService_1 = require("./services/LabelService");
|
|
10
|
+
const ActionService_1 = require("./services/ActionService");
|
|
11
|
+
const ContactService_1 = require("./services/ContactService");
|
|
12
|
+
const GroupService_1 = require("./services/GroupService");
|
|
13
|
+
const CommunityService_1 = require("./services/CommunityService");
|
|
14
|
+
const BusinessService_1 = require("./services/BusinessService");
|
|
7
15
|
class WhatsApp {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
async contacts() {
|
|
109
|
-
this.route = types_1.Routes.CONTACTS;
|
|
110
|
-
this.method = types_1.HttpMethod.GET;
|
|
111
|
-
return await this.request();
|
|
112
|
-
}
|
|
113
|
-
async contactProfile(id) {
|
|
114
|
-
this.route = types_1.Routes.CONTACTS + "/" + id;
|
|
115
|
-
this.method = types_1.HttpMethod.GET;
|
|
116
|
-
return await this.request();
|
|
117
|
-
}
|
|
118
|
-
async groups() {
|
|
119
|
-
this.route = types_1.Routes.GROUPS;
|
|
120
|
-
this.method = types_1.HttpMethod.GET;
|
|
121
|
-
return await this.request();
|
|
122
|
-
}
|
|
123
|
-
async infoGroup(id) {
|
|
124
|
-
this.route = types_1.Routes.GROUPS + "/" + id;
|
|
125
|
-
this.method = types_1.HttpMethod.GET;
|
|
126
|
-
return await this.request();
|
|
127
|
-
}
|
|
128
|
-
async getInviteGroup(id) {
|
|
129
|
-
this.route = types_1.Routes.GROUPS + "/" + id + "/invite";
|
|
130
|
-
this.method = types_1.HttpMethod.GET;
|
|
131
|
-
return await this.request();
|
|
132
|
-
}
|
|
133
|
-
async updateGroup(id, name, description) {
|
|
134
|
-
this.route = types_1.Routes.GROUPS + "/" + id;
|
|
135
|
-
this.method = types_1.HttpMethod.PUT;
|
|
136
|
-
this.body = {
|
|
137
|
-
name,
|
|
138
|
-
description
|
|
139
|
-
};
|
|
140
|
-
return await this.request();
|
|
141
|
-
}
|
|
142
|
-
async updateGroupPicture(id, url) {
|
|
143
|
-
this.route = types_1.Routes.GROUPS + "/" + id + "/picture";
|
|
144
|
-
this.method = types_1.HttpMethod.PUT;
|
|
145
|
-
this.body = {
|
|
146
|
-
url
|
|
147
|
-
};
|
|
148
|
-
return await this.request();
|
|
149
|
-
}
|
|
150
|
-
async leaveGroup(id) {
|
|
151
|
-
this.route = types_1.Routes.GROUPS + "/" + id;
|
|
152
|
-
this.method = types_1.HttpMethod.DELETE;
|
|
153
|
-
return await this.request();
|
|
154
|
-
}
|
|
155
|
-
async createGroup(name, participants) {
|
|
156
|
-
this.route = types_1.Routes.GROUPS;
|
|
157
|
-
this.method = types_1.HttpMethod.POST;
|
|
158
|
-
this.body = {
|
|
159
|
-
name,
|
|
160
|
-
participants
|
|
161
|
-
};
|
|
162
|
-
return await this.request();
|
|
163
|
-
}
|
|
164
|
-
async addParticipantsGroup(id, participants) {
|
|
165
|
-
this.route = types_1.Routes.GROUPS + "/" + id + "/participants";
|
|
166
|
-
this.method = types_1.HttpMethod.POST;
|
|
167
|
-
this.body = {
|
|
168
|
-
participants
|
|
169
|
-
};
|
|
170
|
-
return await this.request();
|
|
171
|
-
}
|
|
16
|
+
constructor(data, httpClient) {
|
|
17
|
+
const client = httpClient ?? new HttpClient_1.HttpClient(`${data.server}/${data.key}`);
|
|
18
|
+
this.instance = new InstanceService_1.InstanceService(client);
|
|
19
|
+
this.message = new MessageService_1.MessageService(client);
|
|
20
|
+
this.chat = new ChatService_1.ChatService(client);
|
|
21
|
+
this.call = new CallService_1.CallService(client);
|
|
22
|
+
this.label = new LabelService_1.LabelService(client);
|
|
23
|
+
this.action = new ActionService_1.ActionService(client);
|
|
24
|
+
this.contact = new ContactService_1.ContactService(client);
|
|
25
|
+
this.group = new GroupService_1.GroupService(client);
|
|
26
|
+
this.community = new CommunityService_1.CommunityService(client);
|
|
27
|
+
this.business = new BusinessService_1.BusinessService(client);
|
|
28
|
+
}
|
|
29
|
+
// ==================== Backward Compatibility ====================
|
|
30
|
+
// These methods delegate to the corresponding services.
|
|
31
|
+
// Use wa.instance.*, wa.message.*, wa.group.*, etc. for the new API.
|
|
32
|
+
// Instance
|
|
33
|
+
connect() { return this.instance.connect(); }
|
|
34
|
+
info() { return this.instance.info(); }
|
|
35
|
+
logout() { return this.instance.logout(); }
|
|
36
|
+
setting(data) { return this.instance.setting(data); }
|
|
37
|
+
updateWebhook(body) { return this.instance.updateWebhook(body); }
|
|
38
|
+
pairingCode(phoneNumber) { return this.instance.pairingCode(phoneNumber); }
|
|
39
|
+
addMongoDb(uri, dbName) { return this.instance.addMongoDb(uri, dbName); }
|
|
40
|
+
setProxy(proxy) { return this.instance.setProxy(proxy); }
|
|
41
|
+
restart() { return this.instance.restart(); }
|
|
42
|
+
updateProfileStatus(text) { return this.instance.updateProfileStatus(text); }
|
|
43
|
+
updateProfilePicture(url) { return this.instance.updateProfilePicture(url); }
|
|
44
|
+
removeProfilePicture() { return this.instance.removeProfilePicture(); }
|
|
45
|
+
updateProfileName(name) { return this.instance.updateProfileName(name); }
|
|
46
|
+
mobileRegisterPrepare(data) { return this.instance.mobileRegisterPrepare(data); }
|
|
47
|
+
mobileRequestCode(method) { return this.instance.mobileRequestCode(method); }
|
|
48
|
+
mobileVerifyCode(code) { return this.instance.mobileVerifyCode(code); }
|
|
49
|
+
webhookStatistics() { return this.instance.webhookStatistics(); }
|
|
50
|
+
// Messages
|
|
51
|
+
listMessages(phoneNumber, page, limit) { return this.message.list(phoneNumber, page, limit); }
|
|
52
|
+
sendMessage(data, reply) { return this.message.send(data, reply); }
|
|
53
|
+
forwardingMessage(to, msgId) { return this.message.forward(to, msgId); }
|
|
54
|
+
sendSticker(to, url) { return this.message.sendSticker(to, url); }
|
|
55
|
+
sendVideoNote(to, url) { return this.message.sendVideoNote(to, url); }
|
|
56
|
+
sendPoll(to, name, values, selectableCount) { return this.message.sendPoll(to, name, values, selectableCount); }
|
|
57
|
+
sendEvent(data) { return this.message.sendEvent(data); }
|
|
58
|
+
pinMessage(id, duration) { return this.message.pin(id, duration); }
|
|
59
|
+
sendCallLink(to, type, caption) { return this.message.sendCallLink(to, type, caption); }
|
|
60
|
+
sendImageBase64(to, base64, caption) { return this.message.sendImageBase64(to, base64, caption); }
|
|
61
|
+
sendAudioBase64(to, base64) { return this.message.sendAudioBase64(to, base64); }
|
|
62
|
+
sendDocumentBase64(to, base64, mimetype, fileName, caption) { return this.message.sendDocumentBase64(to, base64, mimetype, fileName, caption); }
|
|
63
|
+
// Chat
|
|
64
|
+
getChats() { return this.chat.list(); }
|
|
65
|
+
modifyChat(id, action, value) { return this.chat.modify(id, action, value); }
|
|
66
|
+
deleteChat(chatId) { return this.chat.delete(chatId); }
|
|
67
|
+
getChatMessages(chatId) { return this.chat.messages(chatId); }
|
|
68
|
+
// Call
|
|
69
|
+
makeCall(to, isVideo) { return this.call.call(to, isVideo); }
|
|
70
|
+
rejectCall(id, from) { return this.call.reject(id, from); }
|
|
71
|
+
// Labels
|
|
72
|
+
getLabels() { return this.label.list(); }
|
|
73
|
+
createLabel(name, labelId) { return this.label.create(name, labelId); }
|
|
74
|
+
getChatLabel(labelId) { return this.label.getChats(labelId); }
|
|
75
|
+
addChatLabel(labelId, to) { return this.label.addToChat(labelId, to); }
|
|
76
|
+
removeChatLabel(labelId, to) { return this.label.removeFromChat(labelId, to); }
|
|
77
|
+
// Actions
|
|
78
|
+
checkRegisteredWhatsapp(number) { return this.action.checkRegistered(number); }
|
|
79
|
+
downloadMedia(type, message) { return this.action.downloadMedia(type, message); }
|
|
80
|
+
deleteStorage() { return this.action.deleteStorage(); }
|
|
81
|
+
// Contacts
|
|
82
|
+
contacts() { return this.contact.list(); }
|
|
83
|
+
contactProfile(id) { return this.contact.profile(id); }
|
|
84
|
+
blockContact(number, action) { return this.contact.block(number, action); }
|
|
85
|
+
// Groups
|
|
86
|
+
groups() { return this.group.list(); }
|
|
87
|
+
infoGroup(id) { return this.group.info(id); }
|
|
88
|
+
createGroup(name, participants) { return this.group.create(name, participants); }
|
|
89
|
+
updateGroup(id, name, description) { return this.group.update(id, name, description); }
|
|
90
|
+
changeGroupSettings(id, setting) { return this.group.changeSettings(id, setting); }
|
|
91
|
+
leaveGroup(id) { return this.group.leave(id); }
|
|
92
|
+
getInviteGroup(id) { return this.group.getInviteCode(id); }
|
|
93
|
+
updateGroupPicture(id, url) { return this.group.updatePicture(id, url); }
|
|
94
|
+
removeGroupPicture(id) { return this.group.removePicture(id); }
|
|
95
|
+
addParticipantsGroup(id, participants) { return this.group.addParticipants(id, participants); }
|
|
96
|
+
removeParticipantsGroup(id, participants) { return this.group.removeParticipants(id, participants); }
|
|
97
|
+
updateGroupParticipantRole(id, action, participants) { return this.group.updateParticipantRole(id, action, participants); }
|
|
98
|
+
getGroupRequestParticipants(id) { return this.group.getRequestParticipants(id); }
|
|
99
|
+
updateGroupRequestParticipants(id, data) { return this.group.updateRequestParticipants(id, data); }
|
|
100
|
+
// Community
|
|
101
|
+
listCommunities() { return this.community.list(); }
|
|
102
|
+
createCommunity(data) { return this.community.create(data); }
|
|
103
|
+
infoCommunity(id) { return this.community.info(id); }
|
|
104
|
+
updateCommunity(id, data) { return this.community.update(id, data); }
|
|
105
|
+
leaveCommunity(id) { return this.community.leave(id); }
|
|
106
|
+
updateCommunityPicture(id, url) { return this.community.updatePicture(id, url); }
|
|
107
|
+
getCommunityInviteCode(id) { return this.community.getInviteCode(id); }
|
|
108
|
+
removeCommunityParticipants(id, participants) { return this.community.removeParticipants(id, participants); }
|
|
109
|
+
getCommunityRequestParticipants(id) { return this.community.getRequestParticipants(id); }
|
|
110
|
+
updateCommunityRequestParticipants(id, data) { return this.community.updateRequestParticipants(id, data); }
|
|
111
|
+
// Business
|
|
112
|
+
getCatalog(limit, cursor) { return this.business.getCatalog(limit, cursor); }
|
|
113
|
+
createProduct(product) { return this.business.createProduct(product); }
|
|
114
|
+
updateProduct(productId, product) { return this.business.updateProduct(productId, product); }
|
|
115
|
+
deleteProduct(productId) { return this.business.deleteProduct(productId); }
|
|
172
116
|
}
|
|
173
117
|
exports.WhatsApp = WhatsApp;
|
|
174
118
|
exports.default = WhatsApp;
|
package/dist/WhatsApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AACjE,mCAAiL;AAEjL,MAAa,QAAQ;IACF,MAAM,CAAS;IACf,GAAG,CAAS;IACrB,KAAK,CAAS;IACd,MAAM,GAAsB,IAAI,CAAC;IACjC,IAAI,GAAQ,IAAI,CAAC;IAEzB,YAAY,IAAU;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,C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CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG;YACV,IAAI;YACJ,YAAY;SACb,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAGD,KAAK,CAAC,oBAAoB,CAAC,EAAU,EAAE,YAAsB;QAC3D,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,GAAG,eAAe,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG;YACV,YAAY;SACb,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CAEF;AA5OD,4BA4OC;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot, Connect, Location, Buttons, Items } from './types';\n\nexport class WhatsApp {\n private readonly server: string;\n private readonly key: string;\n private route: string;\n private method: HttpMethod | null = null;\n private body: any = null;\n\n constructor(data: Init) {\n this.server = data.server;\n this.key = data.key;\n }\n\n private async request(): Promise<any> {\n if (!this.route || !this.method) {\n throw new Error('Path and method must be defined before making a request.');\n }\n const options: AxiosRequestConfig = {\n url: `${this.server}/${this.key}/${this.route}`,\n method: this.method,\n headers: {\n 'Content-Type': 'application/json'\n }\n };\n if ((this.method === 'POST' || this.method === 'PUT') && this.body) {\n options.data = JSON.stringify(this.body);\n }\n try {\n const response = await axios(options);\n return response.data;\n } catch (error: any) {\n throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);\n }\n }\n\n\n async connect(): Promise<Connect> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async info(): Promise<InfoInstance> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async logout(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n\n async setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean, receivePresence: boolean): Promise<{ status: number, message: string }> {\n this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;\n this.method = HttpMethod.PATCH;\n return await this.request();\n }\n\n\n async updateWebhook(body: WebhookBody): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.PUT;\n this.body = body;\n return await this.request();\n }\n\n\n async sendMessage(\n data: {\n type: TypeMessage,\n body: {\n to: string,\n msgId?: string,\n header?: {\n title?: string,\n },\n status?: StatusPresence,\n text?: string,\n url?: string,\n caption?: string,\n mimetype?: string,\n fileName?: string,\n contact?: Contact,\n location?: Location,\n name?: string,\n options?: string[],\n sections?: Section[],\n buttons?: Buttons[],\n footer?: string,\n description?: string,\n title?: string,\n buttonText?: string,\n thumbnailUrl?: string,\n sourceUrl?: string,\n referenceId?: string,\n code?: string,\n key?: string,\n merchantName?: string,\n keyType?: \"CNPJ\" | \"CPF\" | \"EMAIL\" | \"PHONE\",\n subtotal?: string,\n totalAmount?: string,\n items?: Items[],\n }\n }, reply: boolean = false): Promise<SendMessageRoot> {\n\n if (data.type === TypeMessage.BUTTON_PIX) {\n const { key, keyType, merchantName, subtotal, totalAmount, items } = data.body;\n if (!key || !keyType || !merchantName || !subtotal || !totalAmount || !items || items.length === 0) {\n throw new Error(\"Campos obrigatórios para pagamento via PIX estão ausentes.\");\n }\n }\n\n if (reply) {\n this.route = Routes.MESSAGES + \"/\" + data.body.msgId + \"/\" + data.type;\n } else {\n this.route = Routes.MESSAGES + \"/\" + data.type;\n }\n\n this.method = HttpMethod.POST;\n this.body = data.body;\n return await this.request();\n }\n\n\n async forwardingMessage(to: string, msgId: string) {\n this.route = Routes.MESSAGES + \"/\" + msgId + \"/forwarding\";\n this.method = HttpMethod.POST;\n this.body = {\n to,\n }\n return await this.request();\n }\n\n async rejectCall(id: string, from: string) {\n this.route = Routes.CALL + `/${id}/${from}`;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async pairingCode(phoneNumber: string) {\n this.route = Routes.INSTANCES + \"/pairing-code\";\n this.body = {\n phoneNumber,\n }\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async checkRegisteredWhatsapp(number: string) {\n this.route = Routes.ACTIONS + \"/registered?number=\" + number;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async contacts() {\n this.route = Routes.CONTACTS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async contactProfile(id: string) {\n this.route = Routes.CONTACTS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async groups() {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async infoGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async getInviteGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id + \"/invite\";\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n\n async updateGroup(id: string, name: string, description: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.PUT;\n this.body = {\n name,\n description\n }\n return await this.request();\n }\n\n async updateGroupPicture(id: string, url: string) {\n this.route = Routes.GROUPS + \"/\" + id + \"/picture\";\n this.method = HttpMethod.PUT;\n this.body = {\n url\n }\n return await this.request();\n }\n\n async leaveGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async createGroup(name: string, participants: string[]) {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.POST;\n this.body = {\n name,\n participants\n }\n return await this.request();\n }\n\n\n async addParticipantsGroup(id: string, participants: string[]) {\n this.route = Routes.GROUPS + \"/\" + id + \"/participants\";\n this.method = HttpMethod.POST;\n this.body = {\n participants\n }\n return await this.request();\n }\n\n}\n\n\nexport default WhatsApp;\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;AAWA,oDAAiD;AACjD,gEAA6D;AAC7D,8DAA2D;AAC3D,wDAAqD;AACrD,wDAAqD;AACrD,0DAAuD;AACvD,4DAAyD;AACzD,8DAA2D;AAC3D,0DAAuD;AACvD,kEAA+D;AAC/D,gEAA6D;AAE7D,MAAa,QAAQ;IAYnB,YAAY,IAAU,EAAE,UAAwB;QAC9C,MAAM,MAAM,GAAG,UAAU,IAAI,IAAI,uBAAU,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAE1E,IAAI,CAAC,QAAQ,GAAG,IAAI,iCAAe,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,mCAAgB,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,IAAI,i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C;IACtG,aAAa,CAAC,SAAiB,EAAE,OAAgB,IAA0B,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpI,aAAa,CAAC,SAAiB,IAA0B,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAC1G;AA3ID,4BA2IC;AAED,kBAAe,QAAQ,CAAC","sourcesContent":["import {\n Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section,\n Location, Buttons, Items, HeaderMedia, DownloadableMessage, Product,\n CommunityCreate, CommunityUpdate, GroupParticipantsAction,\n ApiResponse, PairingCodeResponse, MobileRegisterData, EventData,\n InfoInstance, SendMessageRoot, Connect, RegisteredResponse,\n ContactInfo, GroupInfo, InviteCodeResponse, ChatInfo, LabelInfo,\n CommunityInfo, CatalogResponse, WebhookStatistics, ListMessagesResponse,\n DownloadMediaResponse, CallResponse, MessageData, GroupParticipant,\n} from './types';\nimport { IHttpClient } from './client/IHttpClient';\nimport { HttpClient } from './client/HttpClient';\nimport { InstanceService } from './services/InstanceService';\nimport { MessageService } from './services/MessageService';\nimport { ChatService } from './services/ChatService';\nimport { CallService } from './services/CallService';\nimport { LabelService } from './services/LabelService';\nimport { ActionService } from './services/ActionService';\nimport { ContactService } from './services/ContactService';\nimport { GroupService } from './services/GroupService';\nimport { CommunityService } from './services/CommunityService';\nimport { BusinessService } from './services/BusinessService';\n\nexport class WhatsApp {\n readonly instance: InstanceService;\n readonly message: MessageService;\n readonly chat: ChatService;\n readonly call: CallService;\n readonly label: LabelService;\n readonly action: ActionService;\n readonly contact: ContactService;\n readonly group: GroupService;\n readonly community: CommunityService;\n readonly business: BusinessService;\n\n constructor(data: Init, httpClient?: IHttpClient) {\n const client = httpClient ?? new HttpClient(`${data.server}/${data.key}`);\n\n this.instance = new InstanceService(client);\n this.message = new MessageService(client);\n this.chat = new ChatService(client);\n this.call = new CallService(client);\n this.label = new LabelService(client);\n this.action = new ActionService(client);\n this.contact = new ContactService(client);\n this.group = new GroupService(client);\n this.community = new CommunityService(client);\n this.business = new BusinessService(client);\n }\n\n // ==================== Backward Compatibility ====================\n // These methods delegate to the corresponding services.\n // Use wa.instance.*, wa.message.*, wa.group.*, etc. for the new API.\n\n // Instance\n connect(): Promise<Connect> { return this.instance.connect(); }\n info(): Promise<InfoInstance> { return this.instance.info(); }\n logout(): Promise<ApiResponse> { return this.instance.logout(); }\n setting(data: { markMessageRead: boolean; saveMedia: boolean; receiveStatusMessage: boolean; receivePresence: boolean }): Promise<ApiResponse> { return this.instance.setting(data); }\n updateWebhook(body: WebhookBody): Promise<ApiResponse> { return this.instance.updateWebhook(body); }\n pairingCode(phoneNumber: string): Promise<PairingCodeResponse> { return this.instance.pairingCode(phoneNumber); }\n addMongoDb(uri: string, dbName: string): Promise<ApiResponse> { return this.instance.addMongoDb(uri, dbName); }\n setProxy(proxy: string): Promise<ApiResponse> { return this.instance.setProxy(proxy); }\n restart(): Promise<ApiResponse> { return this.instance.restart(); }\n updateProfileStatus(text: string): Promise<ApiResponse> { return this.instance.updateProfileStatus(text); }\n updateProfilePicture(url: string): Promise<ApiResponse> { return this.instance.updateProfilePicture(url); }\n removeProfilePicture(): Promise<ApiResponse> { return this.instance.removeProfilePicture(); }\n updateProfileName(name: string): Promise<ApiResponse> { return this.instance.updateProfileName(name); }\n mobileRegisterPrepare(data: MobileRegisterData): Promise<ApiResponse> { return this.instance.mobileRegisterPrepare(data); }\n mobileRequestCode(method: string): Promise<ApiResponse> { return this.instance.mobileRequestCode(method); }\n mobileVerifyCode(code: string): Promise<ApiResponse> { return this.instance.mobileVerifyCode(code); }\n webhookStatistics(): Promise<WebhookStatistics> { return this.instance.webhookStatistics(); }\n\n // Messages\n listMessages(phoneNumber: string, page?: number, limit?: number): Promise<ListMessagesResponse> { return this.message.list(phoneNumber, page, limit); }\n sendMessage(\n data: {\n type: TypeMessage;\n body: {\n to: string; msgId?: string; header?: HeaderMedia; status?: StatusPresence;\n text?: string; url?: string; caption?: string; mimetype?: string; fileName?: string;\n contact?: Contact; location?: Location; name?: string; options?: string[];\n sections?: Section[]; buttons?: Buttons[]; footer?: string; description?: string;\n title?: string; buttonText?: string; thumbnailUrl?: string; sourceUrl?: string;\n referenceId?: string; code?: string; key?: string; merchantName?: string;\n keyType?: \"CNPJ\" | \"CPF\" | \"EMAIL\" | \"PHONE\"; subtotal?: string;\n totalAmount?: string; items?: Items[];\n };\n },\n reply?: boolean,\n ): Promise<SendMessageRoot> { return this.message.send(data, reply); }\n forwardingMessage(to: string, msgId: string): Promise<SendMessageRoot> { return this.message.forward(to, msgId); }\n sendSticker(to: string, url: string): Promise<SendMessageRoot> { return this.message.sendSticker(to, url); }\n sendVideoNote(to: string, url: string): Promise<SendMessageRoot> { return this.message.sendVideoNote(to, url); }\n sendPoll(to: string, name: string, values: Array<string | number | boolean>, selectableCount?: number): Promise<SendMessageRoot> { return this.message.sendPoll(to, name, values, selectableCount); }\n sendEvent(data: EventData): Promise<SendMessageRoot> { return this.message.sendEvent(data); }\n pinMessage(id: string, duration?: number): Promise<ApiResponse> { return this.message.pin(id, duration); }\n sendCallLink(to: string, type: string, caption?: string): Promise<SendMessageRoot> { return this.message.sendCallLink(to, type, caption); }\n sendImageBase64(to: string, base64: string, caption?: string): Promise<SendMessageRoot> { return this.message.sendImageBase64(to, base64, caption); }\n sendAudioBase64(to: string, base64: string): Promise<SendMessageRoot> { return this.message.sendAudioBase64(to, base64); }\n sendDocumentBase64(to: string, base64: string, mimetype: string, fileName?: string, caption?: string): Promise<SendMessageRoot> { return this.message.sendDocumentBase64(to, base64, mimetype, fileName, caption); }\n\n // Chat\n getChats(): Promise<{ status: number; data: ChatInfo[] }> { return this.chat.list(); }\n modifyChat(id: string, action: 'markRead' | 'pin', value: boolean): Promise<ApiResponse> { return this.chat.modify(id, action, value); }\n deleteChat(chatId: string): Promise<ApiResponse> { return this.chat.delete(chatId); }\n getChatMessages(chatId: string): Promise<{ status: number; data: MessageData[] }> { return this.chat.messages(chatId); }\n\n // Call\n makeCall(to: string, isVideo?: boolean): Promise<CallResponse> { return this.call.call(to, isVideo); }\n rejectCall(id: string, from: string): Promise<ApiResponse> { return this.call.reject(id, from); }\n\n // Labels\n getLabels(): Promise<{ status: number; data: LabelInfo[] }> { return this.label.list(); }\n createLabel(name: string, labelId?: string): Promise<ApiResponse> { return this.label.create(name, labelId); }\n getChatLabel(labelId: string): Promise<{ status: number; data: ChatInfo[] }> { return this.label.getChats(labelId); }\n addChatLabel(labelId: string, to: string): Promise<ApiResponse> { return this.label.addToChat(labelId, to); }\n removeChatLabel(labelId: string, to: string): Promise<ApiResponse> { return this.label.removeFromChat(labelId, to); }\n\n // Actions\n checkRegisteredWhatsapp(number: string): Promise<RegisteredResponse> { return this.action.checkRegistered(number); }\n downloadMedia(type: 'image' | 'video' | 'sticker' | 'audio' | 'document', message: DownloadableMessage): Promise<DownloadMediaResponse> { return this.action.downloadMedia(type, message); }\n deleteStorage(): Promise<ApiResponse> { return this.action.deleteStorage(); }\n\n // Contacts\n contacts(): Promise<{ status: number; data: ContactInfo[] }> { return this.contact.list(); }\n contactProfile(id: string): Promise<{ status: number; data: ContactInfo }> { return this.contact.profile(id); }\n blockContact(number: string, action: 'block' | 'unblock'): Promise<ApiResponse> { return this.contact.block(number, action); }\n\n // Groups\n groups(): Promise<{ status: number; data: GroupInfo[] }> { return this.group.list(); }\n infoGroup(id: string): Promise<{ status: number; data: GroupInfo }> { return this.group.info(id); }\n createGroup(name: string, participants: string[]): Promise<{ status: number; data: GroupInfo }> { return this.group.create(name, participants); }\n updateGroup(id: string, name: string, description: string): Promise<ApiResponse> { return this.group.update(id, name, description); }\n changeGroupSettings(id: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'): Promise<ApiResponse> { return this.group.changeSettings(id, setting); }\n leaveGroup(id: string): Promise<ApiResponse> { return this.group.leave(id); }\n getInviteGroup(id: string): Promise<InviteCodeResponse> { return this.group.getInviteCode(id); }\n updateGroupPicture(id: string, url: string): Promise<ApiResponse> { return this.group.updatePicture(id, url); }\n removeGroupPicture(id: string): Promise<ApiResponse> { return this.group.removePicture(id); }\n addParticipantsGroup(id: string, participants: string[]): Promise<ApiResponse> { return this.group.addParticipants(id, participants); }\n removeParticipantsGroup(id: string, participants: string[]): Promise<ApiResponse> { return this.group.removeParticipants(id, participants); }\n updateGroupParticipantRole(id: string, action: 'promote' | 'demote', participants: string[]): Promise<ApiResponse> { return this.group.updateParticipantRole(id, action, participants); }\n getGroupRequestParticipants(id: string): Promise<{ status: number; data: GroupParticipant[] }> { return this.group.getRequestParticipants(id); }\n updateGroupRequestParticipants(id: string, data: GroupParticipantsAction): Promise<ApiResponse> { return this.group.updateRequestParticipants(id, data); }\n\n // Community\n listCommunities(): Promise<{ status: number; data: CommunityInfo[] }> { return this.community.list(); }\n createCommunity(data: CommunityCreate): Promise<{ status: number; data: CommunityInfo }> { return this.community.create(data); }\n infoCommunity(id: string): Promise<{ status: number; data: CommunityInfo }> { return this.community.info(id); }\n updateCommunity(id: string, data: CommunityUpdate): Promise<ApiResponse> { return this.community.update(id, data); }\n leaveCommunity(id: string): Promise<ApiResponse> { return this.community.leave(id); }\n updateCommunityPicture(id: string, url: string): Promise<ApiResponse> { return this.community.updatePicture(id, url); }\n getCommunityInviteCode(id: string): Promise<InviteCodeResponse> { return this.community.getInviteCode(id); }\n removeCommunityParticipants(id: string, participants: string[]): Promise<ApiResponse> { return this.community.removeParticipants(id, participants); }\n getCommunityRequestParticipants(id: string): Promise<{ status: number; data: GroupParticipant[] }> { return this.community.getRequestParticipants(id); }\n updateCommunityRequestParticipants(id: string, data: GroupParticipantsAction): Promise<ApiResponse> { return this.community.updateRequestParticipants(id, data); }\n\n // Business\n getCatalog(limit?: number, cursor?: string): Promise<CatalogResponse> { return this.business.getCatalog(limit, cursor); }\n createProduct(product: Product): Promise<ApiResponse> { return this.business.createProduct(product); }\n updateProduct(productId: string, product: Product): Promise<ApiResponse> { return this.business.updateProduct(productId, product); }\n deleteProduct(productId: string): Promise<ApiResponse> { return this.business.deleteProduct(productId); }\n}\n\nexport default WhatsApp;\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
class HttpClient {
|
|
8
|
+
constructor(baseUrl) {
|
|
9
|
+
this.baseUrl = baseUrl;
|
|
10
|
+
}
|
|
11
|
+
async request(options) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await (0, axios_1.default)({
|
|
14
|
+
url: `${this.baseUrl}/${options.route}`,
|
|
15
|
+
method: options.method,
|
|
16
|
+
headers: { 'Content-Type': 'application/json' },
|
|
17
|
+
data: options.body,
|
|
18
|
+
params: options.params,
|
|
19
|
+
});
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const axiosError = error;
|
|
24
|
+
throw new errors_1.WhatsAppError(axiosError.message, axiosError.response?.status, axiosError.response?.data);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.HttpClient = HttpClient;
|
|
29
|
+
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/client/HttpClient.ts"],"names":[],"mappings":";;;;AAAA,0DAA0C;AAC1C,sCAA0C;AAG1C,MAAa,UAAU;IACrB,YACmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAI,OAAuB;QACtC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;gBAC3B,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE;gBACvC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,IAAS,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,UAAU,GAAG,KAAmB,CAAC;YACvC,MAAM,IAAI,sBAAa,CACrB,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAC3B,UAAU,CAAC,QAAQ,EAAE,IAAI,CAC1B,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxBD,gCAwBC","sourcesContent":["import axios, { AxiosError } from 'axios';\nimport { WhatsAppError } from '../errors';\nimport { IHttpClient, RequestOptions } from './IHttpClient';\n\nexport class HttpClient implements IHttpClient {\n constructor(\n private readonly baseUrl: string,\n ) {}\n\n async request<T>(options: RequestOptions): Promise<T> {\n try {\n const response = await axios({\n url: `${this.baseUrl}/${options.route}`,\n method: options.method,\n headers: { 'Content-Type': 'application/json' },\n data: options.body,\n params: options.params,\n });\n return response.data as T;\n } catch (error) {\n const axiosError = error as AxiosError;\n throw new WhatsAppError(\n axiosError.message,\n axiosError.response?.status,\n axiosError.response?.data,\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IHttpClient.js","sourceRoot":"","sources":["../../src/client/IHttpClient.ts"],"names":[],"mappings":"","sourcesContent":["export interface RequestOptions {\n route: string;\n method: string;\n body?: object;\n params?: Record<string, string | number | boolean>;\n}\n\nexport interface IHttpClient {\n request<T>(options: RequestOptions): Promise<T>;\n}\n"]}
|