• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The open source Node.js client for MessageBird's REST API

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.

CommonJS require syntax:

const messagebird = require('messagebird').initClient('<YOUR_ACCESS_KEY>');

Typescript with ES6 import (or .mjs with Node >= v13):

import { initClient } from 'messagebird';
const messagebird = initClient('<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'
    }
  ]
}

Notes

Messaging and Voice API use different pagination semantics:

Messaging API uses limit and offset params for list methods (where applicable)

// list conversations
// In this case 20 is limit and 0 is offset
messagebird.conversations.list(20, 0, function (err, response) {
  if (err) {
    return console.log(err);
  }
  console.log(response);
});

Voice API uses page and perPage params for list methods (where applicable)

// list Call Flows
// In this case 1 is page, 2 is items per page
messagebird.callflows.list(1, 2, function (err, response) {
  if (err) {
    return console.log(err);
  }
  console.log(response);
});

Verifying Signatures

For each HTTP request that MessageBird sends, a MessageBird-Signature-JWT header is added.

The MessageBird-Signature-JWT header is a signature that consists of all the information that is required to verify the integrity of the request. The signature is generated from the request URL and request body and is signed with the HMAC-SHA256 algorithm using your your signing key. You can validate this signature using our SDKsto ensure that the request is valid and unaltered. The token also includes timestamp claims that allow you to prove the time of the request, protecting from replay attacks and the like. For more details consult the documentation.

Examples:

Let's use Express Signature middleware to verify webhooks.

// This example show how to verify the authenticity of a MessageBird webhook.
const mbWebhookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
const express = require('express');

const secret = '<YOUR SIGNING KEY>';

const app = express();

// If the node server is behind a proxy, you must trust the proxy to infer the correct protocol and hostname.

app.set('trust proxy', () => true);

// Replace <YOUR_SIGNING_KEY> with your actual signing key.
const verifySignature = new mbWebhookSignatureJwt.ExpressMiddlewareVerify(secret);

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

// Verified webhook.
app.get('/webhook', verifySignature, (req, res) => {
  res.send('verified');
});
app.post('/webhook', verifySignature, (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) 2022, MessageBird

More Repositories

1

sachet

SMS alerts for Prometheus' Alertmanager
Go
216
star
2

php-rest-api

This repository contains the open source PHP client for MessageBird's REST API.
PHP
158
star
3

go-rest-api

MessageBird's REST API for Go
Go
120
star
4

pushprom

Pushprom is a proxy to the Prometheus Go client.
Go
80
star
5

python-rest-api

This repository contains the open source Python client for MessageBird's REST API.
Python
65
star
6

csharp-rest-api

This repository contains the open source C# client for MessageBird's REST API.
C#
54
star
7

java-rest-api

This repository contains the open source Java client for MessageBird's REST API.
Java
50
star
8

clickhouse-postgres-fdw

This project provides federated access to Clickhouse cluster from Postgres, with the ability to write FDW API functions in GO.
Go
45
star
9

ruby-rest-api

MessageBird's REST API for Ruby
Ruby
37
star
10

beanstalkd_exporter

A beanstalkd stats exporter for Prometheus
Go
34
star
11

slackincident

This node.js app is allowing you to start an incident management process via a Slack slash command.
JavaScript
27
star
12

gcppromd

Prometheus GCP discovery
Go
18
star
13

mysql-monitor

A tool to monitor mysql databases
Go
12
star
14

firestore-send-msg

Source code for MessageBird Firebase send message extension
TypeScript
11
star
15

python-grpc-argument-validator

Python
7
star
16

pushprom-php-client

PHP client for Pushprom
PHP
6
star
17

dart-rest-api

MessageBird's REST API for Dart
Dart
5
star
18

messagebird-magento-integration

Integrate magento (v2) with the MessageBird Flow Builder
PHP
3
star
19

messagebird-magento

PHP
3
star
20

pushprom-yii2-client

Yii 2 client for Pushprom
PHP
2
star
21

openapi-specs

Open API specifications of MessageBird public API's
1
star