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ヶ月前157ビュー
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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ