From Alexa To a callbot with Amazon Connect, Lex and Jovo

Following our contribution to Jovo framework with the Lex platform plugin, we can now build a callbot based on Amazon Lex, Connect and Jovo.

Published in
6 min readMay 6, 2021

--

Jovo Framework allows you to build voice experiences that work across devices and platforms. Including Amazon Alexa, Google Assistant, mobile phones, Raspberry Pi, and more.

Amazon Lex is an AWS service for building conversational interfaces for applications using voice and text. Lex offer the same conversational engine that powers Amazon Alexa.

Amazon Connect is a cloud contact center. which can be plugged to Amazon Lex to build powerful callbot.

We are going to build something like that:

Before you start

if you havent deployed any Voice assistant with Jovo you can start readying my previous post: How to deploy Jovo project with AWS CloudFormation and CI/CD

We suppose you have successfully test and deployed the “HelloWord” project available in this course made by Jan König

Ideally and to reduce network latency, you should create your stack (lambda/lexbot/connect) in the same region.
If you don’t want to move your AWS stack to another region, you can just create the callcenter in the nearest region of your main stack. (check the region network latency before. https://www.cloudping.co/grid)

Amazon connect is available in following regions :

Amazon Connect available regions

I. Configure your HelloWord project:

After successfully creating the HelloWorld app, you have to enable Lex support in your project:

First install Lex module:

npm install --save jovo-platform-lex

Import the installed module, initialize and add it to the app object:

// @language=javascript// src/app.jsconst { lex } = require('jovo-platform-lex');app.use(
new Lex()
);
// @language=typescript// src/app.tsimport { lex } from 'jovo-platform-lex';app.use(new lex());

You can have more informations on the module here.
Now your project is ready to handle Lex request.

II. Setup Lambda Policy statements

Before plugin Lex with you lambda function, you need to allow your lambda to be call by Lex.

  1. With CloudFormation
    If you have deployer your lambda with CloudFormation, just add following lines to your template
LexPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: YouLambdaArn:YouAlias # replace by your lambda Arn
Action: lambda:InvokeFunction
Principal: lex.amazonaws.com
SourceArn: !Join [':', ['arn:aws:lex',!Ref "AWS::Region",!Ref 'AWS::AccountId','intent','*','*']]

2. With AWS Console
Create or open existing alias of your lambda function and open the Permission tab.
If your code is already deployed to Alexa and Google Assistant, you should have 2 policy statements, one to manage permission for AlexaSkill and another for ApiGateway :

Lambda Policy Statements

Click “Add permission” and complet the form.
Replace YOURREGION/AccountID by your personal values.

Lex Policy Statement

III. Create LexBot

Lex Bot can be import with a Lex model file (I’ll do a post later about this) or create it manually. For now, we will choose this option.

Open Amazon Lex console (version 1) and create a new bot.
Compare to Alexa which is multi-language, lex v1 support only one language per bot.
We choose Lex v1 because Lex v2 isn’t support by AWS Connect. maybe one day…

Complete the form :

Create Intents:

HelloWord sample contains 3 intents :

  • LAUNCH: is fire when the skill/actions is start.
  • HelloWorldIntent: will ask for your name.
  • MyNameIsIntent: will display your answer.

Because Lex/Connect don’t have Launch Intent, we won’t integrate it in Lex.
For both intents, you will have to pick your lambda function and add an alias name.

HelloWorldIntent informations:

Create MyNameIsIntent informations:

You can now build your bot and try it in the “Test bot panel”:

If everything works fine, publish it.
You are now ready to plug Lex with Amazon Connect.

IV. Amazon Connect instance configuration:

The first step in setting up your Amazon Connect contact center is to create a virtual contact center instance. Each instance contains all the resources and settings related to your contact center.

In AWS console under Amazon Connect, Add a new instance and follow each step to create your virtual contact center:

Give an id to your contact center:

Create an administrator user, you can skip this part if you just want to run a test.

Choose your options, for our case, just enable Incoming Calls. You will be able to enable outboud calls later.

In Data storage section, you can enable logs and decide to keep track of call or chat conversations.
By default AWS create an Amazon S3 bucket. Data, such as reports and recordings of conversations, is encrypted using AWS Key Management Service, and then stored in the Amazon S3 bucket.

Just click next and Create your instance.
You are now ready to link your Connect instance with Lex Bot.

Select your instance (click on the name not the Access URL)

AWS Connect instances

In the Contact flows, search and add your Lex Bot :

Return on the main menu, pick your Access URL and login to your instance:

V. Contact Flow configuration:

A contact flow defines how a customer experiences your contact center from start to finish.
Contact flow designer. It’s a drag-and-drop interface that allows you to customize your contact center without any coding.

In the designer, pick 4 blocks:

  • Disconnect
    The block will close communication when an error appear or if your lambda stop it.
  • Set voice
    the block configure the language support by the skill and the voice use to render dialogue.
  • Play Prompt
    As AWS Connect won’t call you Lex bot without user input, we have to start the conversation. the block will read a prompt to the user.
  • Get Customer Input
    This is the main block which will send user input to Lex Bot and return the result to the customer.

Link all your blocks by following this diagram:

Contact Flow

For Customer Input, You have to select your bot, enter the alias name and configure how the block will manage lex response.

Block configuration

Now you can save and publish the Contact Flow.
You are ready to claim a phone number and link it with the new Contact Flow.
Go to “Manage Phone numbers” in Routing>Phone numbers and claim a new one.

When you claim a new number, you can decide to use a toll free or DID number. Pick a number and choose you ContactFlow.

Claim phone number

Now just call your newly claim number to try your callbot.

That’s it! We hope you found this useful, please comment below if you have any questions and feel free to hit the little clap button if you think it worth it!

--

--