Giter VIP home page Giter VIP logo

sendotp-node's Introduction

Official NodeJS Wrapper for MSG91 API

Documentation

The documentation for the MSG91 API can be found here

The Node library v1.0 documentation can be found here.

DLT Scrubbing

You can get your content template approved by desginated TRAI authorities. We have made a comprehensive document here

Documentation

The documentation for the MSG91 API can be found here

The Node library v1.0 documentation can be found here.

Sample Usage

var msg91 = require("@walkover/msg91")("API_KEY", "SENDER_ID", "ROUTE_NO" );


/**
 * Mobile number should be with International dialling code. Ex - 91 for India, 44 for UK. 
 *
 * @param {mobileNo} Accepts single number
 * @param {mobileNo} Accepts array of the phone number.
 * @param {mobileNo} Accepts CSV string.
 */

var mobileNo = "XXXXXXXXXX";

var mobileNo = [ "XXXXXXXXXX", "XXXXXXXXXX", "XXXXXXXXXX" ];

var mobileNo =  "XXXXXXXXXX,XXXXXXXXXX,XXXXXXXXXX";

msg91.send(mobileNo, "MESSAGE", "DLT_TE_ID", function(err, response){
    console.log(err);
    console.log(response);
});

Get Balance for a route

// Default 
msg91.getBalance(function(err, msgCount){
    console.log(err);
    console.log(msgCount);
});

// Get Balance for given Route.
msg91.getBalance("ROUTE_NO", function(err, msgCount){
    console.log(err);
    console.log(msgCount);
});

Getting help

Please reach out to us on [email protected]

MSG91 Variables

ROUTE_NO

1 - Promotional Route
4 - Transactional Route
106 - SendOTP Route

sendotp-node's People

Contributors

beeeku avatar karuppiah7890 avatar priyankapathak avatar rwalkover avatar sarfarazansari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sendotp-node's Issues

Feature Request: Token Expiration

Please add a feature for generating token with some expiry time and in verify api validate the token on the basis of expiry time as well.

otp sending failed still get success response

i have tried sendOtp.send for sending otp.
And i got the response
{ message: '376941717932393732393030', type: 'success' }
But when i checked it in MSG91 it shows the status as "Rejected by Kannel or Provider "

Not able to use it in Nuxt.js Framework

Hi,

I tried to install and use your package called sendotp : https://www.npmjs.com/package/sendotp

I have created a plugin 'sendotp' in my plugins directory here's the code:

import Vue from 'vue'
import SendOtp from 'sendotp';
const sendOtp = new SendOtp('AuthKey');
Vue.config.productionTip = false
Vue.use(SendOtp, sendOtp)

And added in my plugins list in nuxt.config.js:

plugins: ['~/plugins/sendotp.js']

And getting this error:

TypeError
Class constructor SendOtp cannot be invoked without 'new'

Any Suggestions ?

Limit otp verify api call

Hi, I want to know what is the default limit for verify api call?

Also, How can it be set in the dashboard?

I went through the api doc, but I couldn't find any option there.

All I could find this error message,

Max limit reached:

{"message":"Max limit reached for this otp verification","type":"error"}


Link to the doc

Not working in AWS Lambda function

This below code works in NodeJS Express framework but when I deployed same code in AWS Lambda function it didn't work.
Here's my demo code.

*** BEGIN ***

const SendOtp = require('sendotp');
const objSendOtp = new SendOtp('<API_SECRET>');

objSendOtp.send(, , , function(err, data){
if(err) console.log(err);
else
console.log(data);
});

*** END ***

OTP expiry after one successful verification

Hi,
Is there any feature of verifying the otp only once and then the otp expires after one successful verification.

Incase, the feature is present, kindly let me know how to use it, if not then will that be added soon ?

I have used otp expiry, but in my implementation, I need it to expire after one successful verification.

Allow promise based handling of api

The current mechanism of working with OTP DOEN NOT have a mechanism to use Promises. That might be needed, as working with a combination of async/await makes it diffucult to use the api

How can we set template id

const Otp = new sendotp('AUTH_KEY','templateid'); can i set template id like this its not working how can we set template id and send the otp

not working with aws lambda

exports.handler = async (event, context, callback) => {
const SendOtp = require('sendotp');
const sendOTP = new SendOtp('260981AZN8sH3O5c551802');
sendOTP.send(mobileNum,"611332", (error, data) => {
if(err) {
return err;
} else {
const response = {
statusCode: 200,
body: data.message,
};
return response;
}
})

this is my lambda function and when i invoke the api endpoint i get null as result and nothing more. The function block of sendOTP is not working.

Getting error on send API call.

Using below code to send message
sendOtp.send(req.mobileNumber, 2424, (error, data) => {
console.log("%%%%", data);
}); //otp is optional if not sent it'll be generated automatically

Getting error:
POST /api/auth/otp - - ms - -
%% { message: 'Some Parameter are missing : mobiles/group_id',
type: 'error' }

Typescript support

Please generate @types/sendotp module or .d.ts, the auto-generated index file is not working.

AUTO-GENERATED INDEX

export = index;
declare class index {
static doRequest(method: any, path: any, params: any, callback: any): void;
static generateOtp(): any;
static getBaseURL(): any;
constructor(authKey: any, messageTemplate: any);
authKey: any;
messageTemplate: any;
otp_expiry: any;
retry(contactNumber: any, retryVoice: any, callback: any): any;
send(contactNumber: any, senderId: any, otp: any, callback: any): any;
setOtpExpiry(otp_expiry: any): void;
verify(contactNumber: any, otp: any, callback: any): any;
}

README issues

The README has some punctuation problems while showing function definitions and also while showing function calls - like for verify() function call

International OTP does not work.

Trying to send international OTP, doesn't work.
It will require an extra parameter to be sent "country=0" to the API for it to be considered as international OTP SMS.

Uncaught exception for retryVoice = true

if I use retryVoice = true , it does not work , fail with "Uncaught exception" however working perfectly with false

sendOtp.retry(phone, false, function (error, data, res) {
if(data.type == 'success'){
console.log('resent successfully');
admin.database().ref('/users/' + phone)
.update({ code: code, codeValid: true }, () => {
response.send({ success: true });
});
}
else {
return response.status(422).send(err);
}
});

React Native Support

Hi,

currently I'm developing React Native where i need to use MSG91 for Use register OTP Verification. but I'm getting Current error while compiling

bundling failed: Error: Unable to resolve module cryptofrom/Users/apple/Desktop/Projects/RN/REG/node_modules/request/lib/helpers.js: Module crypto does not exist in the Haste module map

May be this npm package wont work in react native. please help me asap.

Getting error while using sendotp method

Error:-
request is not defined
at Function.doRequest (/node_modules/sendotp/index.js:161:9)

Code in index.js:-
request(options, function(error, response, data) {
// request error
if (error) {
return callback(error, data, response);
}

        // JSON parse error or empty strings
        try {
            // An empty string is a valid response
            if (data === '') {
                data = {};
            }
            else {
                data = JSON.parse(data);
            }
        }
        catch(parseError) {
            return callback(
                new Error('JSON parseError with HTTP Status: ' + response.statusCode + ' ' + response.statusMessage),
                data,
                response
            );
        }


        // response object errors
        // This should return an error object not an array of errors
        if (data.errors !== undefined) {
            return callback(data.errors, data, response);
        }

        // status code errors
        if(response.statusCode < 200 || response.statusCode > 299) {
            return callback(
                new Error('HTTP Error: ' + response.statusCode + ' ' + response.statusMessage),
                data,
                response
            );
        }
        // no errors
        callback(null, data, response);
    });

Another README issue

Another example code issue with README. Callback function has buggy code. "data" object has key "type" now, and not "msgType"

Move mocha and nock to devDependencies

These build tools are unnecessarily getting added into our build process and giving deprecation warning. Please move them into devDependencies in package.json

Check Status Method

If you could provide checkStatus method that was available previously on this sdk , that would be very helpful .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.