Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Create Cross-Platform Voice Applications With Jovo

DZone's Guide to

Create Cross-Platform Voice Applications With Jovo

Jovo aims to create a development framework that allows you to write code once and deliver to multiple voice platforms, taking out a lot of the extra work.

· AI Zone ·
Free Resource

Enable your enterprise to add AI to your existing infrastructure with EdgeVerve’s Business Applications built on AI platform Infosys Nia™. Register for our webinar to learn more.

Voice platforms are increasingly prevalent, sitting and quietly listening to what we do on a variety of mobile, computing, and consumer devices. Behind each of these devices is often a different platform that requires learning new languages, paradigms, or frameworks — it’s like developing for mobile operating systems all over again!

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.

Install Jovo

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:

jovo new <project_name>

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.

Connecting Jovo to Alexa

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).

1. Add Intents

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.

2. Add Webhook URL

In the Configuration tab, change Service Endpoint Type to HTTPS and add your exposed URL from above, appended with /webhook:

Alexa Config Screen

Google Instructions

1. Add Intents

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:

Intents Details

2. Add Webhook URL

In the Fulfillment tab, enable Webhook and add your exposed URL from above, appended with /webhook:

Webhook details

The Code

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:

Google Assistant preview

Making It Even Easier

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.

Adopting a digital strategy is just the beginning. For enterprise-wide digital transformation to take effect, you need an infrastructure that’s #BuiltOnAI. Register for our webinar to learn more.

Topics:
alexa ,google assistant ,voice interfaces ,vui ,ai ,tutorial ,bot development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}