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

@kairosafrika/sms

v1.0.15

Published

A Observable-based wrapper implementation that exposes all of Kairos' SMS APIs making integration into your backend for sending SMS easier and faster

Downloads

46

Readme

Kairos Bulk SMS Node

Dev Status CI Status Tests codecov.io Node License

A Observable-based wrapper implementation that exposes all of Kairos' SMS APIs making integration into your backend for sending SMS easier and faster

Table Of Contents

Features

  • Send Quick SMS
  • Send Bulk SMS
  • Ping the status of an already sent SMS
  • Check your account balance
  • Provides method chaining under-the-hood
  • Supports typescript from the get-go
  • Unsubscribed to method calls with the unsubscribe() method from rxjs

Installation

Quickly use the package by running either of the below commands

Using npm:

npm i @kairosafrika/sms

or Using yarn:

yarn add @kairosafrika/sms

Request Structure

Find the request structure when making an API request for Quick SMS.

{
    "to": "xxxxxxxxx",
    "from": "KAIROS",
    "message": "this is a test message"
}

Find the request structure when making an API request for Quick SMS with multiple phone numbers or msisdns.

{
    "to": "233200746423,23094990599",
    "from": "KAIROS",
    "message": "this is a test message"
}

Find the request structure when making an API request for Bulk SMS.

{
  "messages": [
    {
      "to": "233200746417",
      "from": "Kairos Test",
      "message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
      "type": "Quick"
    }
  ]
}

Note: type is optional but accepts only two values; Quick & Flash

Response Structure

Find the response structure when a successful or failed response is returned.

200 OK

{
  "statusMessage": "SMS scheduled successfully",
  "statusCode": 200,
  "success": true,
  "data":  true,
  "timestamp": "2022-04-21T06:46:22.983Z"
}

400 Bad Request

{
  "statusMessage": "Invalid path params passed",
  "statusCode": 200,
  "success": true,
  "data":  { 
    "message": "URl accept the id of sent message"
  },
  "timestamp": "2022-04-21T06:46:22.983Z"
}

Example

Note: This package is implemented in typescript hence no need to install typings

// importing the package as a default
import KairosSMS from "@kairosafrika/sms";

or

import { KairosSMS } from "@kairosafrika/sms"

Sending a quick SMS

KairosSMS
    .send({ apiKey: 'xxxxxxxxx', apiSecret: 'xxxxxxx', timeout: 90000}, {to: "xxxxxxxxxxx", from: "kairos", message: "this is a test message"})
    .asQuick()
    .subscribe(response => {
        // handle response 
        console.log(response)
})

Sending a bulk SMS

KairosSMS
    .send({apiKey: 'xxxxxxxx', apiSecret: 'xxxxxxxx', timeout: 90000},{
        "messages": [
            {
                "to": "233200746417",
                "from": "Kairos Test",
                "message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
                "type": "Quick"
            }
        ]
    })
    .asBulk()
    .subscribe(response => {
        // handle response
        console.log(response)
    })

NOTE: Kairos SMS package also exposes an independent function that allows you to convert Observables to Promises to use async/await

import { asPromise } from "@kairos/sms";
// always don't forget to append `async` if the function is created as found below
async function sendSMS() {
    const response = await asPromise(
        KairosSMS
        .send({ apiKey: 'xxxxxxxxx', apiSecret: 'xxxxxxx', timeout: 90000}, {to: "xxxxxxxxxxx", from: "kairos", message: "this is a test message"})
        .asQuick()
    )
    console.log(response)
}

Kairos SMS API

Requests can be made by passing the relevant configs to KairosSMS.create()

Creating an instance

You can create an instance of KairosSMS with the relevant configs

KairosSMS.create([config])

const instance = KairosSMS.create({ 
    apiKey: 'xxxxxxxxxxx', 
    apiSecret: 'xxxxxxxxxx', 
    timeout: 800000
})

Instance Methods

There are two main available instance methods that exposes send methods and check balance methods, This includes | Method | description | |--------------------|-------------------------| | send(data) | called when you want to send sms or check the current status of an already sent sms | account() | called when you want to check the account balance | contacts() | called when you want to GET,PATCH,DELETE contact details associated with an account

Send(data)

After you've created the instance, you can then call the send(data) method,

const response = instance.send(data)

Which exposes all the necessary methods below

asQuick()
asBulk()
asQuickMultipleMSISDN()

This method allows customer to send same message to multiple msisdns or phone numbers by using a comma separated values for the to property in the request object at Request Structure

  "to":"233200746423,23094990599"

Example

response
    .asQuickMultipleMSISDN()
    .subscribe(data => {
        // handle response here
        console.log(data)
    })
asPing()

This method is a bit different because it accepts the id of the sent sms instead of an object to make the request. Hence, something like so

instance
    .send("2")
    .asPing()
    .subscribe(response => {
        // handle response here
        console.log(response)
    })

Account()

After you've created the instance, you can then call the account() method,

const response = instance.account()

Which exposes the method below

balance()

Get current user balance with this

response
    .balance()
    .subscribe(response => {
        // handle response here
        console.log(response)
})

Contacts()

Contacts method also exposes a handful of functions that to allow you to GET,PATCH, POST contacts to your accounts | HTTP Verb | Methods | Descriptions | Active | |-----------|--------------------------------|--------------------------------------------------------|----------------------| | GET | setPage(), setSize(), asList() | Get a paginated list of all your contacts | :heavy_check_mark: | | POST | create() | Create a new contact by calling the create() method | :heavy_check_mark: | | GET | details() | Get the details of a particular contact | :heavy_check_mark: | | PUT | update(id) | Update the details of a contact | :heavy_check_mark: | | DELETE | delete(id) | Delete a contact details | :heavy_check_mark: |

The contacts() method accept an optional options parameter of type IContactsOptions which is of the format

interface IContactsOptions {
    paginate: {
        page: number;
        size: number;
    },
    body: {
        name: string;
        phone: string;
        dateOfBirth?: string
    }
}
List All Contacts
asList()

Get a paginated list of your contacts from the Kairos Afrika Bulk SMS Platform by calling asList()

Example #1

Make a request by passing page and size directly to the contacts() method

instance
     .contacts({
         paginate: {
             page: 1,
             size: 15
         }
     })
     .asList()
     .subscribe(response => {
         //handle repsonse here
        console.log(response)
    })
Example #2

Make a request by performing method chaining

instance
      .contacts()
      .setPage(1)
      .setSize(15)
      .asList().subscribe(response => {
          // handle response here
        console.log(response)
    })

Make a request by passing configs and optional options to the static contacts() method

Options - the current page and the total size to show per page

{
    page: 1, 
    size: 15
}
Example #3
const response = KairosSMS
    .contacts(configs, {
        paginate: {
            page: 1, 
            size: 15
           }
        }
    )
    .asList()
    .subscribe(response => {
    //handle response here
    console.log(response)
})

NB. calling setPage & setSize overrides what's been set as the static contacts method.

Create A Contact

Create a new contact via Kairos SMS API by calling either of these two procedures

Example #1

Create an instance of the Kairos SMS that exposes the contacts() method and then pass the body of the contact to be created directly to that method

const instance = KairosSMS.create([config])
const response$ = instance.contacts({
    body: {
        name: "Jane Doe",
        phone: "0203746417",
        dateOfBirth: null
    }
}).create();
response$.subscribe(data => {
    // handle response here
    console.log(data)
})
Example #2

You can also pass the body of the contact to be created directly to the create method that's exposed by the contacts() method.

const response$ = instance.contacts().create({
    name: "Jane Doe",
    phone: "0203746417",
    dateOfBirth: "2022-01-01"
})
response$.subscribe(data => {
    // handle response here
    console.log(data)
})
Get a Contact Details

Get the details of a particular contact by passing the id as a parameter

Example #1
const response$ = instance.contacts().details(12)
response$.subscribe((data) => {
    // handle response here
    console.log(data)
})
Update a Contact

Update the details of a contact by passing the contact id and the payload as a parameter

Example #1

Pass the payload or the request body as a part of the contacts() method and then the contactId as a parameter to the update(id) chained method.

const response$ = instance.contacts({
    body: {
        name: "Jane Doe",
        phone: "0203746417",
        dateOfBirth: null
    }
}).update(12);
response$.subscribe(data => {
    // handle response here
    console.log(data)
})
Example #2

You can also pass both the request payload and the id as parameters to the update() method

const response$ = instance.contacts().update(12,
    {
        name: "Jane Doe",
        phone: "0203746417",
        dateOfBirth: null
    });
response$.subscribe(data => {
    // handle response here
    console.log(data)
})
Delete A Contact

Remove a specific contact from your contact list by passing the contactId as a parameter to delete(id) exposed by the contacts() method

Example #1
const response$ = instance.contacts().delete(12)
response$.subscribe((data) => {
    // handle response here
    console.log(data)
})

Note that the contact method is also exposed as a static method which can be accessed by doing this

import {KairosSMS} from "@kairosafrika/sms"
KairosSMS
     .contacts({
        apiKey: 'xxxxxxxxxx',
        apiSecret: 'xxxxxxxxxxx'
     }, {
        body: {
          name: "Jane Doe",
          phone: "0203746417",
          dateOfBirth: null
        }
     }).create().subscribe(data => {
        // handle response here
        console.log(data)
     })

NB. Don't forget that the instance you'll create will contain the apiKey & apiSecret with an optional timeout

Credits

Kairos SMS Node is heavily inspired by axios

License

MIT