Reputation:
I am trying to make a Lex Chatbot with lambda validations in .NET, if the slot input is valid it should ask for the "slotToElitict" in "proposedNextState" by the bot itself otherwise I re-elicit the slot.
My problem comes when the user input is valid, I return a JSON response (using output format specified here https://docs.aws.amazon.com/es_es/es_es/lexv2/latest/dg/lambda.html) with no problem but when the next user input is received, all the values from the previous session are lost, so it keeps asking for the same two slots every time.
I have tried storing the values from the previous slots and passing them to the json response if the input is valid but it doesn't work, I have also tried using "AmazonLexRuntimeV2Client.PutSessionAsync" to update the session but I couldn't get it to work either.
Conversation flow example:
User inputs "Hi"
Bot asks for slot "nombre"
User fills "nombre"
Lambda validates "nombre"
Valid input -> bot asks for slot "primerApellido", otherwise -> go back to step 2
User fills "primerApellido" (but now slot "nombre" has lost its value in lambda input json)
Lambda validates input for "primerApellido"
Valid input -> ask for "segundoApellido" , otherwise -> re-ask step 5 (never pass this stage, input json next state proposed is to re-elicit "nombre" because it has no value)
User fills "segundoApellido"
... (continues)
Some attachments to see what is happening in Amazon CloudWatch:
Step 3, user fills "nombre" so it has a value which should be stored in the current session
Any help would be greatly appreciated, thank you very much!
Upvotes: 0
Views: 276
Reputation: 579
It sounds like you have the idea right but might be dropping or overwriting the request attributes between calls. Below is a snippet from a Python-based Lambda function that returns a request back to Lex.
def elicit_intent(intent_request, session_attributes, message):
return {
'sessionState': {
'dialogAction': {
'type': 'ElicitIntent'
},
'sessionAttributes': session_attributes
},
'messages': [ message ] if message != None else None,
'requestAttributes': intent_request['requestAttributes'] if 'requestAttributes' in intent_request else None
}
Note that the requestAttributes
from the input event are returned in the output response. Is it possible that you're missing this bit?
I'm not familiar with the .Net SDK for Lex but I imagine you should be able to return a similarly-formed response.
Upvotes: 0