Skip to content

Instantly share code, notes, and snippets.

@abkunal
Created November 22, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abkunal/7c8eb06100edc85afd40cee52cdaf36e to your computer and use it in GitHub Desktop.
Save abkunal/7c8eb06100edc85afd40cee52cdaf36e to your computer and use it in GitHub Desktop.
const http = require('http');
function sendOTP (phone, callback) => {
let path = '/api/sendotp.php?otp_length=6&authkey=' + OTP_AUTH_KEY +
'&message=&sender=MySHIK&mobile=+91'+ phone +'&otp_expiry=5';
path = encodeURI(path);
let options = {
'method': 'POST',
'hostname': 'control.msg91.com',
'port': null,
'path': path,
'headers': {},
};
let req = http.request(options, function(res) {
let chunks = [];
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function() {
let body = Buffer.concat(chunks);
try {
callback(null, JSON.parse(body.toString()));
} catch (err) {
callback('Some error occurred');
}
});
});
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment