OTP SEND VIA Fast2sms
Fri Jul 26 2024 05:26:16 GMT+0000 (Coordinated Universal Time)
Saved by
@codeing
#javascript
app.post('/send-otp', async (req, res) => {
const { phoneNumber } = req.body;
const apiKey = '3mW3hfluK8dpayQ53NXKdBhophrKP9sD8GKPi8qKqsMTZAAEsyq8HGMZCeSv';
const otp = Math.floor(100000 + Math.random() * 900000); // Generate a 6-digit OTP
const message = `${otp}`;
const data = {
sender_id: 'TKSOLV',
message: '110131',
variables_values: message,
route: 'dlt',
numbers: phoneNumber,
};
const options = {
method: 'POST',
headers: {
'authorization': apiKey,
'Content-Type': 'application/json'
},
data: JSON.stringify(data),
url: 'https://www.fast2sms.com/dev/bulkV2',
};
try {
const response = await axios(options);
res.status(200).send({ success: true, message: 'OTP sent successfully', otp: otp });
} catch (error) {
res.status(500).send({ success: false, message: 'Failed to send OTP', error: error.message });
}
});
content_copyCOPY
Comments