2

I just started to create a chat bot using Amazon Lex. I would like to use some session attributes to keep the state of conversation. Basically, my bot first selects a file from a DB, for example file "abc123", and then keeps the state of that file so the user doesn't need to keep specifying the file when trying to retrieve contents from that file. How do I keep the state of flow within the file?

I have created an Intent called "FileQuery", and modified the sessionAttribute to "file": fileNo

fileNo is passed through the users input in the chatbot and stored in the variable. Here is my lambda function below.

exports.handler = (event, context, callback) => {

    //storing users input for file into "file"
    var fileNo = event.currentIntent.slots.FileNumber;

    callback(null, {
      "sessionAttributes": { 
          "file": fileNo,
          "key": "value"
      },
        "dialogAction": {
            "type": "Close",
            "fulfillmentState": "Fulfilled",
            "message": {
                "contentType": "PlainText",
                "content": "File " + fileNo + " selected"
            }

        }

    });


}; //end

When user enters: "Select file abc123"

Lex: "File abc123 selected"

User: "Give me the name and contact information"

I want Lex/Lambda to understand the file in context and retrieve information about that file. How can I do this?

Reza
  • 73
  • 1
  • 8

2 Answers2

0

Once you store the session Attribute in your lex session attribute, the same can be retrieved in your lambda function from request using -

input.sessionAttributes.attributeName
vikash singh
  • 1,479
  • 1
  • 19
  • 29
0

This worked for me. saved the values to the sessionAttributes.

{
  "sessionAttributes": {
  "fileName": "budgetreport.doc"
},
"dialogAction": {
...

Then I can access them from the event/input. Name has the value of the session attribute.

exports.handler = async (event) => {

let message = firstMsg;
var attributes = event['sessionAttributes'];
console.log('attrs; ',attributes);
let name;
let type="Close";

if( attributes != null)
  name= attributes['fileName'];
devcd603
  • 169
  • 1
  • 6