IntentFeature BeforeAfterMethod

Objective

This guide will help to quickly understand a feature of the intent called Before Method and After Method. Usually, an intent executes a single method, however using the feature of before method and after method, you can configure an intent to execute multiple methods. This guide will help you to understand this.

Pre-requisites

  1. A VoiceWorx Account

For steps to create a VoiceWorx account, follow the steps at https://docs.voiceworx.ai/general/voiceworx-create-account

  1. An active AWS Account

You should have an active AWS Account. If you do not have it, you can create an AWS account at https://portal.aws.amazon.com/billing/signup#/start

AWS Accounts Include 12 Months of Free Tier Access

  1. AWS Account - Access Key, Secret access key and AWS Region Name To be able to connect to Amazon Lex from the VoiceWorx platform, one AWS IAM user is required and user should have the required permissions to access Lex service.

Following is a json document which you can use to create an IAM policy and assign it to the IAM user in the AWS console.

{

"Version": "2012-10-17",

"Statement": [

{

"Sid": "VoiceWorx",

"Effect": "Allow",

"Action": [

"lex:*",

"lambda:*",

"iam:*"

],

"Resource": "*"

}

]

}

For more information on creating IAM users and assigning policies, refer to the AWS official documentation https://aws.amazon.com/premiumsupport/knowledge-center/create-access-key/

You can also refer to the simplified VoiceWorx documentation at https://docs.voiceworx.ai/aws-iam-users

To proceed with these steps all pre-requisites must be satisfied. If something is missing, please return to pre-requisites to ensure all are fulfilled.

Now let’s begin using VoiceWorx platform with Amazon Lambda.

Setup connection to Amazon Lex

  1. Login to the VoiceWorx platform,use left navigation menu and click “Integration” then select “Connect System”. In the resulting page, click “Connect External Systems”.

Select Integration Category: Custom

Select System Type: Amazon Lex

Click: Connect System

  1. Once in “Connect System” the configuration screen below will appear. Provide connection information as shown below:

  • Service Instance Name: You can give any value of your choice.

  • Consumer Key: This information is made available in pre-requisites #4

  • Consumer Secret: This information is made available in pre-requisites #4

  • Region: This information is made available in pre-requisites #4

  • Click: Validate and Save Settings

  • See below additional information.

The table below explains each of the inputs shown on this screen:

Input

Information

Service Instance Name

You can give any value of your choice.

Consumer Key

This is your AWS Access key ID

Consumer Secret

This is your AWS Secret access key

Region

AWS Region Name. The Lex service will be used in this region.

When used to publish the skill, it will be published in this region.

  1. Once validation is confirmed the details of integration will be saved. The integrations listing page will be shown as below.

Lex connection is ready to use for future usage.

Create a new connection for the Internal Data

  1. Create another connection for Internal Data. Internal Data means the data source that VoiceWorx provides by default.

  2. Click on Add New Connection on the Connect System page from the left navigation.

You should see a small popup screen as shown below.

  1. Select Custom for the Integration Category

  2. Select Internal Content for the System Type

  3. Give any name of your choice for the system Instance Name.

  4. Click on Connect System button and this should quickly create a connection for the internal Content for you.

  5. You should see a newly created connection as shown in below screenshot.

Now the connection is ready to use with the skill

Create an App to utilise internal data

  1. To create a skill, browse to Apps > Custom Apps and click on New Custom App button, you should see a small popup screen as shown below.

Input

Information

Name

You can give any value of your choice.

Custom App Type

Select Search

Category

Please use the same category that you have used for the Intern Data.

Note: If category do not match then methods in this app may not be able to access the JSON data.

Make this app as shared…

Select this if you want to share this app with other users in your organization.

  1. Click on ‘Save’ and app should get created and selected for the next steps.

Create a Data Source

  1. A Data Source connects the app with the integration. Once you have a app created, you can go to Data Sources by clicking on “Data Sources” tab.

  1. To create a data source, click on ‘Create New Data Source’ button and you should see a popup screen as shown below

  1. Give a name of your choice and make sure you select the same connection that you have created in Step 2. In this example, it is “My Contacts”. If you want to make this connection as private to you, select the available option “Consider as a Personalized Data Source”. If selected, other users in your organization will not be able to use it.

  2. Now click on Save. Once a data source is created, you are ready to start creating various methods and use JSON Data.

Sample Data (JSON file):

  1. We are going to use sample contacts data in JSON format. You should have a contact created with following JSON data.

{

"Contacts": [

{

"name": "Martin",

"contactnumber": "(678)345 6789",

"country": "US",

"occupation": "Businessman"

},

{

"name": "Bob",

"contactnumber": "(678) 045 6789",

"country": "US",

"occupation": "Engineer"

},

{

"name": "James",

"contactnumber": "(678) 123 0456",

"country": "Canada",

"occupation": "Teacher"

}

]

}

Create Methods

Method-1: GetContactNumberMethod

  1. Let’s created first method which returns contact number of a person.

For each of the inputs, enter values as shown below.

Input

Value

Method Name

GetContactNumberMethod

Request Type

GetJsonContents

Parameters

  • ContentID

Contacts01

Record Limit

10

Record JsonPath

$.Contacts[?(@.name=='{{Name}}')]

Empty Result Template

Contact not found

Record Template

Contact Number of {{name}} is {{contactnumber}}

Result Template

{{Records}}

Now click on save & test. Once you test this method, it should

Sample Response:

Contact Number of Bob is (678) 045 6789

Method-2: GetLocationMethod

  1. Let’s created another method which returns location of a person.

For each of the inputs, enter values as shown below.

Input

Value

Method Name

GetLocationMethod

Request Type

GetJsonContents

Parameters

  • ContentID

Contacts01

Record Limit

10

Record JsonPath

$.Contacts[?(@.name=='{{Name}}')]

Empty Result Template

Contact not found

Record Template

{{name}} lives in {{country}}

Result Template

{{Records}}

Sample Response:

Bob lives in US

Method-3: GetOccupationMethod

  1. Let’s created another method which returns occupation of a person.

For each of the inputs, enter values as shown below.

Input

Value

Method Name

GetOccupationMethod

Request Type

GetJsonContents

Parameters

  • ContentID

Contacts01

Record Limit

10

Record JsonPath

$.Contacts[?(@.name=='{{Name}}')]

Empty Result Template

Contact not found

Record Template

{{name}} is {{occupation}}

Result Template

{{Records}}

Sample Response:

Bob is Engineer

Create Intent

  1. Now it’s time to create one or more intents. For the demonstrate purpose, we will create one intent.

  2. Navigate to the Intents tab and then click on Create New Intent button as shown below

Primary method:

Normally an intent executes one single method called as Primary method. However, using a feature called Before Method and After Method, we can choose to execute additional methods.

If any session variable is defined or set for the before method, those will be accessible to the After method.

Before Method (Optional):

If we select Before Method, we get an option to select a data source and a Method which gets executed just before executing the primary method. The result of this method is returned along with the result of the primary method.

If any session variable is defined or set for the before method, those will be accessible to the Primary Method and After method.

After Method (Optional):

If we select After Method, we get an option to select a data source and a Method which gets executed just after executing the primary method. The result of this method is returned along with the result of the primary method.

It can access session variables defined in Before Method or in the Primary Method.

  1. On the Intent creation screen, you should see a popup screen for creating intent. Provide inputs as shown below.

InputValue

Intent Name

GetOccupationIntent

Intent Type

Search

Intent Action

Execute Method

Before Method Checkbox

True

Data Source

The data source that you want to use (Contacts in JSON)

Data Source Method

GetLocationMethod

Primary Method

Data Source

The data source that you want to use (Contacts in JSON)

Data Source Method

GetOccupationMethod

After Method Checkbox

True

Data Source

The data source that you want to use (Contacts in JSON)

Data Source Method

GetContactNumberMethod

Create a slot

  1. We need to create a slot as the method we are using that uses one variable. Go to the Slots tab and select GetOccupationIntent from the intent dropdown.

Now click on Create new slot button and you should see a add slot screen. Enter required values as shown below and click on save to create the slot.

Create Utterance

  1. Now let’s create an utterance which we will be using from Lex to test the bot/skill

Go to the Utterances tab and then select the intent that we have already created, now click on Create New Utterance button.

This should bring a create utterance screen. Enter the values as shown in below screenshot.

Click on save and an utterance should get created.

You can also create/edit utterances in bulk, to do that click on "Bulk Edit" button, this should bring a bulk edit utterance screen. Enter the values as shown in below screenshot.

Create Input

  1. The method we are using requires an input, so we need to create an input from the Inputs screen. Go to the inputs tab and then click on Create New Input button.

On the Add new Custom input screen, fill the details as shown below and click on save.

Once saved, you should see input in the list.

Create Input Parameter

  1. On the inputs list, click on the Manage Parameter button in the Action column – as shown below.

Once you are in the Manage Input Parameters screen, click on "Input Parameter"

  1. On the Add input parameter screen, enter values as shown in the below screenshot.

Click on Save and input parameter should get created.

Now we are ready to publish the skill on any platform.

Publish to Amazon Lex

  1. In the top menu tabs, select “Publish” then click “Add Skill Publishing”.

  2. Once in “Add Skill Publishing” the popup screen will appear. Follow this documentation https://docs.voiceworx.ai/skills/lex-publishing-auto-manual

External App Name

This is the name of the app. You can give name of your choice.

App Type

It should be “Search”

Channel

Must be “Amazon Lex”

Auth Publish

Keep it selected

Welcome Message

Should be auto populated.

Re-Prompt Message

Should be auto populated.

Help Message

Should be auto populated.

Goodbye Message

Should be auto populated.

Fall Back Message

Should be auto populated.

  1. Once in “Publish” the publish process is initiated. The screen shown below will appear.

  2. Click “Publish to Lex” and this will initiate the publish process. The following results screen will appear as shown below.

  3. The results screen has an option to go to the “Go To LexV2 aPP” or “Go Back to App Publishing”.

For each intent defined in your app, the success screen will show two rows as seen in the above screenshot.

Test the skill on Amazon Lex

  1. On the app publishing results page, you have a button Go To Lex V2 App, as shown below.

When you click on it, you will be redirected to the newly created Lex bot on the AWS console.

  1. On the Amazon Lex bot page, ensure “Build Completed” else you may not be able to Test the bot.

Once you are on Lex, you should see a screen like this,

  1. Make sure it’s displaying the correct skill name at the top left and then click on the Test Chatbot option at the right side. Click on Text Chatbot and you should see Test bot screen as shown below.

  2. Start testing by writing utterance in the chat area and lex will connect to the skill configured in the VoiceWorx platform and you should get relevant response.

Congratulations!

You have successfully completed Amazon Lex Integration and have also tested Before Method and After Method. Now you can start using the Lex Bot.

Last updated