Bryan
Bryan

Reputation: 1

AWS Lex - How to share values from one intent to other intents

I am fairly new when it comes to using Lambda with Lex and scripting in general. In an intent, I am asking users for their first name, last name, and organization. I am wondering if there a way I can share this information across other intents in that same chatbot? For example, when responding to the user in another intent I want to be able to use their first name in the response back to them. I have looked online and I am very confused on how to achieve this. Any help is really appreciated on this. Thank you in advance.

Upvotes: 0

Views: 1546

Answers (3)

GOURAV NAVGHARE
GOURAV NAVGHARE

Reputation: 1

(One way) This can be done using contexts, initialise output context "first_name" in intent asking for name and have all other intents input context as "first_name". So when "first_name" gets filled, it gets active and all other intents get recognizable.

Upvotes: 0

Jay A. Little
Jay A. Little

Reputation: 3277

To store values across multiple intents, use SessionAttributes.

It is common to backup your slot values inside of SessionAttributes, so that you can use them in other intents, or be able to return to the original intent and restore slots to continue where the user left off.

Example in Intent A:

//get the values of the slots, use your slot names at the end
var first_name = event.currentIntent.slots.first_name;
var last_name = event.currentIntent.slots.last_name;
var organization = event.currentIntent.slots.organization;

//insert slot values into sessionAttributes
event.sessionAttributes = {
    "first_name": first_name,
    "last_name": last_name,
    "organization": organization,
};

As you respond to lex with the updated sessionAttributes, those values will be saved and available in other intents.

Now in Intent B:

var first_name = event.sessionAttributes.first_name; 

var response_message = "Hello, "+ first_name +". I can help you to ...";

Upvotes: 1

Gurdev Singh
Gurdev Singh

Reputation: 2165

The user inputs captured in Amazon lex are handled using SLOTS. When the request is processed by your AWS Lambda code you can store this captured data in whichever Intent you wish to use.

Upvotes: 0

Related Questions