Lex chatbot response for Polly speech file

0

I am experiencing this output on the Amazon Lex Chat interface for Polly audio speech.

Invalid Lambda Response: Received invalid response from Lambda: Cannot construct instance of `IntentResponse`, problem: Intent must not be null when DialogActionType is Close at [Source: (String)"{"sessionState": {"dialogAction": {"type": "Close", "fulfillmentState": "Fulfilled", "response": {"contentType": "SSML", "content": "<speak><audio src='https://<pre-signed-url for audio file>"[truncated 904 chars]; line: 1, column: 1404]

The Lex reponse is as below:

lex_response is {'sessionState': {'dialogAction': {'type': 'Close', 'fulfillmentState': 'Fulfilled', 'response': {'contentType': 'SSML', 'content': "https://<pre-signed-url for audio file></speak>"}}}, 'messages': [], 'requestAttributes': {}}

I am not sure how this lambda_handler response is to be formatted as this looks correct in the response, any quick help is appreciated.

Polly mp3 are generated correctly in the S3 bucket and I can listen to them seperately.

My code snippet for lambda_handler is as below:

*# Prepare the response for Lex V2
    lex_response = {
        "sessionState": {
            "dialogAction": {
                "type": "Close",
                "fulfillmentState": "Fulfilled",
                "response": {
                    "contentType": "SSML",
                    "content": f"<speak><audio src='{audio_url}'/></speak>"
                }
            }
        },
        "messages": [],
        "requestAttributes": {}
    }
    print('lex_response is', lex_response)
    return lex_response*
asked a month ago95 views
3 Answers
0

Hello

The above error occurs when “intent” has not been specified for closing in the session state. When we specify the type option as “Close”, it ends the specified intent fulfillment process. To close, we need to specify the intent in the lambda response that needs to be closed. Please add the intent in the session state using the syntax in https://docs.aws.amazon.com/lexv2/latest/dg/lambda-common-structures.html#lambda-intent .

AWS
SUPPORT ENGINEER
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Hi Divya003, I am getting the same error after adding the intent: lex_response = { "sessionState": { "dialogAction": { "type": "Close", "fulfillmentState": "Fulfilled", "intent": { "name": "FallbackIntent" }, "message": { "contentType": "SSML", "content": f"<speak><audio src='{audio_url}'/></speak>" } } } }

0

Hi Divya003, I am getting the same error after adding the intent: lex_response = { "sessionState": { "dialogAction": { "type": "Close", "fulfillmentState": "Fulfilled", "intent": { "name": "FallbackIntent" }, "message": { "contentType": "SSML", "content": f"<speak><audio src='{audio_url}'/></speak>" } } } }

answered a month ago
0

The one that I got working for me (up to some extent of the format that I expected) is this one:

lex_response = {
        "messages": [
            {
                "contentType": "SSML",
                "content": f"<speak><audio src='{audio_url}'/></speak>",
                "type": "unstructured"
            },
            {
                "contentType": "PlainText",
                "content": response["answer"],
                "type": "unstructured"
            }
        ],
        "sessionState": {
            "dialogAction": {
                "type": "ElicitIntent"
            }
        }
    }
answered 25 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions