Lex SLU Integration

Turn speech input into structured meaning with the Jovo Framework integration for Amazon Lex.

Introduction

Amazon Lex is a spoken language understanding (SLU) service that can do both automatic speech recognition (ASR) as well as natural language understanding (NLU).

Lex can be used for platforms that don't come with their own ASR and NLU capabilities, for example Jovo for Web.

Learn more how to set everything up in the installation and configuration sections.

To learn more how the integration maps Lex slots to $entities, take a look at the entities section.

Installation

You can install the plugin like this:

$ npm install @jovotech/slu-lex

SLU plugins need to be added to Jovo platform integrations. Here is an example how it can be added to the Jovo Core Platform in app.ts:

import { CorePlatform } from '@jovotech/platform-core';
import { LexSlu } from '@jovotech/slu-lex';
// ...

const app = new App({
  plugins: [
    new CorePlatform({
      plugins: [
        new LexSlu({
          bot: {
            id: '<your-bot-id>',
            aliasId: '<your-alias-id>' 
          },
          region: '<your-aws-region>',
          credentials: {
            accessKeyId: '<your-access-key-id>',
            secretAccessKey: '<your-secret-access-key>',
          },
        })
      ],
    }),
    // ...
  ],
});

For the integration to work, you need to add all configurations shown in the code snippet above. For more information, take a look at the configuration section.

Configuration

The following configurations can be added:

new LexSlu({
  bot: {
    id: '',
    aliasId: ''
  },
  region: '',
  credentials: {
    accessKeyId: '',
    secretAccessKey: '',
  },
  fallbackLocale: 'en_US',
  asr: true,
  nlu: true,
}),
  • bot: Includes information about your created Lex bot.
  • region: The AWS region of the Lex bot, for example us-east-1.
  • credentials: Your AWS security credentials.
  • fallbackLocale: Locale that should be used if none could be found in the request. Default: en_US.
  • asr: Determines whether the Lex ASR capabilities should be used. Default: true.
  • nlu: Determines whether the Lex NLU capabilities should be used. Default: true.

Entities

You can access Lex slots by using the $entities property. You can learn more in the Jovo Model and the $entities documentation.

The Lex slot values are translated into the following Jovo entity properties:

{
  value: slot.value.originalValue || slot.value.interpretedValue, // what the user said
  resolved: slot.value.resolvedValues?.[0] || slot.value.interpretedValue, // the resolved value
  id: slot.value.resolvedValues?.[0] || slot.value.interpretedValue, // same as resolved, since Lex doesn't support IDs
  native: { /* raw API response for this slot */ }
}

You can learn more about the Lex slot format in the official Lex documentation.