Files
next-static-site/markdown/docs/client-sdks/nodejs-sdk.md
Brandon Lee Kitajchuk db94b17829 Latest news + banner, cypress tests, open source copy, general style tweaks (#13)
* Adding latest news and banners

* Adding first draft of cypress specs and github actions workflow

* Adding sticky position for top banner

* Tweak styles for new latest news section

* Tweak styles for text__layout innerHTML

* Fix Cypress homepage test spec

* Fix mobile navi z-index with sticky top banner

* Fix sticky banner z-index bug with mobile navi

* Refactor markdown tools to support pages beyond developer docs

* Adjust TADHACK text max-widths for small mobile

* initial changes for open source copy

* more copy

* more copy

* updated open source structure

* minor

* typo

* more copy

* Adjust styles for Open Source markdown small text

* Update readme and remove floats from docs webhooks markdown

* Add readme notes on Cypress and flesh out navi spec tests

* Fix main navi highlight when on sub-sections of markdown pages

Co-authored-by: Dave Horton <daveh@beachdognet.com>
2021-07-22 12:34:01 -04:00

55 lines
2.9 KiB
Markdown

# jambonz Node.js SDK
The jambonz Node.js SDK is one of the simplest and most powerful ways to build jambonz applications.
The video below provides a walk-through of how to create an application using the [create-jambonz-app](/docs/client-sdks/create-jambonz-app) utility, and then gives examples of building various webhooks applications that include collecting speech or dtmf input as well as integration with Google [Dialogflow](https://developers.google.com/learn/pathways/chatbots-dialogflow) and AWS [Lex V2](https://aws.amazon.com/blogs/aws/amazon-lex-enhanced-console-experience/).
<div class="video-wrap">
<iframe width="560" height="315" src="https://www.youtube.com/embed/42jcqyvCstU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
#### Up and running
As mentioned above, the [create-jambonz-app](/docs/client-sdks/create-jambonz-app) will scaffold you an [express](https://expressjs.com/)-based app that provides a great starting point.
If you prefer to use a different http server, or you need to integrate the jambonz webhooks into an existing Node.js application, then you simply need to install [@jambonz/node-client](https://www.npmjs.com/package/@jambonz/node-client) in your application.
```bash
npm install --save @jambonz/node-client
```
If your application just needs to respond to [webhooks](/docs/webhooks/overview/), you can include it like this:
```js
const {WebhookResponse} = require('@jambonz/node-client');
```
If your application also needs to make [REST API calls](/docs/rest/overview/), you can include it like this:
```js
const jambonz = require('@jambonz/node-client');
const {WebhookResponse} = jambonz;
const client = jambonz('your-account-sid', 'your-api-key', {baseUrl: 'https://jambonz.us'});
```
> Note: if you are running a self-hosted system, replace `https://jambonz.us` in the above with the appropriate URL of your own jambonz system.
#### How to use it - Webhooks
Responding to webhooks is quite simple:
```js
router.post('/', (req, res) => {
const app = new WebhookResponse();
app
.pause({length: 1.5})
.say({
text 'hi there, and welcome to jambonz!'
});
res.status(200).json(app);
```
The WebhookResponse instance offers methods corresponding to each of the [jambonz verbs](/docs/webhooks/overview/), so for the example above you can see the possible options for the `pause` verb [here](/docs/webhooks/pause/), and for the `say` verb [here](/docs/webhooks/say/). After adding all of the verbs that you want to execute, in the order that you want them to happen, simply return the `app` object in the 200 OK to the HTTP request.
#### How to use it - REST API
To making a REST API call simply use the `client` object we showed how to create earlier:
```js
await client.calls.update(req.body.call_sid, {mute_status: 'mute'});
```
Documentation for the REST API can be found [here](/docs/rest/overview/).