Amazon Lex v2 Chatbot session not updating

1

Hello,

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 pass a json response 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 because session ID doesn't exist, even though it's appearing in CloudWatch Logs.

Example Conversation flow:

  1. User inputs "Hi"
  2. Bot asks for slot "firstName"
  3. User inputs his first name
  4. Lambda validates "firstName"
  5. Valid input -> bot asks for slot "surname", otherwise -> go back to step 2
  6. User inputs his surname (but now slot "firstName" has lost its value in lambda input json)
  7. Lambda validates input for "surname"
  8. Valid input -> ask for "phoneNumber" , otherwise -> re-ask step 5 (never pass this stage, input json next state proposed is to re-elicit "firstName" because it has no value)
  9. User input his phone number
  10. ...

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

1 回答
1

Hello,

When using Lamnda code hook, you are expected to have the relevant slot values set in the session state in the Lambda response (post validation). I.e., in step 5 of your flow, ensure value of "firstName" slot is set. Otherwise, Lex bot will assume the first name is not set (perhaps because it didn't pass business validation), and reprompt the user.

Thanks

AWS
已回答 2 年前
  • The issue is that I already tried to set the slot values in the Lambda response, but on the next user input, those values I already set disappear, even if Lex accepted the JSON correctly or even if the slot value was encoded. For example: in step 5, I set an encoded "firstName" value, Lambda accepts it correctly, but when step 6 is triggered, the "firstName" slot goes back to null if I check CloudWatch logs.

    I'm returning a JObject (Newtonsoft.JSON) that represents a JSON rather than a direct string representation of a JSON as I've seen elsewhere. could this be a problem? Apparently Lambda accepts it just fine and the JSON it produces is valid.

    Maybe I'm doing something wrong or just Lex doesn't store session state and I have to track and validate everything myself but that doesn't seem to be the case as I've seen Python-JavaScript examples without this problem.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则