Reputation:
I keep getting lambda response errors when trying to set the event response object, which contains multiple slots for fulfillment state, which are currently set to none. I want to set them as 'ReadyForFulfillment', which apparently is a dialogAction option. I've been trying now for over 15 hours on this one issue and I can't find a solution.
In my cloudwatch logs, there is no errors appearing which makes debugging a pain.
I have a slot with the name 'policy', which I am validating in my code, and based on the validation, it sends one of two responses to lex. A dialogAction asking for a new policy format (works), and a dialogAction that will proceed if it is correctly validated and change the state to 'ReadyForFulfillment'
Here is my current Lambda:
import json
import logging
import re
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def dispatch(event):
slots = event["currentIntent"]["slots"]
policy = slots["policy"]
if re.match(r"policy\.([\w]+\.)+[\w]+(?=[\s]|$)", policy):
print("Valid input.")
retStr = "valid"
savePolicy = policy
else:
print("Invalid input.")
retStr = "invalid"
if retStr == "invalid":
return {
"dialogAction": {
"type": "ElicitSlot",
"message": {
"contentType": "PlainText",
"content": "Invalid policy format entered. Please try another format now:"
},
"intentName": "policyprovider",
"slots": {
"policy": policy
},
"slotToElicit": "policy"
}
}
else:
return {
"dialogAction": {
"type": "Close",
"fulfillmentState": "ReadyForFulfillment",
}
}
def lambda_handler(event, context):
logger.debug('event={}'.format(event))
response = dispatch(event)
logger.debug(response)
logger.debug('eventAfter={}'.format(event))
try:
return response
except Exception as e:
logger.debug("Exception: {}".format(e))
This results in on Lex chat bot, something similar to this:
Lex: What is your policy name?
User Input: test
Lex: Invalid policy format entered. Please try another format now:
User Input: policy.foobar.foobar
Lex: An error has occurred: The server encountered an error processing the Lambda response
On Cloudwatch, there is no sign of this error or further details what is causing it. The lex intent never changes to 'ReadyForFulfillment' either.
This is the event response on Lex:
RequestID: blah-blah-blah
{
"activeContexts": [],
"alternativeIntents": [
{
"intentName": "AMAZON.FallbackIntent",
"nluIntentConfidence": null,
"slots": {}
},
{
"intentName": "alternativePolicy",
"nluIntentConfidence": {
"score": 0.31
},
"slots": {
"TestItem": null
}
}
],
"botVersion": "$LATEST",
"dialogState": "ElicitSlot",
"intentName": "policyprovider",
"message": "Invalid policy format entered. Please try another format now:",
"messageFormat": "PlainText",
"nluIntentConfidence": {
"score": 1
},
"responseCard": null,
"sentimentResponse": null,
"sessionAttributes": {},
"sessionId": "2022-05-04T11:22:40-blah-blah",
"slotToElicit": "policy",
"slots": {
"policy": "test"
Upvotes: 0
Views: 569
Reputation: 579
I am working on the assumption that you are using AWS Lex V1. If so, your error is likely because the response message you're returning from your Lambda function in the case of valid user input contains an invalid value.
As per the developer guide for Lex V1, the acceptable response values for fulfillmentState
are Fulfilled
and Failed
.
This will effectively tell Lex that the interaction has been completed successfully. Assuming you want to perform some custom processing in the case of valid input, include that operation in your existing Lambda function so that by the time you reply back to the user, the fulfillment has indeed been performed.
Upvotes: 0