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

spryng

v1.0.1

Published

NodeJS SDK for the Spryng SMS API

Downloads

1,156

Readme

Spryng NodeJS SDK

npm version

This is a NodeJS SDK for the Spryng SMS platform. The SDK makes it easy to implement the Spryng messaging system in your Node environment.

Installation

The package can be installed from NPM using

yarn add spryng

or

npm i spryng

Configuration

All the SDK needs is an API key. You can create an API key in your Spryng account settings:

  • Log in to your account in the Spryng dashboard
  • Under 'My data', click on 'Profile'
  • Scroll down to 'REST API keys' and generate a new API key

You can now initialize the SDK as follows:

import { Spryng } from 'spryng'

const API_KEY = 'YourApiKey'

const spryng = new Spryng(API_KEY)

Sending messages

Use the following code to send a message:

import { Spryng } from 'spryng'

const API_KEY = 'YourApiKey'

const spryng = new Spryng(API_KEY)

const message = await spryng.message.send({
  encoding: 'auto',
  body: 'Test message',
  route: 'business',
  originator: 'Example Company',
  recipients: ['31612345678', '31687654321'],
  reference: 'ABC123'
})

Listing Messages

It is possible to list messages that have been sent through the API:

import { Spryng } from 'spryng'

const API_KEY = 'YourApiKey'

const spryng = new Spryng(API_KEY)

const message = await spryng.message.list({
  recipient_number: '31612345678'
}, ['recipients'])

List message response

The response object for listing messages mimics the API as follows:

total: Total number of results

per_page: Number of results per page

current_page: The current page that is fetched

last_page: The number of pages

next_page_url: Full URL of the next page GET endpoint

prev_page_url: Full URL of the previous page GET endpoint

from: From index in the total results

to: To index in the total results

data: Array of Message objects, the actual result data

List message filters

The first argument of the list method is an object of filters that can be specified to limit the results:

originator: String used as the originator property when sending the messages

recipient_number: The phone number of the recipient

reference: A reference that has optionally been specified when creating the message

created_from: Date range for when the message has been created

created_until: Date range for when the message has been created

scheduled_from: Date range when the message has been scheduled to be send

scheduled_toDate range when the messsage has been scheduled to be send

status: Send status of the message

Fetching single message

Instead of listing, a single message can be fetched as well by its ID:

import { Spryng } from 'spryng'

const API_KEY = 'YourApiKey'

const spryng = new Spryng(API_KEY)

const message = await spryng.message.show('91d95b85-b32f-42bd-a9fb-4cde0a56424x')

Cancel a message

Scheduled messages can be canceled from being send:

import { Spryng } from 'spryng'

const API_KEY = 'YourApiKey'

const spryng = new Spryng(API_KEY)

const message = await spryng.message.cancel('91d95b85-b32f-42bd-a9fb-4cde0a56424x')