Input

In this section, you will learn how to deal with entities and slot values provided by your users.

Introduction to User Input

Learn how to add inputs to the Jovo Language Model here.

We call user input any additional information your user provides besides an intent. For example, on Amazon Alexa, input is usually called a slot, on Google Assistant/Dialogflow an entity or parameter.

How to Access Input

You can access the complete object of inputs with this.$inputs, and a specific input by its name: this.$inputs.name.

Each input is an object which looks like this:

For example, if we want to access the value of an input name provided by the user, we can do so by using name.value.

Other parameters (like id or platform specific elements) can be found in the object as well.

inputMap

Similar to intentMap, there are cases where it might be valuable (due to naming conventions on different platforms or built-in input types) to map different input entities to one defined Jovo inputName. You can add this to the configuration section of your voice app:

Example: You want to ask your users for their name and created a slot called name on the Amazon Developer Platform. However, on Dialogflow, you decided to use the pre-defined entity given-name. You can now use an inputMap to match incoming inputs from Alexa and Google.

With this, you can use name to get the input with both Alexa and Google requests:

Validation

Jovo input validation allows you to register multiple validators per input in your handlers.

After defining your schema, where you define how you want to validate your inputs for the current intent, the core function of input validation this.validate() will be called. This will return an object containing a function failed(). You can use it to check, if the validation failed for a specific case.

You can validate your input in multiple ways, either as a specific Validator, your own function or a mixture from both in an array. The Validation Plugin already offers you multiple built-in Validators to choose from, each with its own functionality and set of parameter attributes.

Each Validator derives from a base abstract class Validator, which contains an abstract function validate() that gets overwritten by each deriving Validator. This means that besides using a function, you can easily write your own Validators and use them with the built-in Validators.

Regardless of whether you're using your own function or Validator, whenever you want to mark a path as failed you need to throw a ValidationError. This class expects at least a Validator identifier and an optional error message. Both of these can be used as a filter in the returned failed() function. This can be useful if you want to throw multiple ValidationErrors per function.

You can even use async/await in your own function/Validator for asynchronous calls. For this, simply use await this.validateAsync() instead of this.validate().

Comments and Questions

Any specific questions? Just drop them below or join the Jovo Community Forum.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.