Ultimate Guide to Jovo Framework Enhancing Voice App Development

Welcome to the Ultimate Guide to Jovo Framework

The Jovo Framework is an open-source framework that enables you to build voice apps for platforms like Amazon Alexa, Google Assistant, and more. It’s designed to create cross-platform voice applications easily and efficiently. This guide introduces the Jovo Framework and showcases dozens of useful APIs with code snippets to help you maximize your app development experience.

Getting Started

To begin using Jovo, you need to install the Jovo CLI:

  
    npm install -g jovo-cli
  

Initializing a New Jovo Project

  
    jovo new 
  

Hello World Example

Below is a simple “Hello World” example to get you acquainted with Jovo’s capabilities:

  
    // src/app.js
    const { App } = require('jovo-framework');
    const { ExpressJS } = require('jovo-framework/dist/src/integrations/ExpressJS');
    const app = new App();

    app.setHandler({
        LAUNCH() {
            this.tell('Hello World!');
        },
    });

    if (process.argv.indexOf('--webhook') !== -1) {
        const server = new ExpressJS();
        server.start(app);
        console.log('Listening on port 3000');
    } else {
        app.handle();// Traditional voice app setup
    }
  

Understanding App Handlers

Handler definitions control how your application responds to different intents. Below is an example with multiple intents:

  
    app.setHandler({
        LAUNCH() {
            this.ask('Welcome to my Jovo app. How can I help you?');
        },
        MyIntent() {
            this.tell('You triggered MyIntent!');
        },
        Unhandled() {
            this.tell('Sorry, I didn\'t understand that.');
        },
    });
  

Using Jovo Models

Jovo models are used to model the interaction with your voice app. Here’s an example:

  
    // models/en-US.json
    {
      "invocation": "my jovo app",
      "intents": [
        {
          "name": "LAUNCH",
          "phrases": ["open my jovo app"]
        },
        {
          "name": "MyIntent",
          "phrases": ["trigger my intent"]
        }
      ]
    }
  

APIs and Integrations

Jovo provides numerous APIs to extend your app. Here are some key examples:

Session Handling

  
    this.setSessionAttribute('key', 'value');
    let value = this.getSessionAttribute('key');
  

Speech and Reprompt

  
    this.ask('What is your name?', 'Can you say that again?');
  

AudioPlayer

  
    this.$alexaSkill.$audioPlayer.play('AUDIO_URL', 'token')
                        .tell('Now playing...');
  

State Handling

  
    this.followUpState('MyState')
        .ask('Do you want to continue?', 'Please say yes or no');
  

Complete Application Example

Here is a complete application example utilizing various Jovo APIs:

  
    // src/app.js
    const { App } = require('jovo-framework');
    const { ExpressJS } = require('jovo-framework/dist/src/integrations/ExpressJS');
    const app = new App();

    app.setHandler({
        LAUNCH() {
            this.ask('Welcome! What is your name?', 'Please tell me your name.');
        },

        MyNameIsIntent() {
            const name = this.$inputs.name.value;
            this.ask(`Hey ${name}, do you want to hear a joke?`, 'Please say yes or no.');
        },

        YesIntent() {
            this.tell('Why did the scarecrow win an award? Because he was outstanding in his field!');
        },

        NoIntent() {
            this.tell('Alright, maybe next time.');
        },

        Unhandled() {
            this.tell('Sorry, I didn\'t understand that.');
        },
    });

    if (process.argv.indexOf('--webhook') !== -1) {
        const server = new ExpressJS();
        server.start(app);
        console.log('Listening on port 3000');
    } else {
        app.handle();
    }
  

This concludes our brief guide to Jovo Framework. Happy coding!


Hash: 1868e73cc89ce8164d764685a323a3ddfb54693e658ba9d6224e1b532b83d0c5

Leave a Reply

Your email address will not be published. Required fields are marked *