1
votes

Building a bot in which we fulfill an intent in a Lambda function. In this function, based on a user's selection, we have to set two slots to certain values.

The slots in question are "userResponse," "chatType," and "segment."

The code attempts to fill the latter slots based on the userResponse slot. Looks something like this:

let requestedService = event.currentIntent.slots.userResponse;
        
if (requestedService === "a") {
    event.currentIntent.slots.segment = 'a';
    event.currentIntent.slots.chatType = 'a';
} else {
    event.currentIntent.slots.segment = 'b';
    event.currentIntent.slots.chatType = 'b';
}

Thus, upon code running, the slots may look like this:

{
    "userResponse": "a",
    "chatType": "a",
    "segment" "a"
}

Now that we've fulfilled all of our slots, we pass the fulfill intent dialog action back to Lex.

callback(null, {    
    "sessionAttributes": event.sessionAttributes,   
    "dialogAction": {   
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {    
            "contentType": "PlainText", 
            "content": "Please wait"    
         }  
     }  
});

The problem is, when I send this information back to Lex, the slots that I've just manually set are somehow wiped out and returned to Lex as null, so that the slots are like this:

{
    "userResponse": "a",
    "chatType": null
    "segment" null
}

No other code is present between setting the slot values and then calling the dialog action. In this Lambda function's CloudWatch log, I've console logged the event just prior to the dialog action call and it shows the slots as being fulfilled. And yet...somehow, Lex is not getting those slots back with the correct data.

Is there something I'm missing? Why is Lex receiving null values when they're not null in Lambda?

1

1 Answers

0
votes

According to the document, I think you have to introduce the slots in the response object:

callback(null, {    
    "sessionAttributes": event.sessionAttributes,   
    "dialogAction": {   
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "stols": event.currentIntent.slots, // this change
        "message": {    
            "contentType": "PlainText", 
            "content": "Please wait"    
         }  
     }  
});