1.0.4 • Published 2 years ago

@saralsms/sdk-for-node v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

SaralSMS SDK for Node.js

Package Downloads License

The SaralSMS SDK for Node.js makes it easy for developers to access SaralSMS API service in their Node.js applications, and build robust SMS based applications and software.

Getting Started

  1. Sign up for SaralSMS – Before you begin, you need to sign up for an SaralSMS account and retrieve your Credentials.
  2. Minimum requirements – To run the SDK, your system will need to meet the minimum requirements, including having Node.js >= 8.0.

Installation

Install the SDK – Using npm or Yarn is the recommended way to install the SaralSMS SDK for Node.js. The SDK is available via npm under the @saralsms/sdk-for-node package.

// npm
npm install @saralsms/sdk-for-node
// yarn
yarn add @saralsms/sdk-for-node

Getting Help

We use the GitHub issues for tracking bugs and feature requests and address them as quickly as possible.

Quick Examples

Create a SaralSMS client

import SaralSms from '@saralsms/sdk-for-node';
// instantiate a SaralSMS client.
const saral = new SaralSms('f9c6......55c1');

where f9c6......55c1 is the authentication token.

Send Message

This will send the message to one or multiple numbers in an array.

saral
  .sendSms(['9851xxx123', '9801xxx456'], 'This is test message from API.')
  .then((res) => {
    // success
    console.log(res);
  })
  .catch((error) => {
    // error
    console.log(error);
  });

Sample Response

{
    "message": "2 messages queued for delivery."
}

Credits

This will return the available credits and total messages sent.

saral
  .getCredits()
  .then((res) => {
    // success
    console.log(res);
  })
  .catch((error) => {
    // error
    console.log(error);
  });

Sample Response

{
  "credits": 6584,
  "total_sent": 3416
}

Reports

This will return historical messages reports including networks, charges and status.

const pageNumber = 1;
saral
  .getReports(pageNumber)
  .then((res) => {
    // success
    console.log(res);
  })
  .catch((error) => {
    // error
    console.log(error);
  });

Sample Response

{
  "pages": 126,
  "data": [
    {
      "id": 56480058,
      "receiver": "9779851xxx123",
      "network": "ntc",
      "message": "Fruits are an excellent source of essential vitamins and minerals.",
      "api_credit": "1",
      "delivery_at": "2020-07-09 01:45:09"
    },
    {
      "id": 56480057,
      "receiver": "9779801xxx456",
      "network": "ncell",
      "message": "Vegetables are important sources of many nutrients, including potassium, dietary fiber.",
      "api_credit": "1",
      "delivery_at": "2020-07-08 07:25:31"
    }
  ]
}