npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jxdevroot/smsglobal

v1.2.6

Published

SDK for SMSGlobal rest api

Downloads

3

Readme

SMSGlobal node SDK

Build codecov Node npm Downloads

THIS IS A CUSTOM FORK OF THE ORIGINAL REPO. THE ORIGINAL REPO IS LOCATED AT link THIS LIBRARY USES LATEST VERSION OF AXIOS TO RESOLVE SECURITY VULNERABILITIES

The SMSGlobal Node library provides convenient access to the SMSGlobal REST API from node applications.

Sign up for a free SMSGlobal account today and get your API Key from our advanced SMS platform, MXT. Plus, enjoy unlimited free developer sandbox testing to try out your API in full!

Example

Check out the code examples

SMSGlobal rest API credentials

Rest API credentials can be provided in the SMSGlobal client or node environment variables. The credential variables are SMSGLOBAL_API_KEY and SMSGLOBAL_API_SECRET

Installation

npm install --save smsglobal

Usage

  • Require smsglobal in your file
const apiKey = 'YOUR_API_KEY';
const apiSecret = 'YOUR_API_SECRET';
var smsglobal = require('smsglobal')(apiKey, secret);

All method return promise if no callback is given

To send a sms

var payload = {
    origin: 'from number',
    destination: 'destination',
    message: 'This is a test message'
}

smsglobal.sms.send(payload, function (error, response) {
    console.log(response);
});

To fetch a list outgoing sms

var promise = smsglobal.sms.getAll();

promise
    .then(function(response) {
        console.log(response)
    })
    .catch(function(error){
        console.log(error)
    });

To fetch an outgoing sms by id

var id = 'outgoing-sms-id';
var promise = smsglobal.sms.get(id);

promise
    .then(function(response) {
        console.log(response)
    })
    .catch(function(error){
        console.log(error)
    });

To fetch a list incoming sms

var promise = smsglobal.sms.incoming.getAll();

promise
    .then(function(response) {
        console.log(response)
    })
    .catch(function(error){
        console.log(error)
    });

To fetch an incoming sms by id

var id = 'incoming-sms-id';
var promise = smsglobal.sms.incoming.get(id);

promise
    .then(function(response) {
        console.log(response)
    })
    .catch(function(error){
        console.log(error)
    });

To send an OTP

var payload = {
  origin: 'from number',
  message: '{*code*} is your SMSGlobal verification code.',
  destination: 'destination'
};

// {*code*} placeholder is mandatory and will be replaced by an auto generated numeric code.

smsglobal.otp.send(payload, function(error, response) {
  if (response) {
    console.log(response);
  }

  if (error) {
     console.log(error);
  }
});

Success response object

{
  statusCode: 200,
  status: 'OK',
  data: {
    requestId: '404372541683676561917558',
    destination: '61400000000',
    validUnitlTimestamp: '2020-11-18 17:08:14',
    createdTimestamp: '2020-11-18 16:58:14',
    lastEventTimestamp: '2020-11-18 16:58:14',
    status: 'Sent'
  }
}

Error response object in the case of validation error

{
  statusCode: 400,
  status: 'Bad Request',
  data: {
    errors: {
      message: {
        errors: [
          'Message template should contain a placeholder for code i.e. {*code*}.'
        ]
      }
    }
  }
}

To cancel an OTP request

The OTP request can be cancelled if it's not expired and verified yet. It can be done by either using requestId or destination number. The followings are examples of each method:

var id = 'otp-request-id'; // requestId received upon sending an OTP
var promise = smsglobal.otp.cancelByRequestId(id)

promise.then((response) => {
   console.log(response)
}).catch((err) => {
   console.log(error)
});
var destination = 'destination-number';
var promise = smsglobal.otp.cancelByDestination(id)

promise.then((response) => {
   console.log(response)
}).catch((err) => {
   console.log(error)
});

Success response object

{
  statusCode: 200,
  status: 'OK',
  data: {
    requestId: '404372541683676561917558',
    destination: '61400000000',
    validUnitlTimestamp: '2020-11-18 17:08:14',
    createdTimestamp: '2020-11-18 16:58:14',
    lastEventTimestamp: '2020-11-18 16:58:14',
    status: 'Cancelled'
  }
}

To verify an OTP code entered by your user

The OTP code entered by your user can be verified by either using requestId or destination number. The followings are examples of each method:

var id = 'otp-request-id'; // requestId received upon sending an OTP
var code = 'otp-code'; // input code entered by your user

smsglobal.otp.verifyByRequestId(id, code, function(error, response) {
  if (response) {
    console.log(response);
  }

  if (error) {
     console.log(error);
  }
});
var destination = 'destination-number';
var code = 'otp-code'; // input code entered by your user

smsglobal.otp.verifyByDestination(id, code, function(error, response) {
  if (response) {
    console.log(response);
  }

  if (error) {
     console.log(error);
  }
});

Success response object

{
  statusCode: 200,
  status: 'OK',
  data: {
    requestId: '404372541683676561917558',
    destination: '61400000000',
    validUnitlTimestamp: '2020-11-18 17:08:14',
    createdTimestamp: '2020-11-18 16:58:14',
    lastEventTimestamp: '2020-11-18 16:58:14',
    status: 'Verified'
  }
}

Running tests

Run the tests:

npm test

To run test with code coverage report

npm run mocha-only

Available REST API Resources

  • Sms
  • Sms Incoming
  • OTP (beta)

Reference

REST API Documentation

For any query contact us