Send an One Time Password (OTP) via the Twilio SMS gateway
Updated Jun 06, 2023
Version 2.0Was this article helpful?
// Import the f5-nodejs module.
var f5 = require('f5-nodejs');
// Create a new rpc server for listening to TCL iRule calls.
var ilx = new f5.ILXServer();
const accountSid = 'AC7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your Account SID from www.twilio.com/console
const authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your Auth Token from www.twilio.com/console
const client = require('twilio')(accountSid, authToken);
ilx.addMethod('sendOTP', function(req, res) {
var generatedOTP = req.params()[0];
var telephoneNumber = req.params()[1];
var sender = req.params()[2];
var message = 'Your OTP is: ' + generatedOTP;
client.messages.create({
body: message,
to: telephoneNumber, // Text this number
messagingServiceSid: 'MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
from: sender // From a valid Twilio number
})
.then(function(message) {
return res.reply(message.sid);
});
});
// Start listening for ILX::call and ILX::notify events.
ilx.listen();
If i sent with this, message is sent and i also see Service Name on twilio dashboard, but i receive the sms with number as sender.
If i commnet "messagingServiceSid", message still sent but i don't see Service Name on twilio dashboard and this is right.
But if i comment "from", message never arrive at twilio.