3
votes

Scenario

I wanted to add feedback feature, on thumbs down to any responses from the bot. The idea is to send response & question pair with intent message like thumbs down and thereafter using lambda function store it somewhere else for future references.

Things I have tried

I am using JS SDK from Amazon lex to add in the website.

  1. Tried adding key value pair in requestAttributes but the postText method throws an error with message Unexpected key 'requestAttributes' found in params, which is unexpected because in developer guide it is mentioned there.

Documentation URL

  1. Based on same documentation I tried adding two slots in the intent with last_question & last_response and was sending them simply in input string like : Thumbs down last_question last question last_answer last answer - this one I don't understand how it works.

i. Is there a better way to handle this requirement?

ii. How do custom slots work in single request with multiple information, what am I supposed to send to lex?

1

1 Answers

2
votes

i. Is there a better way to handle this requirement?

From what I remember, postText is simply the way to manually connect and send user inputs to your Lex bot, instead of going through Facebook Messenger for example. So postText doesn't handle any recognition of slots, intents or anything like that. That's all done by Lex and then handled with Lambda.

So I would suggest using sessionAttributes for this to remember both the last_question and last_response through multiple turns. Then use postText again to simply send the thumbs up or down rating.

Lambda will then recognize the rating input as its own slot, and retrieve the last_question and last_response from sessionAttributes and then perform the saving and tracking the rating system however you'd like.

Example:

User: "...(Question A)..."

  1. postText passes question A to Lex
  2. Lex receives question A, interprets intent and slots and passes to Lambda
  3. Lambda receives input, intent, and slot data
  4. Lambda saves question A in sessionAttributes as last_question
  5. Lambda determines Answer A is the proper response
  6. Lambda saves Answer A in sessionAttributes as last_answer and passes to Lex
  7. Lex receives Answer A from Lambda and responds to user with Answer A

Bot: "...(Answer A).... Please rate this answer."

  1. Lex response delivered through output channel.

User: "Thumbs up."

  1. postText passes Thumbs up to Lex. -> Lex interprets. -> Lambda receives.
  2. Lambda saves user input as user_rating
  3. Lambda finds last_question and last_answer in sessionAttributes
  4. Lambda saves last_question, last_answer, and user_rating in a database
  5. Lambda erases last_question and last_answer from sessionAttributes to start again.
  6. Lambda responds -> Lex responds -> Output channel displays response.

Bot: "Thank you, please ask another question."


ii. How do custom slots work in single request with multiple information, what am I supposed to send to lex?

It sounds like the confusion you are having is that you have to prepare formatted data before sending to Lex inside of postText when it's much simpler than that. Just pass the user input and let Lex sort it out based on how you've set up intents and slots. Here's how it should go for a multiple-slot single-input.

Lex receives the user input as a string and attempts to parse the string for intents and slots, looking for the best matches. You simply prepare the Lex Console with intents and slots and custom slots and slot values, to improve its matching accuracy.

So let's say you know a user might give a single input with multiple information that you would like to catch as separate slots, for example:

"What is the time in New York?"

You probably want to catch the type of question so you have a slot to determine if the user is asking for "time" or "weather" or "population". So those would be made as one slot question_type, with those options as slot values.

Then you'd also want to catch where the question is about so you have another slot to determine if the user asked about "New York" or "Paris" or "Bangkok". So those would be made as one slot question_location, with those options as slot values.

After you prepare those slots and slot values in the Lex Console, you'd also want to prepare Lex for this type of input by narrowing down where in the sentence Lex is likely to find which slots. These would be the utterances for this intent, putting the slot names inside of curly braces "{ }":

what is the {question_type} in {question_location}

Then imagine more ways and in different orders the user might ask those questions:

what {question_type} is it in {question_location}
in {question_location} what is the {question_type}

Lex will parse the input and fill the slots with whatever it detected in that part of the input. Then in Lambda you match the slots with what you would expect and determine the best response.