'How do I make Lex + Lambda ask the user are they ready for fulfillment?
I've got a basic bot set up that asks the user for some input in format such as:
User input: I need information on {policy}
Then a lambda function is executed that validates the policy entered using some basic regex. This all works perfectly and as expected.
Then, it returns the dialogAction to lex, which I have set up as follows:
return {"dialogAction": {
"type": "ConfirmIntent",
"fulfillmentState": "ReadyForFulfillment",
"message": {
"contentType": "PlainText",
"content": "Your policy " + policy + " is " + retStr (this just says valid or invalid) + " input."
}
}}
Ideally, when tested, I want this to validate the user input with the regex, then the bot to essentially do the ReadyForFulfillment message, but that doesn't work. Instead it crashes and I get:
An error has occurred: The server encountered an error processing the Lambda response
I have logging set up, which I used for other errors but when it errors out for this stuff, it doesn't produce an error in the CloudWatch logs.
I can change fulfillmentState to 'Fulfilled' and type to 'Close' and this will run perfectly. But I want the 'ReadyForFulfillment' option.
Here is my full lambda function:
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"
else:
print("Invalid input.")
retStr = "invalid"
return {"dialogAction": {
"type": "ConfirmIntent",
"fulfillmentState": "ReadyForFulfillment",
"message": {
"contentType": "PlainText",
"content": "Your policy " + policy + " is " + retStr + " input."
}
}}
def lambda_handler(event, context):
logger.debug('event={}'.format(event))
response = dispatch(event)
logger.debug(response)
return response
Solution 1:[1]
Have you tried the different dialogAction types?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mantle LoL |
