@jambonz/node-client

0.4.6 • Public • Published

@jambonz/node-client

A Node.js SDK for the open source jambonz CPaaS platform. Node.js applications can use this library to respond to jambonz webhooks and to make REST API calls to a jambonz platform.

Note: One suggested way to get up and running with this Node SDK is to use the npx create-jambonz-app command, which will scaffold out a jambonz application for you using this SDK.

Webooks

To respond to webhooks, you will need a lightweight http server. An example is shown below using express.

const {WebhookResponse} = require('@jambonz/node-client');
const express = require('express');
const app = express();

app.use(express.json());

app.post('/my-app', (req, res) => {
  const jambonz = new WebhookResponse();
  jambonz
    .pause({length: 1.5})
    .say({
      text: 'Good morning. This is a simple test of text to speech functionality.  That is all.  Goodbye',
      synthesizer: {
        vendor: 'google',
        language: 'en-US'
      }
    });
  res.status(200).json(app);
});

app.listen(port, () => {
  logger.info(`listening at http://localhost:${port}`);
});

See here for information on the available verbs you can use in a jambonz application, and for their associated properties.

Verifying webhook signature

If your jambonz server includes a Jambonz-Signature header on webhook requests, you can verify that the request was signed by jambonz using your webhook secret as follows:

const {WebhookResponse} = require('@jambonz/node-client');

if (process.env.WEBHOOK_SECRET) {
  app.use(WebhookResponse.verifyJambonzSignature(process.env.WEBHOOK_SECRET));
}

const express = require('express');
const app = express();

app.use(express.json());

/* make sure this comes after the body has been converted to json */
if (process.env.WEBHOOK_SECRET) {
  app.use(WebhookResponse.verifyJambonzSignature(process.env.WEBHOOK_SECRET));
}

/* if we get here we know the request was signed with our webhook secret */
app.post('/my-app', (req, res) => { ...})

REST API calls

Creating a client

To use the REST API you need to know your account sid and api key (both of which you can view in the jambonz portal). You generate a REST client as shown below.

const client = require('@jambonz/node-client')(<my-account-sid>, <my-api-key>, {
  baseUrl: http://<my-jambonz-sbc>
});

All of the above parameters are required (account sid, api key, and baseUrl);

Calls

Creating a call
const sid = await client.calls.create({
  from: '16172223333',
  to: {
    type: 'phone',
    number: '15083084808'
  },
  call_hook: 'http://myurl.com/myapp-webhook',
  call_status_hook: 'http://myurl.com/call-status'
});

See here for further details.

Updating a call

To update a call in progress -- for example to mute/unmute, hangup the call etc -- you need to know the call sid. Typically you would get this from a webhook sent from an existing call event.

  // play a whisper prompt to one party on the call
  await client.calls.update(<my-call-sid>, {
    whisper: {
        verb: 'say',
        text: 'You have 30 seconds remaining on this call.'
      }
    }
  });

See here for further details.

Example

See here for a full-featured example application built using this API.

Status

This project is under active development and is currently very much pre-beta.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.661latest

Version History

VersionDownloads (Last 7 Days)Published
0.4.661
0.4.5234
0.4.43
0.4.363
0.4.215
0.4.165
0.3.94275
0.3.930
0.3.921
0.3.910
0.3.900
0.3.890
0.3.87434
0.3.860
0.3.850
0.3.840
0.3.830
0.3.820
0.3.810
0.3.800
0.3.790
0.3.781
0.3.776
0.3.760
0.3.750
0.3.740
0.3.735
0.3.720
0.3.710
0.3.700
0.3.691
0.3.681
0.3.670
0.3.661
0.3.651
0.3.640
0.3.635
0.3.620
0.3.610
0.3.604
0.3.590
0.3.582
0.3.570
0.3.560
0.3.550
0.3.541
0.3.530
0.3.526
0.3.510
0.3.500
0.3.492
0.3.461
0.3.481
0.3.470
0.3.450
0.3.441
0.3.430
0.3.420
0.3.410
0.3.400
0.3.390
0.3.380
0.3.370
0.3.360
0.3.350
0.3.340
0.3.330
0.3.320
0.3.300
0.3.290
0.3.280
0.3.270
0.3.260
0.3.251
0.3.240
0.3.230
0.3.220
0.3.210
0.3.200
0.3.190
0.3.180
0.3.170
0.3.160
0.3.150
0.3.140
0.3.120
0.3.110
0.3.100
0.3.90
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.240
0.2.230
0.2.220
0.2.210
0.2.200
0.2.190
0.2.180
0.2.170
0.2.160
0.2.150
0.2.140
0.2.130
0.2.120
0.2.110
0.2.100
0.2.90
0.2.80
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.1.00
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.11

Package Sidebar

Install

npm i @jambonz/node-client

Weekly Downloads

899

Version

0.4.6

License

MIT

Unpacked Size

45.3 kB

Total Files

47

Last publish

Collaborators

  • beachdog