Reputation: 11
I am currently working on an AWS Lex chatbot which will integrate with Lambda. The chatbot's goal is to provide the distance between two cities and return an amount. Here is an example of a chat: Chat example
However, I keep getting "Intent is fulfilled".
Here is a copy of the Lambda code:
import json
import boto3
from boto3.dynamodb.conditions import Key
def lambda_handler(event, context):
destination = event["sessionState"]["intent"]["slots"]["Destination"]["value"]["interpretedValue"]
source = event["sessionState"]["intent"]["slots"]["Source"]["value"]["interpretedValue"]
distance = get_distance(source, destination)
return {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"name": "DistanceIntent"
"state": "Fulfilled"
},
"messages": [
{
"contentType": "PlainText",
"content": f"{distance}"
}
]
}
}
Could you please explain what is wrong?
Upvotes: 0
Views: 613
Reputation: 1
For Lex v2 (current since 2022):
"messages" should not be nested inside sessionState. Only dialogAction and intent go inside sessionState.
return {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"name": "DistanceIntent"
"state": "Fulfilled"
},
},
"messages": [
{
"contentType": "PlainText",
"content": f"{distance}"
}
]
}
documentation: https://docs.aws.amazon.com/lexv2/latest/dg/lambda-response-format.html
dialogAction.type must be "Close" and intent must be provided. If you use type "Delegate" your custom message will be ignored.
Upvotes: 0
Reputation: 579
It would appear that you have yet linked your intent to the Lambda function. There are two steps that are necessary.
This will now ensure that Lex defers all fulfillment to the Lambda function.
An important difference between v1 and v2 of Lex is that you can only configure 1 Lambda function for the entire bot in Lex v2. You will need to consider using a router function for more flexibility. Take a look at the following guide: https://docs.aws.amazon.com/lexv2/latest/dg/lambda-attach.html
Upvotes: 0