Jovo aims to create a development framework that allows you to write code once and deliver to multiple voice platforms (at this time, Alexa and Google Assistant). Again, it’s like the voice ecosystem is taking the same path as app development, trying to find ways around maintaining multiple code bases. There are still a handful of steps with each voice platform that you can’t avoid, but you can write the core logic of your application in JavaScript.
For this post, I’ve created a simple application that tells the user what the latest article on my site is.
Jovo is an NPM module, so install with:
npm install -g jovo-cli
This command installs a command line utility that will help you create and manage projects, including a helpful project creation command:
Then, install the other dependencies that your Jovo project will need:
cd <project_name>npm install
You can start the application with node index.js
or jovo run
, but, as all voice platforms work via web-connected applications, you need to expose your application to the web through a tool such as ngrok and grab the secure version of the URL it generates.
To get your application code to work with Alexa, you need to take two initial steps (but there will be others depending on its complexity).
Intents tell Alexa what to do with specific default and custom actions and custom phrases users can use to trigger them. If you don’t specify anything for default actions, it will use the platform defaults. Add the following to the intents section of the Alexa creator of your skill:
{"languageModel": {"intents": [{"name": "AMAZON.CancelIntent","samples": []},{"name": "AMAZON.HelpIntent","samples": []},{"name": "AMAZON.PauseIntent","samples": []},{"name": "AMAZON.ResumeIntent","samples": []},{"name": "AMAZON.StopIntent","samples": []},{"name": "LatestPostIntent","samples": ["latest post","latest news","latest article","latest blog"],"slots": []}],"invocationName": "<your_invocation>"}}
As you can see above, I’ve only changed the custom LatestPostIntent
and added a handful of alternative "utterances" that can trigger that intent. This intent relates directly to the application code, but I’ll return to that later.
In the Configuration tab, change Service Endpoint Type to HTTPS and add your exposed URL from above, appended with /webhook
:
Setting up Google Assistant is more complex, with less provided for you by default. For speed, in this article, I recommend you import the intents I created via the Settings > Export and Import option. You can see the specifics of the LatestPostIntent
below, including the trigger phrases:
In the Fulfillment tab, enable Webhook and add your exposed URL from above, appended with /webhook
:
Thanks to Jovo, the code for this application is fairly simple and requires a small update to index.js
at the bottom of the file:
const handlers = {
'LAUNCH': function() {app.toIntent('LatestPostIntent');},
'LatestPostIntent': function() {parser.parseURL('https://gregariousmammal.com/feed.xml', function(err, parsed) {console.log(parsed.feed.title);parsed.feed.entries.slice(1).forEach(function(entry) {console.log(entry.title + ':' + entry.link);app.tell(entry.title);})});},};
The toIntent
method allows you to jump into a new intent within the same request — in this case, the LatestPostIntent
. The logic for the intent is JavaScript, using rss-parser to parse the RSS feed of the site and return one result that the framework speaks.
Here’s me trying the application on my Echo.
And in the Google Assistant simulator:
If you’ve read so far, it may seem like Jovo doesn’t save you as much time as you hoped, and this is a valid comment. This is partially due to the need to visit the different developer portals to connect the code to the platform but also because Jovo is a new platform. I spoke with the team behind the platform, and they are due to release a new version soon. This version will reduce the need to create your interaction models on each platform. Instead, you can create one file locally, and new CLI commands will push these to the platforms for you. It will also introduce a slightly different file structure from outlined above and plans to add internationalization of strings soon.
If you’re interested in developing voice interfaces for multiple platforms, but want to keep your code as manageable as possible, experiment with the platform as it stands, sign up to the Jovo Slack and keep an eye out for those changes.
Originally published at dzone.com.