[Course] Project 2: Adventure Game


#1

Welcome to our second project-based course about voice app development. After completing Project 1: Hello World, you now have a basic understanding of how voice apps work and how to set Alexa and Google Assistant up for simple responses.


This is a companion discussion topic for the original entry at https://www.jovo.tech/courses/project-2-adventure-game

#2

Hello!

I have a question about the functions located outside the app.setHandler.

For example, imagine that you have the following code inside app.setHandler:

if (this.$inputs.color.value === 'blue') {
        speech = 'You chose to go through the blue door.'
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.'
            \+ ' Do you want to follow the sound?';
        reprompt = 'Please say yes or no.';
        this.ask(speech, reprompt);
}

If I add this code to a function such that:

if (this.$inputs.color.value === 'blue') {
    readFunction();
}

And out of the app.setHandler I add these function:

function readFunction() {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     this.ask(speech, reprompt);
}

I have an error in this.ask:

Message:
Cannot read property ‘ask’ of undefined

Can someone help me? Thank you in advance!


#3

Can someone please help me? :pensive:


#4

In your handler, pass the Jovo context object like this: readFunction(this);

And then accept the jovo object in your helper function like this:

function readFunction(jovo) {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     jovo.ask(speech, reprompt);
}

Alternative: You can also use readFunction.call(this); and don’t need to accept the jovo object then, because the context will be passed to the helper method:

function readFunction() {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     this.ask(speech, reprompt);
}

#5

Thank you so much Jan!!

It works correctly!

Thank you very much for your reply.

Greetings! :grin:


#6

How to ask user to fill intent slot?

For Example the user has initated the intent “book Hotel”, but has not given an required Intent Slot ‘city’.

With an Alexa skill i would delegate it to dialog system and alexa would ask the user by the predefined question. But how do i do it with jovo that it works for alexa and googleAction?


#7

As far as i know google Action does not offer an option to ask the user for a specific input. But you can set input parameter as required and define prompts (questions google asks on its own to fill the paramters)

To do so you have to set your model json like this:


    {
        "intents": [
            {
                "name": "yourAwesomeIntent",
                "phrases": [ ... ],
                "dialogflow": { 
                    "webhookForSlotFilling": true    //<--to tell google to fill required paramters
                },
                "inputs": [
                    {
                         "name": "requiredInput",
                         "type": { ... },
                         **"required": true,     <--- set input to required**
                         "prompts": [      <--- define question google should ask 
                               "Question google asks the user to fill the input",
                               "another question"
                         ]
                    }
                ]
            }
        ]
    }

I would suggest to do it similar on Alexa side with “dialog”.
To predefine the same questions and let alexa fill the paramter on its own too.

On 2 Things i’m not sure about:

  • how to use the same sentences with a variable or something. Otherwise you have to handle the same sentence on 2 spots
  • how to set the sentences to use in dialog on alexa side in the model json file.

Maybe @jan could help out here?