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

nvoip-node-sms

v1.1.0

Published

Send SMS messages in node via Nvoip SMS API.

Downloads

3

Readme

nvoip-node-sms

Send SMS messages in node via Nvoip SMS API.

Installation

Install nvoip-node-sms from npm

with yarn:

yarn add nvoip-node-sms

or alternatively using npm:

npm install --save nvoip-node-sms

Testing

With yarn:

yarn test

or alternatively using npm:

npm run test

Basic usage

To be able to send messages, you'll need an access token provided by Nvoip. You can get it by signing in on https://www.nvoip.com.br. After signing in, go to 'Configurações' > 'Integrações' and click the button 'Abrir' on the 'ExactSales' div to launch a pop up window. You should be able to copy the token string (the string that follows the word 'Token') from there.


// Import the client factory function:

const { createClient } = require('nvoip-node-sms');

// or alternatively using ES6 imports:
// import { createClient } from 'nvoip-node-sms';

// Instantiate a client:

const client = createClient({ authToken: '523abc21d8b659bc19553d5ce5b42' });

// Send a message!

client.sendSms('1111111111', 'Hi!')
  .then(response => console.log(response))
  .catch(error => console.error(error));

// That's it!

Command line utility

nvoip-node-sms bundles with a simple command line utililty that enables you to send messages without the need to write any code.

You can check the available options using

./bin/send-sms --help

Be sure the script has the necessary permissions to execute. You can, of course, use chmod +x ./bin/send-sms for that.

Its also possible to run it without installation using npx.

API

createClient(config)

Creates a client for sending messages.

Parameters:

  • config Object» a configuration object:
    • authToken «String» the authentication token.
    • [url] «String» the API endpoint.
    • [request] «Function» custom request function. (see the request module for more details).

Returns

A SMS client «SmsClient».

Example


const client = createClient({
  url: 'https://api.nvoip.com.br/v1/sms',
  authToken: '523abc21d8b659bc19553d5ce5b42',
});

SmsClient.prototype.sendSms(phoneNumber, textMessage)

  • phoneNumber «String» a phone number containing nothing but digits.
  • textMessage «String» the message to be sent.

Returns

A promise «Promise» containing the API response data.

Throws

  • «MessageValidationError» if the textMessage is invalid.
  • «PhoneNumberValidationError» if the phoneNumber is invalid.
  • «HttpRequestError» if the HTTP request failed.

Example


const client = createClient({
  authToken: '523abc21d8b659bc19553d5ce5b42',
});

client.sendSms('121212121', 'How are you doing?')
  .then(data => console.log(data));

Error Handling

A collection of errors are provided in order to enable proper error handling and control flow. You can safely use the instanceof operator in a catch block to detemine the precise source and cause of the error.

Error hierarchy:

  • «SmsClientError»
    • «HttpRequestError»
    • «ValidationError»
      • «PhoneNumberValidationError»
      • «MessageValidationError»

Check the errors module for more details.

Example:


//...
const {
  ValidationError,
  HttpRequestError,
  createClient,
} = require('nvoip-node-sms');

// Immediately invoked asynchronous function
(async () => {

  // ...

  const client = createClient({
    authToken: '523abc21d8b659bc19553d5ce5b42',
  });

  // ...

  let response;

  try {
    response = await client.sendSms('1125235235', 'Hi!');
  } catch (err) {
    if (err instanceof ValidationError) {
      console.error('error: be more careful with your input!');
    } else if (err instanceof HttpRequestError) {
      console.error('error: maybe check your network connection?!');
    } else {
      // Unknown error, don't treat it:
      throw err;
    }
  }

  console.log(response);

  // ...
}())

// ...