Created
November 22, 2018 16:53
-
-
Save abkunal/7c8eb06100edc85afd40cee52cdaf36e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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