@raphaelvserafim/client-api-whatsapp 1.0.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/.babelrc +3 -0
- package/README.md +225 -0
- package/dist/WhatsApp.d.ts +46 -0
- package/dist/WhatsApp.js +125 -0
- package/dist/WhatsApp.js.map +1 -0
- package/dist/exemple.d.ts +1 -0
- package/dist/exemple.js +121 -0
- package/dist/exemple.js.map +1 -0
- package/dist/model/index.d.ts +64 -0
- package/dist/model/index.js +40 -0
- package/dist/model/index.js.map +1 -0
- package/package.json +45 -0
- package/src/WhatsApp.ts +171 -0
- package/src/exemple.ts +159 -0
- package/src/model/index.ts +79 -0
- package/tsconfig.compile.json +15 -0
- package/tsconfig.json +35 -0
package/.babelrc
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# WhatsApp API
|
|
2
|
+
|
|
3
|
+
## About Our WhatsApp API
|
|
4
|
+
|
|
5
|
+
🔓 **Unlock the Potential of WhatsApp:** Powerful Integration with Our Unofficial API!
|
|
6
|
+
|
|
7
|
+
### Efficient Group Management on WhatsApp
|
|
8
|
+
|
|
9
|
+
📋 Our stable, though unofficial, API allows for efficient management of WhatsApp groups. Simplify administration, and easily add or remove members.
|
|
10
|
+
|
|
11
|
+
### Versatile Message Sending
|
|
12
|
+
|
|
13
|
+
💬 With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively.
|
|
14
|
+
|
|
15
|
+
### Receive Instant Events
|
|
16
|
+
|
|
17
|
+
🔔 Stay updated with our API, receiving real-time events when new messages are received. Stay connected and agile in responding to interactions on WhatsApp.
|
|
18
|
+
|
|
19
|
+
🔗 **Create Your Account:** Visit [https://api-wa.me/sign-up](https://api-wa.me/sign-up) to create your account and start using our API today!
|
|
20
|
+
|
|
21
|
+
🎁 **Special Discount:** Use the coupon **GIT20** and get 20% off on your first instance!
|
|
22
|
+
|
|
23
|
+
## Contact Support
|
|
24
|
+
|
|
25
|
+
- **Name:** Raphael Serafim
|
|
26
|
+
- **Email:** [support@api-wa.me](mailto:support@api-wa.me)
|
|
27
|
+
- **Website:** [https://api-wa.me](https://api-wa.me)
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const whatsapp = new WhatsApp({ server: "https://us.api-wa.me", key: "12345678" });
|
|
36
|
+
const to = "559999999999" // If you want to send it to the group = 123456789@us
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Get Information
|
|
40
|
+
```js
|
|
41
|
+
whatsapp.info().then((response) => {
|
|
42
|
+
console.log(response)
|
|
43
|
+
}).catch(console.error)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Connect to WhatsApp
|
|
47
|
+
```js
|
|
48
|
+
whatsapp.connect().then((response) => {
|
|
49
|
+
console.log(response)
|
|
50
|
+
}).catch(console.error);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Logout
|
|
54
|
+
```js
|
|
55
|
+
whatsapp.logout().then((response) => {
|
|
56
|
+
console.log(response)
|
|
57
|
+
}).catch(console.error);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Get Contacts
|
|
61
|
+
```js
|
|
62
|
+
whatsapp.contacts().then((response) => {
|
|
63
|
+
console.log(response)
|
|
64
|
+
}).catch(console.error)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Send Messages
|
|
68
|
+
|
|
69
|
+
### Presence
|
|
70
|
+
```js
|
|
71
|
+
whatsapp.sendMessage({
|
|
72
|
+
type: TypeMessage.PRESENCE,
|
|
73
|
+
body: {
|
|
74
|
+
to: to,
|
|
75
|
+
status: StatusPresence.COMPOSING
|
|
76
|
+
}
|
|
77
|
+
}).then((response) => {
|
|
78
|
+
console.log(response)
|
|
79
|
+
}).catch(console.error)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Text
|
|
83
|
+
```js
|
|
84
|
+
whatsapp.sendMessage({
|
|
85
|
+
type: TypeMessage.TEXT,
|
|
86
|
+
body: {
|
|
87
|
+
to: to,
|
|
88
|
+
text: "Hey"
|
|
89
|
+
}
|
|
90
|
+
}).then((response) => {
|
|
91
|
+
console.log(response)
|
|
92
|
+
}).catch(console.error)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Audio
|
|
96
|
+
```js
|
|
97
|
+
whatsapp.sendMessage({
|
|
98
|
+
type: TypeMessage.AUDIO,
|
|
99
|
+
body: {
|
|
100
|
+
to: to,
|
|
101
|
+
url: ""
|
|
102
|
+
}
|
|
103
|
+
}).then((response) => {
|
|
104
|
+
console.log(response)
|
|
105
|
+
}).catch(console.error)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Image
|
|
109
|
+
```js
|
|
110
|
+
whatsapp.sendMessage({
|
|
111
|
+
type: TypeMessage.IMAGE,
|
|
112
|
+
body: {
|
|
113
|
+
to: to,
|
|
114
|
+
url: ""
|
|
115
|
+
}
|
|
116
|
+
}).then((response) => {
|
|
117
|
+
console.log(response)
|
|
118
|
+
}).catch(console.error)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Video
|
|
122
|
+
```js
|
|
123
|
+
whatsapp.sendMessage({
|
|
124
|
+
type: TypeMessage.VIDEO,
|
|
125
|
+
body: {
|
|
126
|
+
to: to,
|
|
127
|
+
url: ""
|
|
128
|
+
}
|
|
129
|
+
}).then((response) => {
|
|
130
|
+
console.log(response)
|
|
131
|
+
}).catch(console.error)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Document
|
|
136
|
+
```js
|
|
137
|
+
whatsapp.sendMessage({
|
|
138
|
+
type: TypeMessage.DOCUMENT,
|
|
139
|
+
body: {
|
|
140
|
+
to: to,
|
|
141
|
+
url: "",
|
|
142
|
+
mimetype: "",
|
|
143
|
+
fileName: ""
|
|
144
|
+
}
|
|
145
|
+
}).then((response) => {
|
|
146
|
+
console.log(response)
|
|
147
|
+
}).catch(console.error)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Contact
|
|
151
|
+
```js
|
|
152
|
+
whatsapp.sendMessage({
|
|
153
|
+
type: TypeMessage.CONTACT,
|
|
154
|
+
body: {
|
|
155
|
+
to: to,
|
|
156
|
+
contact: {
|
|
157
|
+
fullName: "Raphael",
|
|
158
|
+
phoneNumber: to,
|
|
159
|
+
organization: "api-wa.me"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}).then((response) => {
|
|
163
|
+
console.log(response)
|
|
164
|
+
}).catch(console.error)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Reaction
|
|
168
|
+
```js
|
|
169
|
+
whatsapp.sendMessage({
|
|
170
|
+
type: TypeMessage.REACTION,
|
|
171
|
+
body: {
|
|
172
|
+
to: to,
|
|
173
|
+
msgId: "ASDDF872AHDURBSG",
|
|
174
|
+
text: "🤖"
|
|
175
|
+
}
|
|
176
|
+
}).then((response) => {
|
|
177
|
+
console.log(response)
|
|
178
|
+
}).catch(console.error)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### All types of submissions you can respond to a message, so for example
|
|
182
|
+
|
|
183
|
+
### Text
|
|
184
|
+
```js
|
|
185
|
+
whatsapp.sendMessage({
|
|
186
|
+
type: TypeMessage.TEXT,
|
|
187
|
+
body: {
|
|
188
|
+
msgId: "SKJH455AJKJ",
|
|
189
|
+
to: to,
|
|
190
|
+
text: "Hey"
|
|
191
|
+
}
|
|
192
|
+
}, true ).then((response) => {
|
|
193
|
+
console.log(response)
|
|
194
|
+
}).catch(console.error)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Group Management
|
|
198
|
+
|
|
199
|
+
### List Groups
|
|
200
|
+
```js
|
|
201
|
+
whatsapp.groups().then((response) => {
|
|
202
|
+
console.log(response)
|
|
203
|
+
}).catch(console.error)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Group Information
|
|
207
|
+
```js
|
|
208
|
+
whatsapp.infoGroup("123456789@us").then((response) => {
|
|
209
|
+
console.log(response)
|
|
210
|
+
}).catch(console.error)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Create a Group
|
|
214
|
+
```js
|
|
215
|
+
whatsapp.createGroup("Devs", [to]).then((response) => {
|
|
216
|
+
console.log(response)
|
|
217
|
+
}).catch(console.error)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Update a Group
|
|
221
|
+
```js
|
|
222
|
+
whatsapp.updateGroup("123456789@us", "Devs", "Only developers !").then((response) => {
|
|
223
|
+
console.log(response)
|
|
224
|
+
}).catch(console.error)
|
|
225
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section } from './model';
|
|
2
|
+
export declare class WhatsApp {
|
|
3
|
+
private readonly server;
|
|
4
|
+
private readonly key;
|
|
5
|
+
private route;
|
|
6
|
+
private method;
|
|
7
|
+
private body;
|
|
8
|
+
constructor(data: Init);
|
|
9
|
+
private request;
|
|
10
|
+
connect(): Promise<any>;
|
|
11
|
+
info(): Promise<any>;
|
|
12
|
+
logout(): Promise<any>;
|
|
13
|
+
setting(markMessageRead: boolean, saveMedia: boolean): Promise<any>;
|
|
14
|
+
updateWebhook(body: WebhookBody): Promise<any>;
|
|
15
|
+
sendMessage(data: {
|
|
16
|
+
type: TypeMessage;
|
|
17
|
+
body: {
|
|
18
|
+
to: string;
|
|
19
|
+
msgId?: string;
|
|
20
|
+
status?: StatusPresence;
|
|
21
|
+
text?: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
caption?: string;
|
|
24
|
+
mimetype?: string;
|
|
25
|
+
fileName?: string;
|
|
26
|
+
contact?: Contact;
|
|
27
|
+
location?: Location;
|
|
28
|
+
name?: string;
|
|
29
|
+
options?: string[];
|
|
30
|
+
sections?: Section;
|
|
31
|
+
footer?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
title?: string;
|
|
34
|
+
buttonText?: string;
|
|
35
|
+
};
|
|
36
|
+
}, reply?: boolean): Promise<any>;
|
|
37
|
+
checkRegisteredWhatsapp(number: string): Promise<any>;
|
|
38
|
+
contacts(): Promise<any>;
|
|
39
|
+
contactProfile(id: string): Promise<any>;
|
|
40
|
+
groups(): Promise<any>;
|
|
41
|
+
infoGroup(id: string): Promise<any>;
|
|
42
|
+
updateGroup(id: string, name: string, description: string): Promise<any>;
|
|
43
|
+
leaveGroup(id: string): Promise<any>;
|
|
44
|
+
createGroup(name: string, participants: string[]): Promise<any>;
|
|
45
|
+
}
|
|
46
|
+
export default WhatsApp;
|
package/dist/WhatsApp.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsApp = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const model_1 = require("./model");
|
|
7
|
+
class WhatsApp {
|
|
8
|
+
server;
|
|
9
|
+
key;
|
|
10
|
+
route;
|
|
11
|
+
method = null;
|
|
12
|
+
body = null;
|
|
13
|
+
constructor(data) {
|
|
14
|
+
this.server = data.server;
|
|
15
|
+
this.key = data.key;
|
|
16
|
+
}
|
|
17
|
+
async request() {
|
|
18
|
+
if (!this.route || !this.method) {
|
|
19
|
+
throw new Error('Path and method must be defined before making a request.');
|
|
20
|
+
}
|
|
21
|
+
const options = {
|
|
22
|
+
url: `${this.server}/${this.key}/${this.route}`,
|
|
23
|
+
method: this.method,
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json'
|
|
26
|
+
},
|
|
27
|
+
data: this.body ? JSON.stringify(this.body) : null
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const response = await (0, axios_1.default)(options);
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async connect() {
|
|
38
|
+
this.route = model_1.Routes.INSTANCES;
|
|
39
|
+
this.method = model_1.HttpMethod.POST;
|
|
40
|
+
return await this.request();
|
|
41
|
+
}
|
|
42
|
+
async info() {
|
|
43
|
+
this.route = model_1.Routes.INSTANCES;
|
|
44
|
+
this.method = model_1.HttpMethod.GET;
|
|
45
|
+
return await this.request();
|
|
46
|
+
}
|
|
47
|
+
async logout() {
|
|
48
|
+
this.route = model_1.Routes.INSTANCES;
|
|
49
|
+
this.method = model_1.HttpMethod.DELETE;
|
|
50
|
+
return await this.request();
|
|
51
|
+
}
|
|
52
|
+
async setting(markMessageRead, saveMedia) {
|
|
53
|
+
this.route = model_1.Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;
|
|
54
|
+
this.method = model_1.HttpMethod.PATCH;
|
|
55
|
+
return await this.request();
|
|
56
|
+
}
|
|
57
|
+
async updateWebhook(body) {
|
|
58
|
+
this.route = model_1.Routes.INSTANCES;
|
|
59
|
+
this.method = model_1.HttpMethod.PUT;
|
|
60
|
+
this.body = body;
|
|
61
|
+
return await this.request();
|
|
62
|
+
}
|
|
63
|
+
async sendMessage(data, reply = false) {
|
|
64
|
+
if (reply) {
|
|
65
|
+
this.route = model_1.Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.route = model_1.Routes.MESSAGES + "/" + data.type;
|
|
69
|
+
}
|
|
70
|
+
this.method = model_1.HttpMethod.POST;
|
|
71
|
+
this.body = data.body;
|
|
72
|
+
return await this.request();
|
|
73
|
+
}
|
|
74
|
+
async checkRegisteredWhatsapp(number) {
|
|
75
|
+
this.route = model_1.Routes.ACTIONS + "/registered?number=" + number;
|
|
76
|
+
this.method = model_1.HttpMethod.GET;
|
|
77
|
+
return await this.request();
|
|
78
|
+
}
|
|
79
|
+
async contacts() {
|
|
80
|
+
this.route = model_1.Routes.CONTACTS;
|
|
81
|
+
this.method = model_1.HttpMethod.GET;
|
|
82
|
+
return await this.request();
|
|
83
|
+
}
|
|
84
|
+
async contactProfile(id) {
|
|
85
|
+
this.route = model_1.Routes.CONTACTS + "/" + id;
|
|
86
|
+
this.method = model_1.HttpMethod.GET;
|
|
87
|
+
return await this.request();
|
|
88
|
+
}
|
|
89
|
+
async groups() {
|
|
90
|
+
this.route = model_1.Routes.GROUPS;
|
|
91
|
+
this.method = model_1.HttpMethod.GET;
|
|
92
|
+
return await this.request();
|
|
93
|
+
}
|
|
94
|
+
async infoGroup(id) {
|
|
95
|
+
this.route = model_1.Routes.GROUPS + "/" + id;
|
|
96
|
+
this.method = model_1.HttpMethod.GET;
|
|
97
|
+
return await this.request();
|
|
98
|
+
}
|
|
99
|
+
async updateGroup(id, name, description) {
|
|
100
|
+
this.route = model_1.Routes.GROUPS + "/" + id;
|
|
101
|
+
this.method = model_1.HttpMethod.PUT;
|
|
102
|
+
this.body = {
|
|
103
|
+
name,
|
|
104
|
+
description
|
|
105
|
+
};
|
|
106
|
+
return await this.request();
|
|
107
|
+
}
|
|
108
|
+
async leaveGroup(id) {
|
|
109
|
+
this.route = model_1.Routes.GROUPS + "/" + id;
|
|
110
|
+
this.method = model_1.HttpMethod.DELETE;
|
|
111
|
+
return await this.request();
|
|
112
|
+
}
|
|
113
|
+
async createGroup(name, participants) {
|
|
114
|
+
this.route = model_1.Routes.GROUPS;
|
|
115
|
+
this.method = model_1.HttpMethod.POST;
|
|
116
|
+
this.body = {
|
|
117
|
+
name,
|
|
118
|
+
participants
|
|
119
|
+
};
|
|
120
|
+
return await this.request();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.WhatsApp = WhatsApp;
|
|
124
|
+
exports.default = WhatsApp;
|
|
125
|
+
//# sourceMappingURL=WhatsApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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SAAS,CAAC,EAAU;QACxB,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,GAAG,CAAC;QAC7B,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU,EAAE,IAAY,EAAE,WAAmB;QAC7D,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,GAAG,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG;YACV,IAAI;YACJ,WAAW;SACZ,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,MAAM,CAAC;QAChC,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,YAAsB;QACpD,IAAI,CAAC,KAAK,GAAG,cAAM,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;CAEF;AAlKD,4BAkKC;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section } from './model';\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\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 data: this.body ? JSON.stringify(this.body) : null\n };\n\n try {\n const response: AxiosResponse = 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<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async info(): Promise<any> {\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 async setting(markMessageRead: boolean, saveMedia: boolean): Promise<any> {\n this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;\n this.method = HttpMethod.PATCH;\n return await this.request();\n }\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 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 footer?: string,\n description?: string,\n title?: string,\n buttonText?: string,\n }\n }, reply: boolean = false ): Promise<any> {\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 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 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 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\n\nexport default WhatsApp;\n\n\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/exemple.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const WhatsApp_1 = tslib_1.__importDefault(require("./WhatsApp"));
|
|
5
|
+
const model_1 = require("./model");
|
|
6
|
+
const whatsapp = new WhatsApp_1.default({ server: "", key: "" });
|
|
7
|
+
const to = "559999999999"; // If you want to send it to the group = 123456789@us
|
|
8
|
+
whatsapp.info().then((response) => {
|
|
9
|
+
console.log(response);
|
|
10
|
+
}).catch(console.error);
|
|
11
|
+
whatsapp.connect().then((response) => {
|
|
12
|
+
console.log(response);
|
|
13
|
+
}).catch(console.error);
|
|
14
|
+
whatsapp.logout().then((response) => {
|
|
15
|
+
console.log(response);
|
|
16
|
+
}).catch(console.error);
|
|
17
|
+
whatsapp.contacts().then((response) => {
|
|
18
|
+
console.log(response);
|
|
19
|
+
}).catch(console.error);
|
|
20
|
+
whatsapp.sendMessage({
|
|
21
|
+
type: model_1.TypeMessage.PRESENCE,
|
|
22
|
+
body: {
|
|
23
|
+
to: to,
|
|
24
|
+
status: model_1.StatusPresence.COMPOSING
|
|
25
|
+
}
|
|
26
|
+
}).then((response) => {
|
|
27
|
+
console.log(response);
|
|
28
|
+
}).catch(console.error);
|
|
29
|
+
whatsapp.sendMessage({
|
|
30
|
+
type: model_1.TypeMessage.TEXT,
|
|
31
|
+
body: {
|
|
32
|
+
to: to,
|
|
33
|
+
text: "Hey"
|
|
34
|
+
}
|
|
35
|
+
}).then((response) => {
|
|
36
|
+
console.log(response);
|
|
37
|
+
}).catch(console.error);
|
|
38
|
+
whatsapp.sendMessage({
|
|
39
|
+
type: model_1.TypeMessage.TEXT,
|
|
40
|
+
body: {
|
|
41
|
+
msgId: "SKJH455AJKJ",
|
|
42
|
+
to: to,
|
|
43
|
+
text: "Hey"
|
|
44
|
+
}
|
|
45
|
+
}, true).then((response) => {
|
|
46
|
+
console.log(response);
|
|
47
|
+
}).catch(console.error);
|
|
48
|
+
whatsapp.sendMessage({
|
|
49
|
+
type: model_1.TypeMessage.AUDIO,
|
|
50
|
+
body: {
|
|
51
|
+
to: to,
|
|
52
|
+
url: ""
|
|
53
|
+
}
|
|
54
|
+
}).then((response) => {
|
|
55
|
+
console.log(response);
|
|
56
|
+
}).catch(console.error);
|
|
57
|
+
whatsapp.sendMessage({
|
|
58
|
+
type: model_1.TypeMessage.IMAGE,
|
|
59
|
+
body: {
|
|
60
|
+
to: to,
|
|
61
|
+
url: ""
|
|
62
|
+
}
|
|
63
|
+
}).then((response) => {
|
|
64
|
+
console.log(response);
|
|
65
|
+
}).catch(console.error);
|
|
66
|
+
whatsapp.sendMessage({
|
|
67
|
+
type: model_1.TypeMessage.VIDEO,
|
|
68
|
+
body: {
|
|
69
|
+
to: to,
|
|
70
|
+
url: ""
|
|
71
|
+
}
|
|
72
|
+
}).then((response) => {
|
|
73
|
+
console.log(response);
|
|
74
|
+
}).catch(console.error);
|
|
75
|
+
whatsapp.sendMessage({
|
|
76
|
+
type: model_1.TypeMessage.DOCUMENT,
|
|
77
|
+
body: {
|
|
78
|
+
to: to,
|
|
79
|
+
url: "",
|
|
80
|
+
mimetype: "",
|
|
81
|
+
fileName: ""
|
|
82
|
+
}
|
|
83
|
+
}).then((response) => {
|
|
84
|
+
console.log(response);
|
|
85
|
+
}).catch(console.error);
|
|
86
|
+
whatsapp.sendMessage({
|
|
87
|
+
type: model_1.TypeMessage.CONTACT,
|
|
88
|
+
body: {
|
|
89
|
+
to: to,
|
|
90
|
+
contact: {
|
|
91
|
+
fullName: "Raphael",
|
|
92
|
+
phoneNumber: to,
|
|
93
|
+
organization: "api-wa.me"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}).then((response) => {
|
|
97
|
+
console.log(response);
|
|
98
|
+
}).catch(console.error);
|
|
99
|
+
whatsapp.sendMessage({
|
|
100
|
+
type: model_1.TypeMessage.REACTION,
|
|
101
|
+
body: {
|
|
102
|
+
to: to,
|
|
103
|
+
msgId: "ASDDF872AHDURBSG",
|
|
104
|
+
text: "🤖"
|
|
105
|
+
}
|
|
106
|
+
}).then((response) => {
|
|
107
|
+
console.log(response);
|
|
108
|
+
}).catch(console.error);
|
|
109
|
+
whatsapp.groups().then((response) => {
|
|
110
|
+
console.log(response);
|
|
111
|
+
}).catch(console.error);
|
|
112
|
+
whatsapp.infoGroup("123456789@us").then((response) => {
|
|
113
|
+
console.log(response);
|
|
114
|
+
}).catch(console.error);
|
|
115
|
+
whatsapp.createGroup("Devs", [to]).then((response) => {
|
|
116
|
+
console.log(response);
|
|
117
|
+
}).catch(console.error);
|
|
118
|
+
whatsapp.updateGroup("123456789@us", "Devs", "Only developers !").then((response) => {
|
|
119
|
+
console.log(response);
|
|
120
|
+
}).catch(console.error);
|
|
121
|
+
//# sourceMappingURL=exemple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exemple.js","sourceRoot":"","sources":["../src/exemple.ts"],"names":[],"mappings":";;;AAAA,kEAAkC;AAClC,mCAAsD;AAEtD,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;AAEvD,MAAM,EAAE,GAAG,cAAc,CAAA,CAAC,sDAAsD;AAEhF,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAGvB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IACnC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAGxB,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAGxB,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IACpC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAGvB,QAAQ,CAAC,WAAW,CAAC;IACnB,IAAI,EAAE,mBAAW,CAAC,QAAQ;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AAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA","sourcesContent":["import WhatsApp from \"./WhatsApp\";\nimport { StatusPresence, TypeMessage } from \"./model\";\n\nconst whatsapp = new WhatsApp({ server: \"\", key: \"\" });\n\nconst to = \"559999999999\" // If you want to send it to the group = 123456789@us\n\nwhatsapp.info().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.connect().then((response) => {\n console.log(response)\n}).catch(console.error);\n\n\nwhatsapp.logout().then((response) => {\n console.log(response)\n}).catch(console.error);\n\n\nwhatsapp.contacts().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.PRESENCE,\n body: {\n to: to,\n status: StatusPresence.COMPOSING\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.TEXT,\n body: {\n to: to,\n text: \"Hey\"\n }\n}).then((response) => {\n console.log(response)\n\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.TEXT,\n body: {\n msgId: \"SKJH455AJKJ\",\n to: to,\n text: \"Hey\"\n }\n}, true).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.AUDIO,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.IMAGE,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.VIDEO,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.DOCUMENT,\n body: {\n to: to,\n url: \"\",\n mimetype: \"\",\n fileName: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.CONTACT,\n body: {\n to: to,\n contact: {\n fullName: \"Raphael\",\n phoneNumber: to,\n organization: \"api-wa.me\"\n }\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.REACTION,\n body: {\n to: to,\n msgId: \"ASDDF872AHDURBSG\",\n text: \"🤖\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.groups().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.infoGroup(\"123456789@us\").then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.createGroup(\"Devs\", [to]).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.updateGroup(\"123456789@us\", \"Devs\", \"Only developers !\").then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface Init {
|
|
2
|
+
server: string;
|
|
3
|
+
key: string;
|
|
4
|
+
}
|
|
5
|
+
export declare enum HttpMethod {
|
|
6
|
+
GET = "GET",
|
|
7
|
+
POST = "POST",
|
|
8
|
+
PUT = "PUT",
|
|
9
|
+
DELETE = "DELETE",
|
|
10
|
+
PATCH = "PATCH"
|
|
11
|
+
}
|
|
12
|
+
export declare enum Routes {
|
|
13
|
+
INSTANCES = "instance",
|
|
14
|
+
MESSAGES = "message",
|
|
15
|
+
CONTACTS = "contacts",
|
|
16
|
+
GROUPS = "groups",
|
|
17
|
+
ACTIONS = "actions"
|
|
18
|
+
}
|
|
19
|
+
export declare enum TypeMessage {
|
|
20
|
+
PRESENCE = "presence",
|
|
21
|
+
TEXT = "text",
|
|
22
|
+
AUDIO = "audio",
|
|
23
|
+
IMAGE = "image",
|
|
24
|
+
VIDEO = "video",
|
|
25
|
+
DOCUMENT = "document",
|
|
26
|
+
CONTACT = "contact",
|
|
27
|
+
LOCATION = "location",
|
|
28
|
+
REACTION = "reaction"
|
|
29
|
+
}
|
|
30
|
+
export declare enum StatusPresence {
|
|
31
|
+
UNAVAILABLE = "unavailable",
|
|
32
|
+
AVAILABLE = "available",
|
|
33
|
+
COMPOSING = "composing",
|
|
34
|
+
RECORDING = "recording",
|
|
35
|
+
PAUSED = "paused"
|
|
36
|
+
}
|
|
37
|
+
export interface WebhookBody {
|
|
38
|
+
allowWebhook: boolean;
|
|
39
|
+
webhookMessage: string;
|
|
40
|
+
webhookGroup: string;
|
|
41
|
+
webhookConnection: string;
|
|
42
|
+
webhookQrCode: string;
|
|
43
|
+
webhookMessageFromMe: string;
|
|
44
|
+
webhookHistory: string;
|
|
45
|
+
}
|
|
46
|
+
export interface Contact {
|
|
47
|
+
fullName: string;
|
|
48
|
+
phoneNumber: string;
|
|
49
|
+
organization?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface Location {
|
|
52
|
+
latitude: number;
|
|
53
|
+
longitude: number;
|
|
54
|
+
address: string;
|
|
55
|
+
}
|
|
56
|
+
export interface Row {
|
|
57
|
+
title: string;
|
|
58
|
+
description: string;
|
|
59
|
+
rowId: string;
|
|
60
|
+
}
|
|
61
|
+
export interface Section {
|
|
62
|
+
title: string;
|
|
63
|
+
rows: Row[];
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatusPresence = exports.TypeMessage = exports.Routes = exports.HttpMethod = void 0;
|
|
4
|
+
var HttpMethod;
|
|
5
|
+
(function (HttpMethod) {
|
|
6
|
+
HttpMethod["GET"] = "GET";
|
|
7
|
+
HttpMethod["POST"] = "POST";
|
|
8
|
+
HttpMethod["PUT"] = "PUT";
|
|
9
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
10
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
11
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
12
|
+
var Routes;
|
|
13
|
+
(function (Routes) {
|
|
14
|
+
Routes["INSTANCES"] = "instance";
|
|
15
|
+
Routes["MESSAGES"] = "message";
|
|
16
|
+
Routes["CONTACTS"] = "contacts";
|
|
17
|
+
Routes["GROUPS"] = "groups";
|
|
18
|
+
Routes["ACTIONS"] = "actions";
|
|
19
|
+
})(Routes || (exports.Routes = Routes = {}));
|
|
20
|
+
var TypeMessage;
|
|
21
|
+
(function (TypeMessage) {
|
|
22
|
+
TypeMessage["PRESENCE"] = "presence";
|
|
23
|
+
TypeMessage["TEXT"] = "text";
|
|
24
|
+
TypeMessage["AUDIO"] = "audio";
|
|
25
|
+
TypeMessage["IMAGE"] = "image";
|
|
26
|
+
TypeMessage["VIDEO"] = "video";
|
|
27
|
+
TypeMessage["DOCUMENT"] = "document";
|
|
28
|
+
TypeMessage["CONTACT"] = "contact";
|
|
29
|
+
TypeMessage["LOCATION"] = "location";
|
|
30
|
+
TypeMessage["REACTION"] = "reaction";
|
|
31
|
+
})(TypeMessage || (exports.TypeMessage = TypeMessage = {}));
|
|
32
|
+
var StatusPresence;
|
|
33
|
+
(function (StatusPresence) {
|
|
34
|
+
StatusPresence["UNAVAILABLE"] = "unavailable";
|
|
35
|
+
StatusPresence["AVAILABLE"] = "available";
|
|
36
|
+
StatusPresence["COMPOSING"] = "composing";
|
|
37
|
+
StatusPresence["RECORDING"] = "recording";
|
|
38
|
+
StatusPresence["PAUSED"] = "paused";
|
|
39
|
+
})(StatusPresence || (exports.StatusPresence = StatusPresence = {}));
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;AAKA,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,0BAAV,UAAU,QAMrB;AAGD,IAAY,MAMX;AAND,WAAY,MAAM;IAChB,gCAAsB,CAAA;IACtB,8BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,2BAAiB,CAAA;IACjB,6BAAkB,CAAA;AACpB,CAAC,EANW,MAAM,sBAAN,MAAM,QAMjB;AAGD,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;AACvB,CAAC,EAVW,WAAW,2BAAX,WAAW,QAUtB;AAGD,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,6CAA2B,CAAA;IAC3B,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB","sourcesContent":["export interface Init {\n server: string;\n key: string;\n}\n\nexport enum HttpMethod {\n GET = 'GET',\n POST = 'POST',\n PUT = 'PUT',\n DELETE = 'DELETE',\n PATCH = 'PATCH',\n}\n\n\nexport enum Routes {\n INSTANCES = 'instance',\n MESSAGES = 'message',\n CONTACTS = 'contacts',\n GROUPS = 'groups',\n ACTIONS= 'actions',\n}\n\n\nexport enum TypeMessage {\n PRESENCE = 'presence',\n TEXT = 'text',\n AUDIO = 'audio',\n IMAGE = 'image',\n VIDEO = 'video',\n DOCUMENT = 'document',\n CONTACT = 'contact',\n LOCATION = 'location',\n REACTION = 'reaction'\n}\n\n\nexport enum StatusPresence {\n UNAVAILABLE = 'unavailable',\n AVAILABLE = 'available',\n COMPOSING = 'composing',\n RECORDING = 'recording',\n PAUSED = 'paused',\n}\n\n\n\nexport interface WebhookBody {\n allowWebhook: boolean;\n webhookMessage: string;\n webhookGroup: string;\n webhookConnection: string;\n webhookQrCode: string;\n webhookMessageFromMe: string;\n webhookHistory: string;\n}\n\nexport interface Contact {\n fullName: string;\n phoneNumber: string;\n organization?: string;\n}\n\n\nexport interface Location {\n latitude: number;\n longitude: number;\n address: string;\n}\n\nexport interface Row {\n title: string;\n description: string;\n rowId: string;\n}\n\nexport interface Section {\n title: string;\n rows: Row[];\n}"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raphaelvserafim/client-api-whatsapp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively.",
|
|
5
|
+
"main": "dist/WhatsApp.js",
|
|
6
|
+
"types": "dist/WhatsApp.d.ts",
|
|
7
|
+
"private": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"api",
|
|
10
|
+
"whatsapp",
|
|
11
|
+
"typescript",
|
|
12
|
+
"js",
|
|
13
|
+
"bot",
|
|
14
|
+
"whatsapp-api",
|
|
15
|
+
"whatsapp-bot",
|
|
16
|
+
"whatsapp-chat"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc --project tsconfig.compile.json",
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
21
|
+
"deploy": "npm run build && npm publish --access=public"
|
|
22
|
+
},
|
|
23
|
+
"author": "Raphael Serafim <raphaelvserafim@gmail.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/raphaelvserafim/client-api-whatsapp.git"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.6.8",
|
|
31
|
+
"fs": "^0.0.1-security",
|
|
32
|
+
"typescript": "^5.4.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@babel/preset-env": "^7.24.3",
|
|
36
|
+
"@jest/globals": "^29.7.0",
|
|
37
|
+
"@types/jest": "^29.5.12",
|
|
38
|
+
"@types/node": "^20.11.30",
|
|
39
|
+
"babel-jest": "^29.7.0",
|
|
40
|
+
"jest": "^29.7.0",
|
|
41
|
+
"ts-jest": "^29.1.2",
|
|
42
|
+
"tslib": "^2.6.2",
|
|
43
|
+
"typescript": "^5.4.3"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/WhatsApp.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section } from './model';
|
|
3
|
+
|
|
4
|
+
export class WhatsApp {
|
|
5
|
+
private readonly server: string;
|
|
6
|
+
private readonly key: string;
|
|
7
|
+
private route: string;
|
|
8
|
+
private method: HttpMethod | null = null;
|
|
9
|
+
private body: any = null;
|
|
10
|
+
|
|
11
|
+
constructor(data: Init) {
|
|
12
|
+
this.server = data.server;
|
|
13
|
+
this.key = data.key;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private async request(): Promise<any> {
|
|
17
|
+
if (!this.route || !this.method) {
|
|
18
|
+
throw new Error('Path and method must be defined before making a request.');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const options: AxiosRequestConfig = {
|
|
22
|
+
url: `${this.server}/${this.key}/${this.route}`,
|
|
23
|
+
method: this.method,
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json'
|
|
26
|
+
},
|
|
27
|
+
data: this.body ? JSON.stringify(this.body) : null
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response: AxiosResponse = await axios(options);
|
|
32
|
+
return response.data;
|
|
33
|
+
} catch (error: any) {
|
|
34
|
+
throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async connect(): Promise<any> {
|
|
40
|
+
this.route = Routes.INSTANCES;
|
|
41
|
+
this.method = HttpMethod.POST;
|
|
42
|
+
return await this.request();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async info(): Promise<any> {
|
|
46
|
+
this.route = Routes.INSTANCES;
|
|
47
|
+
this.method = HttpMethod.GET;
|
|
48
|
+
return await this.request();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async logout(): Promise<any> {
|
|
52
|
+
this.route = Routes.INSTANCES;
|
|
53
|
+
this.method = HttpMethod.DELETE;
|
|
54
|
+
return await this.request();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async setting(markMessageRead: boolean, saveMedia: boolean): Promise<any> {
|
|
58
|
+
this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;
|
|
59
|
+
this.method = HttpMethod.PATCH;
|
|
60
|
+
return await this.request();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async updateWebhook(body: WebhookBody): Promise<any> {
|
|
66
|
+
this.route = Routes.INSTANCES;
|
|
67
|
+
this.method = HttpMethod.PUT;
|
|
68
|
+
this.body = body;
|
|
69
|
+
return await this.request();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async sendMessage(
|
|
74
|
+
data: {
|
|
75
|
+
type: TypeMessage,
|
|
76
|
+
body: {
|
|
77
|
+
to: string,
|
|
78
|
+
msgId?: string,
|
|
79
|
+
status?: StatusPresence,
|
|
80
|
+
text?: string,
|
|
81
|
+
url?: string,
|
|
82
|
+
caption?: string,
|
|
83
|
+
mimetype?: string,
|
|
84
|
+
fileName?: string,
|
|
85
|
+
contact?: Contact,
|
|
86
|
+
location?: Location,
|
|
87
|
+
name?: string,
|
|
88
|
+
options?: string[],
|
|
89
|
+
sections?: Section,
|
|
90
|
+
footer?: string,
|
|
91
|
+
description?: string,
|
|
92
|
+
title?: string,
|
|
93
|
+
buttonText?: string,
|
|
94
|
+
}
|
|
95
|
+
}, reply: boolean = false ): Promise<any> {
|
|
96
|
+
if (reply) {
|
|
97
|
+
this.route = Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
|
|
98
|
+
} else {
|
|
99
|
+
this.route = Routes.MESSAGES + "/" + data.type;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.method = HttpMethod.POST;
|
|
103
|
+
this.body = data.body;
|
|
104
|
+
return await this.request();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async checkRegisteredWhatsapp(number: string) {
|
|
108
|
+
this.route = Routes.ACTIONS + "/registered?number=" + number;
|
|
109
|
+
this.method = HttpMethod.GET;
|
|
110
|
+
return await this.request();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
async contacts() {
|
|
115
|
+
this.route = Routes.CONTACTS;
|
|
116
|
+
this.method = HttpMethod.GET;
|
|
117
|
+
return await this.request();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async contactProfile(id: string) {
|
|
121
|
+
this.route = Routes.CONTACTS + "/" + id;
|
|
122
|
+
this.method = HttpMethod.GET;
|
|
123
|
+
return await this.request();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async groups() {
|
|
128
|
+
this.route = Routes.GROUPS;
|
|
129
|
+
this.method = HttpMethod.GET;
|
|
130
|
+
return await this.request();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async infoGroup(id: string) {
|
|
135
|
+
this.route = Routes.GROUPS + "/" + id;
|
|
136
|
+
this.method = HttpMethod.GET;
|
|
137
|
+
return await this.request();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async updateGroup(id: string, name: string, description: string) {
|
|
141
|
+
this.route = Routes.GROUPS + "/" + id;
|
|
142
|
+
this.method = HttpMethod.PUT;
|
|
143
|
+
this.body = {
|
|
144
|
+
name,
|
|
145
|
+
description
|
|
146
|
+
}
|
|
147
|
+
return await this.request();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async leaveGroup(id: string) {
|
|
151
|
+
this.route = Routes.GROUPS + "/" + id;
|
|
152
|
+
this.method = HttpMethod.DELETE;
|
|
153
|
+
return await this.request();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async createGroup(name: string, participants: string[]) {
|
|
157
|
+
this.route = Routes.GROUPS;
|
|
158
|
+
this.method = HttpMethod.POST;
|
|
159
|
+
this.body = {
|
|
160
|
+
name,
|
|
161
|
+
participants
|
|
162
|
+
}
|
|
163
|
+
return await this.request();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
export default WhatsApp;
|
|
170
|
+
|
|
171
|
+
|
package/src/exemple.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import WhatsApp from "./WhatsApp";
|
|
2
|
+
import { StatusPresence, TypeMessage } from "./model";
|
|
3
|
+
|
|
4
|
+
const whatsapp = new WhatsApp({ server: "", key: "" });
|
|
5
|
+
|
|
6
|
+
const to = "559999999999" // If you want to send it to the group = 123456789@us
|
|
7
|
+
|
|
8
|
+
whatsapp.info().then((response) => {
|
|
9
|
+
console.log(response)
|
|
10
|
+
}).catch(console.error)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
whatsapp.connect().then((response) => {
|
|
14
|
+
console.log(response)
|
|
15
|
+
}).catch(console.error);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
whatsapp.logout().then((response) => {
|
|
19
|
+
console.log(response)
|
|
20
|
+
}).catch(console.error);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
whatsapp.contacts().then((response) => {
|
|
24
|
+
console.log(response)
|
|
25
|
+
}).catch(console.error)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
whatsapp.sendMessage({
|
|
29
|
+
type: TypeMessage.PRESENCE,
|
|
30
|
+
body: {
|
|
31
|
+
to: to,
|
|
32
|
+
status: StatusPresence.COMPOSING
|
|
33
|
+
}
|
|
34
|
+
}).then((response) => {
|
|
35
|
+
console.log(response)
|
|
36
|
+
}).catch(console.error)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
whatsapp.sendMessage({
|
|
40
|
+
type: TypeMessage.TEXT,
|
|
41
|
+
body: {
|
|
42
|
+
to: to,
|
|
43
|
+
text: "Hey"
|
|
44
|
+
}
|
|
45
|
+
}).then((response) => {
|
|
46
|
+
console.log(response)
|
|
47
|
+
|
|
48
|
+
}).catch(console.error)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
whatsapp.sendMessage({
|
|
52
|
+
type: TypeMessage.TEXT,
|
|
53
|
+
body: {
|
|
54
|
+
msgId: "SKJH455AJKJ",
|
|
55
|
+
to: to,
|
|
56
|
+
text: "Hey"
|
|
57
|
+
}
|
|
58
|
+
}, true).then((response) => {
|
|
59
|
+
console.log(response)
|
|
60
|
+
}).catch(console.error)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
whatsapp.sendMessage({
|
|
65
|
+
type: TypeMessage.AUDIO,
|
|
66
|
+
body: {
|
|
67
|
+
to: to,
|
|
68
|
+
url: ""
|
|
69
|
+
}
|
|
70
|
+
}).then((response) => {
|
|
71
|
+
console.log(response)
|
|
72
|
+
}).catch(console.error)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
whatsapp.sendMessage({
|
|
76
|
+
type: TypeMessage.IMAGE,
|
|
77
|
+
body: {
|
|
78
|
+
to: to,
|
|
79
|
+
url: ""
|
|
80
|
+
}
|
|
81
|
+
}).then((response) => {
|
|
82
|
+
console.log(response)
|
|
83
|
+
}).catch(console.error)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
whatsapp.sendMessage({
|
|
87
|
+
type: TypeMessage.VIDEO,
|
|
88
|
+
body: {
|
|
89
|
+
to: to,
|
|
90
|
+
url: ""
|
|
91
|
+
}
|
|
92
|
+
}).then((response) => {
|
|
93
|
+
console.log(response)
|
|
94
|
+
}).catch(console.error)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
whatsapp.sendMessage({
|
|
99
|
+
type: TypeMessage.DOCUMENT,
|
|
100
|
+
body: {
|
|
101
|
+
to: to,
|
|
102
|
+
url: "",
|
|
103
|
+
mimetype: "",
|
|
104
|
+
fileName: ""
|
|
105
|
+
}
|
|
106
|
+
}).then((response) => {
|
|
107
|
+
console.log(response)
|
|
108
|
+
}).catch(console.error)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
whatsapp.sendMessage({
|
|
112
|
+
type: TypeMessage.CONTACT,
|
|
113
|
+
body: {
|
|
114
|
+
to: to,
|
|
115
|
+
contact: {
|
|
116
|
+
fullName: "Raphael",
|
|
117
|
+
phoneNumber: to,
|
|
118
|
+
organization: "api-wa.me"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}).then((response) => {
|
|
122
|
+
console.log(response)
|
|
123
|
+
}).catch(console.error)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
whatsapp.sendMessage({
|
|
127
|
+
type: TypeMessage.REACTION,
|
|
128
|
+
body: {
|
|
129
|
+
to: to,
|
|
130
|
+
msgId: "ASDDF872AHDURBSG",
|
|
131
|
+
text: "🤖"
|
|
132
|
+
}
|
|
133
|
+
}).then((response) => {
|
|
134
|
+
console.log(response)
|
|
135
|
+
}).catch(console.error)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
whatsapp.groups().then((response) => {
|
|
139
|
+
console.log(response)
|
|
140
|
+
}).catch(console.error)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
whatsapp.infoGroup("123456789@us").then((response) => {
|
|
144
|
+
console.log(response)
|
|
145
|
+
}).catch(console.error)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
whatsapp.createGroup("Devs", [to]).then((response) => {
|
|
150
|
+
console.log(response)
|
|
151
|
+
}).catch(console.error)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
whatsapp.updateGroup("123456789@us", "Devs", "Only developers !").then((response) => {
|
|
155
|
+
console.log(response)
|
|
156
|
+
}).catch(console.error)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export interface Init {
|
|
2
|
+
server: string;
|
|
3
|
+
key: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum HttpMethod {
|
|
7
|
+
GET = 'GET',
|
|
8
|
+
POST = 'POST',
|
|
9
|
+
PUT = 'PUT',
|
|
10
|
+
DELETE = 'DELETE',
|
|
11
|
+
PATCH = 'PATCH',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export enum Routes {
|
|
16
|
+
INSTANCES = 'instance',
|
|
17
|
+
MESSAGES = 'message',
|
|
18
|
+
CONTACTS = 'contacts',
|
|
19
|
+
GROUPS = 'groups',
|
|
20
|
+
ACTIONS= 'actions',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export enum TypeMessage {
|
|
25
|
+
PRESENCE = 'presence',
|
|
26
|
+
TEXT = 'text',
|
|
27
|
+
AUDIO = 'audio',
|
|
28
|
+
IMAGE = 'image',
|
|
29
|
+
VIDEO = 'video',
|
|
30
|
+
DOCUMENT = 'document',
|
|
31
|
+
CONTACT = 'contact',
|
|
32
|
+
LOCATION = 'location',
|
|
33
|
+
REACTION = 'reaction'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export enum StatusPresence {
|
|
38
|
+
UNAVAILABLE = 'unavailable',
|
|
39
|
+
AVAILABLE = 'available',
|
|
40
|
+
COMPOSING = 'composing',
|
|
41
|
+
RECORDING = 'recording',
|
|
42
|
+
PAUSED = 'paused',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export interface WebhookBody {
|
|
48
|
+
allowWebhook: boolean;
|
|
49
|
+
webhookMessage: string;
|
|
50
|
+
webhookGroup: string;
|
|
51
|
+
webhookConnection: string;
|
|
52
|
+
webhookQrCode: string;
|
|
53
|
+
webhookMessageFromMe: string;
|
|
54
|
+
webhookHistory: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Contact {
|
|
58
|
+
fullName: string;
|
|
59
|
+
phoneNumber: string;
|
|
60
|
+
organization?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export interface Location {
|
|
65
|
+
latitude: number;
|
|
66
|
+
longitude: number;
|
|
67
|
+
address: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface Row {
|
|
71
|
+
title: string;
|
|
72
|
+
description: string;
|
|
73
|
+
rowId: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Section {
|
|
77
|
+
title: string;
|
|
78
|
+
rows: Row[];
|
|
79
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"noResolve": false,
|
|
9
|
+
"preserveConstEnums": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"noEmit": false,
|
|
12
|
+
"emitDeclarationOnly": false,
|
|
13
|
+
"inlineSources": true
|
|
14
|
+
}
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"sourceMap": true,
|
|
6
|
+
"declaration": false,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"isolatedModules": false,
|
|
11
|
+
"suppressImplicitAnyIndexErrors": false,
|
|
12
|
+
"noImplicitAny": true,
|
|
13
|
+
"strictNullChecks": true,
|
|
14
|
+
"noUnusedLocals": false,
|
|
15
|
+
"noUnusedParameters": false,
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
"importHelpers": true,
|
|
18
|
+
"newLine": "LF",
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"resolveJsonModule": true,
|
|
22
|
+
"lib": [
|
|
23
|
+
"es7",
|
|
24
|
+
"dom",
|
|
25
|
+
"ESNext.AsyncIterable"
|
|
26
|
+
],
|
|
27
|
+
"typeRoots": [
|
|
28
|
+
"./node_modules/@types"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"include": ["src/**/*.ts"],
|
|
32
|
+
"linterOptions": {
|
|
33
|
+
"exclude": []
|
|
34
|
+
}
|
|
35
|
+
}
|