-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiClient.js
More file actions
31 lines (26 loc) · 1.06 KB
/
apiClient.js
File metadata and controls
31 lines (26 loc) · 1.06 KB
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
31
// Ensure Node.js version is 18+ for built-in fetch support
const fetch = require('node-fetch'); // If using Node.js <18, install this via `npm install node-fetch`
const sendOtp = async () => {
const phoneNumber = '919339399097';
const API_KEY = 'hellowhoisthis007'; // Replace with your actual API key
const SERVER_URL = 'https://whatsapp-server-bqvf.onrender.com'; // Replace with your server's URL if hosted elsewhere
try {
const response = await fetch(`${SERVER_URL}/otp/generate?key=${API_KEY}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify({ phone: phoneNumber })
});
const data = await response.json();
if (response.ok) {
console.log('✅ OTP Sent Successfully:', data);
} else {
console.error('❌ Failed to send OTP:', data);
}
} catch (error) {
console.error('❌ Error sending OTP:', error.message);
}
};
sendOtp();