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 個月前檢視次數 154 次
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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南