Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

messagebird

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messagebird

A node.js wrapper for the MessageBird REST API

  • 2.4.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

MessageBird REST API for Node.js

This repository contains the open source Node.js client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com

Requirements

  • Sign up for a free MessageBird account
  • Create a new access_key in the developers section
  • MessageBird REST API for Node.js requires Node.js >= 0.10 or io.js

Installation

npm install messagebird

Usage

We have put some self-explanatory examples in the examples directory, but here is a quick breakdown on how it works. Let's go ahead and initialize the library first. Don't forget to replace <YOUR_ACCESS_KEY> with your actual access key.

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

Nice! Now we can send API requests through node. Let's use getting your balance overview as an example:

// Get your balance
messagebird.balance.read(function (err, data) {
  if (err) {
    return console.log(err);
  }
  console.log(data);
});

// Result object:
{
  payment: 'prepaid',
  type: 'credits',
  amount: 42.5
}

Or in case of an error:

{ [Error: api error]
  errors: [
    {
      code: 2,
      description: 'Request not allowed (incorrect access_key)',
      parameter: 'access_key'
    }
  ]
}

Verifying Signatures

We sign our HTTP requests to allow you to verify that they actually came from us (authentication) and that they haven't been altered along the way (integrity). For each HTTP request that MessageBird sends, a MessageBird-Signature and MessageBird-Request-Timestamp header is added. Signature middleware calculates a signature using the timestamp, query parameters and body then compares the calculated signature to MessageBird-Signature header. If they are not same or request expired, middleware throws an error. This way, you will know if the request is valid or not. If you want to verify request manually, you can check here. Let's use Signature middleware to verify webhooks.

var Signature = require('messagebird/lib/signature');

// Replace <YOUR_SIGNING_KEY> with your actual signing key.
var verifySignature = new Signature('<YOUR_SIGNING_KEY>');

// Retrieve the raw body as a buffer.
app.use(require('body-parser').raw({ type: '*/*' }));

// Verified webhook.
app.get('/webhook', verifySignature, function(req, res) {
    res.send("Verified");
});

Documentation

Complete documentation, instructions, and examples are available at: https://developers.messagebird.com

License

The MessageBird REST API for Node.js is licensed under The BSD 2-Clause License. Copyright (c) 2014, MessageBird

Keywords

FAQs

Package last updated on 06 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc