user18723375
user18723375

Reputation:

C# - Amazon Lex v2 Chatbot session is not being updated

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:

  1. User inputs "Hi"

  2. Bot asks for slot "nombre"

  3. User fills "nombre"

  4. Lambda validates "nombre"

  5. Valid input -> bot asks for slot "primerApellido", otherwise -> go back to step 2

  6. User fills "primerApellido" (but now slot "nombre" has lost its value in lambda input json)

  7. Lambda validates input for "primerApellido"

  8. 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)

  9. User fills "segundoApellido"

  10. ... (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

Step 6, "nombre" is null again like at the beginning even though session id is the same and value has been filled previously

Any help would be greatly appreciated, thank you very much!

Upvotes: 0

Views: 276

Answers (1)

Reegz
Reegz

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

Related Questions