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

savannacom

v0.3.4

Published

Unnoficial Javascript SDK for the savannacom Hermes SMS API; Works on the client and server.

Downloads

172

Readme

savannacom

A fully typed unnoficial Javascript SDK for the Savannacom Hermes SMS API. Unnoficial meaning it is not developed by Savannacom but by Cerebrus Inc.

It uses cross-fetch under the hood to enable the platform and environment agnostic usage.

Additionally, the functions and methods include checks to ensure that you are sending a number in the corrcet format. Incorrect numbers are automatically rejected. Duplicate messages are recognised via multiple entries with the same phone number; The same message content will not count as a duplicate message.

NOTE

  • This is accurate to their API as at 23 Nov 2023.
  • Phone number format is 260... as a 12 digit string.
  • One message is defined as having 160 characters, any excess characters will count as additional message(s) of which you will be charged for.

Importing

// ES6 Module
import * as savannacom from "savannacom";

// ES6 Destructuring
import { SMS } from "savannacom";

// Commonjs Module
const savannacom = require("savannacom");

// Commonjs Destructuring
const { SMS } = require("savannacom");

You can also add the CDN via jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"></script>

Exports

We export the following:

SMS(id, username)

This is a class that needs to be instanciated with auth params. The methods are automatically called without need to pass authorusation. The methods are:

  • sendSms(number, content): Promise<SavannacomResponse>
    • Send a single SMS to a single recipient.
    • Returns a Savannacom API response object.
  • bulkSms(data, withDuplicates?): Promise<BulkSMSResponse>
    • A custom method to ease sending bulk SMS' to multiple recipients; Note that this method may be subject to rate limits and can be resource intensive if the list is fairly large.
    • By default it will ignore duplicates unless the param is set to true
    • Returns a custom response object with errors and their details, as well as any duplicates and their details.

sendSms(id, username, number, content): Promise

A function to send a single SMS to a single recipient; Requires auth on every call. It operates exaclty like the class based method.

bulkSms(is, username, data, withDuplicates?): Promise

A custom function to send bulkSms; Requires auth on every call. It operates exaclty like the class based method.

BulkSMSObject

This is a custom type not provided by Savannacom; Ideal usage would be if you would like to dynamically generate the details for a bulk sms operation prior to calling the bulkSms function or method.

Usage

You can use both class based and function based implementions via async/await or promises.

Class Based

This is ideal for backend usage wherein you can create an instance on startup and use it without needing to continously pass the auth params on every call.

example

import { SMS } from "savannacom";

const sms = new SMS(process.env.SENDER_ID, process.env.SENDER_USERNAME);

const sendUpdate = async (number, message) => {
	const update = await sms.sendSms(number, message);

	if (update.error) {
		// log errors
	}
};

// we are not passing true to the withDuplicates param, therefore, the operation will not send requests for the duplicated phone number entries
const sendMultipleUpdates = async (data) => {
	const updates = await sms.bulkSms(data);

	if (updates.errors) {
		// log errors
	}

	if (updates.duplicates) {
		// handle duplicates
	}
};

sendUpdate("260970101010", "Test 1");
sendMultipleUpdates([
	{ number: "260970101010", content: "Test 2" },
	{ number: "260970909090", content: "Test 3" },
]);

Function Based

This can be used in the browser or in your favourite framework. It requires auth params on every call so ensure to keep them obfuscated.

import { sendSms, bulkSms } from "savannacom";

// Promise based example
sendSms("00000", "username", "260970101010", "Test 4")
	.then((update) => {
		// success handler
	})
	.catch((error) => {
		// error handler
	});

// Passing true to param withDuplicates will send the duplicate entries
const sendMultipleUpdates = async (data, withDuplicates) => {
	const updates = await bulkSms("00000", "username", data, withDuplicates);

	if (updates.errors) {
		// log errors
	}

	if (updates.duplicates) {
		// handle duplicates
	}
};

sendMultipleUpdates(
	[
		{ number: "260970101010", content: "Test 4" },
		{ number: "260970101010", content: "Test 5" },
	],
	true
);

Utils

This package comes with some utils to make it more secure to interface with the API. Any errors raised by these checks will not run the request. The following list is in order of importance:

  • Phone numbers with non numerical chars will immediately be rejected
  • Phone numbers not equal to 12 chars will immediately be reject
  • Phone numbers not beginning with 26 will immediately be rejected
  • Phone numbers that are not the following will be rejected:
    • 097
    • 077
    • 096
    • 076
    • 095
    • 075
  • It does not enforce content length to be less than 160 chars; If you do not want to mistakenly go over the limit you may enforce this on your own

Types

SavannacomResponse

The Savannacom API response object.

{
	status: string;
	message: string;
	data: {
		sender_username: string;
		sender_id: string;
		sender_message: string;
		msisdn: string;
	};
	error?: string;
}

BulkSMSObject

The custom bulk SMS request interface.

{
	number: string;
	content: string;
}

BulkSMSResponseError

The custom bulk SMS error object.

{
	number: string;
	error: string;
}

BulkSMSResponse

The cusotom bulk SMS Response object.

{
	errors?: BulkSMSResponseError[];
	duplicates?: BulkSMSObject[];
}

Changelog

v0.3.x

  • Updated readme CDN import
  • Added bulksms to package.json keywords
  • Added `MIT license
  • Added README
  • Exported custom type BulkSMSResponse and function based functions
  • Added function based approach

v0.2.x

  • Added duplicates parameter to BulkSMSResponse

v0.1.x

  • Fixed carrier identiier problem
  • Initial release
  • Added class based approach
  • Added interaces