question

milanc avatar image
milanc asked

APL RenderDocument directive results in INTERNAL_SERVICE_ERROR

I'm trying to use APL in a skill I'm creating. I'm using the Python ASK SDK to develop it (FWIW, the code can be found here). If a device supports the Alexa.Presentation.APL interface, I add an RenderDocumentDirective to the response and send it off to the device. This, however, results in an immediate new invocation of type SessionEndedRequest with INTERNAL_SERVICE_ERROR as the error reason. I've tested the APL document in the Display simulator and it all worked fine so I'm not sure what's going on.

Here's the JSON I send from my skill:

{
        "version": "1.0",
        "sessionAttributes": {
            "launch_count": 12,
            "previous_session_end": 1545238739,
            "session_data": {
                "operation": "add",
                "difficulty": 1,
                "correct_result": 14,
                "questions_count": 0,
                "correct_answers_count": 0,
                "streak_count": 0
            }
        },
        "userAgent": "ask-python/1.5.0 Python/3.6.1 alexa-math-practice-skill/1.0.0",
        "response": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak>OK. Let's get started. What is 6 plus 8?</speak>"
            },
            "reprompt": {
                "outputSpeech": {
                    "type": "SSML",
                    "ssml": "<speak>What is 6 plus 8?</speak>"
                }
            },
            "directives": [
                {
                    "type": "Alexa.Presentation.APL.RenderDocument",
                    "document": {
                        "type": "APL",
                        "version": "1.0",
                        "import": [
                            {
                                "name": "alexa-styles",
                                "version": "1.0.0"
                            }
                        ],
                        "mainTemplate": {
                            "parameters": [
                                "payload"
                            ],
                            "items": [
                                {
                                    "type": "Container",
                                    "alignItems": "center",
                                    "justifyContent": "center",
                                    "height": "100vh",
                                    "width": "100vw",
                                    "items": [
                                        {
                                            "type": "Text",
                                            "fontSize": "@fontSizeXXLarge",
                                            "fontWeight": "@fontWeightLight",
                                            "text": "${payload.op1} ${payload.operator} ${payload.op2}"
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    "datasources": {
                        "op1": 6,
                        "op2": 8,
                        "operand": "+"
                    }
                }
            ],
            "shouldEndSession": false
        }

And here's the INTERNAL_SERVICE_ERROR invocation that follows:

{
        "version": "1.0",
        "session": {
            "new": false,
            "sessionId": "amzn1.echo-api.session.ea9d15a6-93fe-4721-8f3c-5a2f6c3cdf8a",
            "application": {
                "applicationId": "amzn1.ask.skill.d455ad8c-dde9-4ee8-a492-4e3985b5ff79"
            },
            "attributes": {
                "launch_count": 12,
                "session_data": {
                    "operation": "add",
                    "difficulty": 1,
                    "correct_result": 14,
                    "questions_count": 0,
                    "correct_answers_count": 0,
                    "streak_count": 0
                },
                "previous_session_end": 1545238739
            },
            "user": {
                "userId": "foo"
            }
        },
        "context": {
            "System": {
                "application": {
                    "applicationId": "amzn1.ask.skill.d455ad8c-dde9-4ee8-a492-4e3985b5ff79"
                },
                "user": {
                    "userId": "foo"
                },
                "device": {
                    "deviceId": "foo",
                    "supportedInterfaces": {
                        "Alexa.Presentation.APL": {
                            "runtime": {
                                "maxVersion": "1.0"
                            }
                        }
                    }
                },
                "apiEndpoint": "https://api.amazonalexa.com",
                "apiAccessToken": "foo"
            },
            "Viewport": {
                "experiences": [
                    {
                        "arcMinuteWidth": 346,
                        "arcMinuteHeight": 216,
                        "canRotate": false,
                        "canResize": false
                    }
                ],
                "shape": "RECTANGLE",
                "pixelWidth": 1280,
                "pixelHeight": 800,
                "dpi": 160,
                "currentPixelWidth": 1280,
                "currentPixelHeight": 800,
                "touch": [
                    "SINGLE"
                ],
                "keyboard": []
            }
        },
        "request": {
            "type": "SessionEndedRequest",
            "requestId": "amzn1.echo-api.request.c63717a4-b8de-4642-9758-fc7b3b145e35",
            "timestamp": "2018-12-20T13:22:50Z",
            "locale": "en-US",
            "reason": "ERROR",
            "error": {
                "type": "INTERNAL_SERVICE_ERROR",
                "message": "Internal Server Error"
            }
        }

What am I doing wrong? Thank you for any pointers.

aplpython
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Alexander Martin avatar image
Alexander Martin answered
try
"datasources": {
  "math": {
    "type": "object",
    "properties": {
      "op1": 6,
      "op2": 8,
      "operand": "+" 
    }  
  }
}
instead of your current datasources object.
"datasources": {
  "op1": 6,
  "op2": 8,
  "operand": "+"
}
and use the following expressions:
${payload.math.properties.op1} ${payload.math.properties.operand} ${payload.math.properties.op2}
instead of:
${payload.op1} ${payload.operand} ${payload.op2}

hope this helps

2 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

milanc avatar image milanc commented ·

Mate! It works. I owe you an adult beverage and not just one. Thanks a lot.

1 Like 1 ·
Alexander Martin avatar image Alexander Martin milanc commented ·

you're welcome :)

0 Likes 0 ·
sungyoo avatar image
sungyoo answered

Hey @milanc is this still happening ie. are you able to reproduce this issue? Which device are you testing it on? Would you be able to provide utterances you are testing when this happens?

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

milanc avatar image milanc commented ·

Yes, I can reproduce it in the developer console and also on my device. I have an Echo Show 2.

If it helps, when using the dev console, this is the last message in the Device Log:

{
                   
"header": {
"namespace": "System",
"name": "Exception",
"messageId": "67133bc2-086c-4db2-9a5a-1614f3563e45"
},
"payload": {
"code": "INTERNAL_SERVICE_EXCEPTION",
"description": "Request could not be executed due to an internal service error."
}
}
0 Likes 0 ·
Arun@Amazon avatar image
Arun@Amazon answered

Hi @milanc

@Alexander Martin is right. The problem is indeed the datasources object. Basically, the values themselves must live inside an object (the datasource). I also found a small data binding bug with the operand. The fixed version is below. I am logging a ticket to ensure that when we encounter this situation, we show a meaningful error message instead of "INTERNAL_SERVICE_ERROR".

Thanks
Arun

{
    "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>OK. Let's get started. What is 6 plus 8?</speak>"
    },
    "directives": [
        {
            "type": "Alexa.Presentation.APL.RenderDocument",
            "token": "anydocument",
            "document": {
                "type": "APL",
                "version": "1.0",
                "import": [
                    {
                        "name": "alexa-styles",
                        "version": "1.0.0"
                    }
                ],
                "mainTemplate": {
                    "parameters": [
                        "payload"
                    ],
                    "items": [
                        {
                            "type": "Container",
                            "alignItems": "center",
                            "justifyContent": "center",
                            "height": "100vh",
                            "width": "100vw",
                            "items": [
                                {
                                    "type": "Text",
                                    "fontSize": "@fontSizeXXLarge",
                                    "fontWeight": "@fontWeightLight",
                                    "text": "${payload.documentData.op1} ${payload.documentData.operand} ${payload.documentData.op2}"
                                }
                            ]
                        }
                    ]
                }
            },
            "datasources": {
                "documentData": {
                    "op1": 6,
                    "op2": 8,
                    "operand": "+"
                }
            }
        }
    ]
}
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.