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; //otp is optional if not sent it'll be generated automaticallyconst resendObj = await sendOtp;const verifyObj = await sendOtp;
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 = ;const 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.