msg91-sendotp-promise
v1.0.0
Published
This is a module for using api from msg91-service for sending and verifying OTP
Downloads
7
Maintainers
Readme
msg91-sendotp-promise
SendOtp - Node.js SDK
This is a module for using api from msg91-service for sending and verifying OTP
Set-up:
- Download the NPM module
npm install msg91-sendotp-promise --save
- Require the package in your code.
const SendOtp = require('msg91-sendotp-promise');
- Initialize with your MSG91 auth key
const sendOtp = new SendOtp('AuthKey');
That's all, your SDK is set up!
Requests
You now have the send, retry and verify otp via following methods.
const sendObj = await sendOtp.send(contactNumber, senderId, otp, callback); //otp is optional if not sent it'll be generated automatically
const resendObj = await sendOtp.retry(contactNumber, retryVoice, callback);
const verifyObj = await sendOtp.verify(contactNumber, otpToVerify, callback);
Note:
Success object
{ "type": "success", "message": "aaaaaaaaaaaaaaaaaaaaaaa"}
Error object sample code
{ "type": "error","message": "ERROR_MESSAGE" }
Options:
By default sendotp uses default message template, but custom message template can also set in constructor like
const SendOtp = require('msg91-sendotp-promise');
const sendOtp = new SendOtp('AuthKey', 'Otp for your order is {{otp}}, please do not share it with anybody');
{{otp}}
expression is used to inject generated otp in message.