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 });
}
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter