-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 838 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const axios = require('axios');
async function sendBulkMessages(recipients, message) {
try {
// Iterate over the recipients array and send a message to each recipient
for (const recipient of recipients) {
const response = await axios.post('https://api.whatsapp.com/v1/messages', {
to: recipient,
type: 'text',
content: {
text: message
}
}, {
headers: {
'Authorization': 'Bearer <YOUR_AUTH_TOKEN>'
}
});
console.log(`Message sent to ${recipient}: ${response.status}`);
}
} catch (error) {
console.error(error);
}
}
// Example usage
const recipients = ['1234567890', '0987654321', '6789054321'];
const message = 'Hello, this is a bulk message sent using the WhatsApp Business API.';
sendBulkMessages(recipients, message);