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

websms

v1.0.1

Published

A custom nodejs websms.com sdk for sending text and binary sms

Downloads

13

Readme

websms.js Build Status

Custom nodejs sdk for websms.com services

This module should be a better and stable implementation of the original websms.com sdk. https://websms.com/

No additional dependencies!

It is a SMS text/binary messaging tool for node.js

websms.js module provides an easy-to-use API for sending SMS text and binary messages through websms.com API (https://api.websms.com).

Simple examples can be found in the examples.js.

Features:

  • Text Messages
  • Binary Messages
  • Confirmation of Delivery
  • Answers to SMS can be forwarded
  • Only usable in modules

See websms.com website to register for an account.

For general API specification of the server (nodejs independent) visit: https://api.websms.com

Installation

Install with npm:

$ npm install websms

Tests

Tests are runnable after running npm install. (mocha and expect.js as devDependencies)

$ mocha spec/tests

Usage

  1. require
var websms = require('websms');
  1. Create a client object (once)
var client = new websms.Client(username, password);
  1. Create a Message object (or many)
var TextMessage = new websms.TextMessage(unicodeMessageText, recipientAddressList);
  1. Send Message object over Client
client.send(TextMessage, maxSmsPerMessage, isTest, callback);

Parameters explained:

  • username : {string}username used in basic authentication. This is your websms.com account username
  • password : {string} password used in basic authentication This is your websms.com account password
  • recipientAddressList : {Array} of strings containing message recipient mobile numbers (MSISDN) like ['4367612345678','4369912345678']
  • unicodeMessageText : {string} messageContent string sent that will be included in JSON object and sent as charset utf-8 to API. Special characters should be escaped as unicode. Euro sign is \u20AC.
  • maxSmsPerMessage : {Number} integer number 1-255 telling how many concatenated sms parts are the limit for sending this message. (in case the text is longer than what fits into multiple sms)
  • isTest : {boolean} false to really send sms. true to just test interface connection and process
  • callback : {Function} function that is called after success or error - parameter: error, response

Quick Message Construction

You don't need to use setter methods, it's also possible create a message with all properties at once:

TextMessage = new websms.TextMessage(messageContent, recipientAddressList, {
       'senderAddress'           : "AlphanumericSender",
       'senderAddressType'       : 'alphanumeric',  // also possible values: 'shortcode', 'international', 'national
       'sendAsFlashSms'          : true,
       'priority'                : 1,
       'notificationCallbackUrl' : 'https://my_server_for_send_notification',
       'clientMessageId'         : "My custom message id"
    });

If there was an error during message creation -> you can find it on TextMessage.error (object with cause, message as keys). If you not check this the Client.send method will do it and calling your sending callback with that error object.

Callback function format

callback(error, response)

function (error, response) {
    // error = {
    //   cause: String with error code 
    //   message: String with error message
    // }
    
    // repsonse = if request was successfully sent -> this is the response object
    var statusCode      = repsonse.statusCode;
    var statusMessage   = repsonse.statusMessage;
    var transferId      = repsonse.transferId;
    var clientMessageId = repsonse.clientMessageId;
};

Classes

Client

new websms.Client(user, password)

Methods/Functions
 Client.send(messageObject, maxSmsPerMessage, isTest, callback)
 

TextMessage

new websms.TextMessage(messageContent, recipientAddressList, optionalOptions)

Methods/Functions
 TextMessage.getMessageContent()

BinaryMessage

new websms.BinaryMessage(messageContentSegments, recipientAddressList, userDataHeaderPresent, optionalOptions)

Methods/Functions
 BinaryMessage.getMessageContent()
 BinaryMessage.getUserDataHeader()
 BinaryMessage.setUserDataHeader(userDataHeader)

Message

Base class for all messages (every message inherits from Event.Emitter)

Methods/Functions
 Message.getRecipientAddressList()
 Message.getSenderAddress()
 Message.setSenderAddress(senderAddress)
 Message.getSenderAddressType()
 Message.setSenderAddressType(senderAddressType)
 Message.getSendAsFlashSms()
 Message.setSendAsFlashSms(sendAsFlashSms)
 Message.getNotificationCallbackUrl()
 Message.setNotificationCallbackUrl(notificationCallbackUrl)
 Message.getClientMessageId()
 Message.setClientMessageId(clientMessageId)
 Message.getPriority()
 Message.setPriority(priority)