msg91-sendotp-promise

1.0.0 • Public • Published

msg91-sendotp-promise

SendOtp - Node.js SDK

This is a module for using api from msg91-service for sending and verifying OTP

Set-up:

  1. Download the NPM module
npm install msg91-sendotp-promise --save
  1. Require the package in your code.
const SendOtp = require('msg91-sendotp-promise');
  1. 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.

Dependents (0)

Package Sidebar

Install

npm i msg91-sendotp-promise

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.93 kB

Total Files

4

Last publish

Collaborators

  • andriy_antonenko