In this section, you will learn more about the project structure of a Jovo Voice App.
A Jovo project is divided into two main building blocks:
- Project Files: Overall project related files, e.g. language models and platform project information
- Source Files: The actual code of your app. Can be found in the
src
folder
These files are in the root folder and include anything that is needed to publish a project to voice platforms like Amazon Alexa and Google Assistant.
Project files include:
The project.js
file stores all the necessary information for your Jovo project, for example which voice platforms are built for.
Here is the project.js
file of the Jovo Sample App:
// ------------------------------------------------------------------
// JOVO PROJECT CONFIGURATION
// ------------------------------------------------------------------
module.exports = {
alexaSkill: {
nlu: 'alexa',
},
googleAction: {
nlu: 'dialogflow',
},
endpoint: '${JOVO_WEBHOOK_URL}',
};
The models folder contains the Jovo Language Model, which can be used to create and update platform specific language models using the Jovo CLI.
The idea is to maintain a single language model locally instead of having to go to the platform developer consoles independently.
In the models
folder, every language gets a file. For example, here's how a file en-US.json
could look like:
{
"invocation": "my test app",
"intents":[
{
"name":"HelloWorldIntent",
"phrases":[
"hello",
"say hello",
"say hello world"
]
},
{
"name":"MyNameIsIntent",
"phrases":[
"{name}",
"my name is {name}",
"i am {name}",
"you can call me {name}"
],
"inputs":[
{
"name":"name",
"type":{
"alexa":"AMAZON.US_FIRST_NAME",
"dialogflow":"@sys.given-name"
}
}
]
}
]
}
The platforms
folder is created by the Jovo CLI. Each platform (like Amazon Alexa and Google Assistant) gets its own folder with project files and language models. These files are then used to deploy the projects to the voice platforms.
In the src
folder, you can find the actual code of your Jovo app. This part is later deployed to hosting providers like AWS Lambda.
The app.js
file is used for the logic of your voice application, which contains handlers, intents, and the configuration of your voice app:
'use strict';
// ------------------------------------------------------------------
// APP INITIALIZATION
// ------------------------------------------------------------------
const { App } = require('jovo-framework');
const { Alexa } = require('jovo-platform-alexa');
const { GoogleAssistant } = require('jovo-platform-googleassistant');
const { JovoDebugger } = require('jovo-plugin-debugger');
const { FileDb } = require('jovo-db-filedb');
const app = new App();
app.use(
new Alexa(),
new GoogleAssistant(),
new JovoDebugger(),
new FileDb()
);
// ------------------------------------------------------------------
// APP LOGIC
// ------------------------------------------------------------------
app.setHandler({
LAUNCH() {
return this.toIntent('HelloWorldIntent');
},
HelloWorldIntent() {
this.ask('Hello World! What\'s your name?', 'Please tell me your name.');
},
MyNameIsIntent() {
this.tell('Hey ' + this.$inputs.name.value + ', nice to meet you!');
},
});
module.exports.app = app;
The config.js
file stores all the logic-related configuration:
// ------------------------------------------------------------------
// APP CONFIGURATION
// ------------------------------------------------------------------
module.exports = {
logging: true,
intentMap: {
'AMAZON.StopIntent': 'END',
},
db: {
FileDb: {
pathToFile: '../db/db.json',
}
},
};
Everything related to running and hosting your voice application, either in Lambda or using a webhook (recommended for local prototyping), is dealt with in index.js
file:
'use strict';
const { Webhook, ExpressJS, Lambda } = require('jovo-framework');
const { app } = require ('./app.js');
// ------------------------------------------------------------------
// HOST CONFIGURATION
// ------------------------------------------------------------------
// ExpressJS (Jovo Webhook)
if (process.argv.indexOf('--webhook') > -1) {
const port = process.env.PORT || 3000;
Webhook.listen(port, () => {
console.info(`Local server listening on port ${port}.`);
});
Webhook.post('/webhook', async (req, res) => {
await app.handle(new ExpressJS(req, res));
});
}
// AWS Lambda
exports.handler = async (event, context, callback) => {
await app.handle(new Lambda(event, context, callback));
};
Learn everything related to host configuration and the
index.js
file here.