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*
demandé il y a un mois152 vues
3 réponses
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
INGÉNIEUR EN ASSISTANCE TECHNIQUE
répondu il y a un mois
profile picture
EXPERT
vérifié il y a un mois
  • 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>" } } } }

répondu il y a un mois
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"
            }
        }
    }
répondu il y a un mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions