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*
已提问 1 个月前146 查看次数
3 回答
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
支持工程师
已回答 1 个月前
profile picture
专家
已审核 1 个月前
  • 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>" } } } }

已回答 1 个月前
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"
            }
        }
    }
已回答 1 个月前

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

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

回答问题的准则