I am building a chat bot that takes inputs such as the following:
"How do I take a screenshot on iphone"
and then searches for
"take a screenshot on iphone"
I followed the tutorials on how to make a Document Search Bot and a Question and Answer Bot but both relied on providing keywords or fully formed example questions.
Is there anyway for the bot to intuit what the query is without providing any keywords or the like?
Click on the +
icon next to "Intents" in the left side navigation.
A popup will appear so click "Create intent".
Then input a name, example: QueryLookup
. Then click on that intent from the Intents list on the left.
Slot Type
Click on the +
icon next to "Slot types" in the left side navigation.
A popup will appear so click "Create slot type".
Give the slot type a name (example: QueryPhrases
), description (optional), and check the "Expand Values" box.
Then input some example values you would expect a user to ask about. Give it a variety of values as single words or multiple words or full sentences. This helps train Lex what queries to identify from the whole user input. When finished, click the "Add slot to intent" button.
Step 2 will automatically add a slot to the intent. The default name given is slotOne
, but you can change that by clicking on the highlighted slot name. The "Required" checkbox is checked by default. Input a prompt in case you need to elicit this slot (ask the user specifically to provide it) example: What would you like to know about?
Check both of the Lambda Function checkboxes: (1) "Initialization and validation code hook" and (2) Fulfillment. And in the dropdown menus select your Lamda Function from the list. This is where you will do your handling based on the query interpreted by Lex.
Back at the top of your new intent, add "Sample Utterances". These train Lex how to match the user input to trigger this intent and capture the query
slot. Consider the ways a user will ask for something in this intent. From your example:
"How do I take a screenshot on iphone"
Simply replace the query word or phrase you want identified with your slot name. Also remove the question mark.
"How do I {query}"
Then write as many variations of these as you can.
Save the Intent, Build, and Test or Publish-then-Test. Lex will now be able to understand "How do I..."
type questions, trigger this new "QueryLookup"
intent, identify the "QueryPhrase"
and save it in the slot "query"
. Lex will then deliver this information to your Lambda Function where you can handle, do the lookup and build your response.
Here is the documentation on receiving that information (sometimes called "Event" or "Request") in your Lambda Function and how to respond.
Lambda Function Input Event and Response Format:
This section describes the structure of the event data that Amazon Lex provides to a Lambda function. Use this information to parse the input in your Lambda code. It also explains the format of the response that Amazon Lex expects your Lambda function to return.