App Configuration > Server > Webhook
For voice apps in prototyping stage, we recommend using a local webserver and a service like jovo webhook or bst proxy. This way, you can easily update your app without having to upload it to a server or AWS Lambda every time.
Jovo uses the express
framework for running a server. Here is how the part of index.js
, which is used to run the app on a webhook, looks like:
'use strict';
const {Webhook} = require('jovo-framework');
const {app} = require('./app/app.js');
if (app.isWebhook()) {
const port = process.env.PORT || 3000;
Webhook.listen(port, () => {
console.log(`Example server listening on port ${port}!`);
});
Webhook.post('/webhook', (req, res) => {
app.handleWebhook(req, res);
});
}
You can either run your server locally, or deploy to a webhosting service.
You can use either of the following commands to run the server locally:
# Using the Jovo CLI
$ jovo run
# Alternative
$ node index.js
Make sure that, with every file update, you terminate the server with ctrl+c
and run it again. Find more information on the jovo run
command here: CLI: jovo run.
$ jovo run
should return this:
Local development server listening on port 3000.
This is your webhook url: https://webhook.jovo.cloud/[your-id]
As you can see, a jovo webhook
URL is automatically created, which serves as a link to your local webhook and can be posted as a HTTPS endpoint to the voice platforms.
Here are all the services that can point to your local development server:
- jovo webhook (default)
- bst proxy
- ngrok
The jovo webhook
is a free service that creates a link to your local webserver. This way, you can prototype locally without having to deal with servers or Lambda uploads all the time.
By using the jovo init
command or jovo run
, a unique, anonymized link is created that looks like this:
https://webhook.jovo.cloud/[your-id]
This link simply makes it easier for you to prototype locally by being able to see the logs in your command line, and to make fast changes without uploading your code to AWS Lambda.
You can either use this link and paste it into the respective developer platform consoles, or use the jovo deploy
command to upload it from the command line (jovo webhook
is the default endpoint
added to app.json
with the jovo init
command).
Find the following sections in our beginner tutorials to learn how to do so:
With the bst proxy by Bespoken, you can create a link similar to the jovo webhook, but with additional features like logging.
You can run the proxy with the jovo run
command:
$ jovo run --bst-proxy
This is what the result looks like:
Now, you can not only use the link as an endpoint, but also use it to access Bespoken Analytics for powerful logging capabilities:
Ngrok is a tunneling service that makes your localhost accessible to outside APIs.
You can download ngrok like so:
# Open a new tab in your command line tool, then:
$ npm install ngrok -g
# Point ngrok to your localhost:3000
$ ngrok http 3000
It should display something similar to this:
When you want to deploy your code to a webserver other than AWS Lambda, you need to verify that Alexa Skill requests are actually coming from Amazon.
For this, Jovo uses a package called alexa-verifier-middleware, which can be accessed by switching one line of the configuration in index.js
:
// Use this
const Webhook = require('jovo-framework').WebhookVerified;
// Instead of this
const {Webhook} = require('jovo-framework');
To make use of it, please install it like so:
$ npm install alexa-verifier-middleware