question

Mohamed Sayed avatar image
Mohamed Sayed asked

My skill never receive the SendEvent

My skill display an APL that runs a video, and onEnd it fires SendEvent to my skill.
the problem is that skill never got this SendEvent. CloudWatch does not show any log for the sendEvent handler.

here is the request handler in my skill


class APLUserEventHander(AbstractRequestHandler):
    """
    Handles RecipeIntent or APL Touch Event requests sent by Alexa
    """

    def can_handle(self, handler_input):
        #logger.info("------> In userEvent intent")
        #logger.info(list(handler_input.request_envelope.request.arguments)[0])
        return is_request_type('Alexa.Presentation.APL.UserEvent')(handler_input)

    def handle(self, handler_input):

        logger.info("-----> In userEvent")
        handler_input.response_builder.set_should_end_session(Tru
        
        return handler_input.response_builder.response



This is my APL

{
    "type": "APL",
    "version": "2023.1",
    "license": "Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: LicenseRef-.amazon.com.-AmznSL-1.0\nLicensed under the Amazon Software License  http://aws.amazon.com/asl/",
    "settings": {},
    "theme": "dark",
    "import": [
        {
            "name": "alexa-layouts",
            "version": "1.6.0"
        }
    ],
    "resources": [],
    "styles": {},
    "onMount": [],
    "graphics": {},
    "commands": {},
    "layouts": {},
    "mainTemplate": {
        "parameters": [
            "payload"
        ],
        "items": [
            {
                "alignItems": "center",
                "direction": "column",
                "justifyContent": "center",
                "type": "Container",
                "disabled": true,
                "width": "100%",
                "height": "100%",
                "items": [
                    {
                        "type": "AlexaBackground",
                        "backgroundImageSource": "${payload.data.backgroundImage}",
                        "colorOverlay": true
                    },
                    {
                        "type":"Video",
                        "id":"versePlayer",
                        "audioTrack": "foreground",
                        "source":"${payload.data.verseAudio}",
                        "autoplay": true,
                        "maxHeight": "2dp",
                        "maxWidth": "20dp",
                        "alignSelf": "center",
                        "onEnd":[
                            {
                                "type":"SendEvent",
                                "arguments": ["playbackFinished"]
                            }
                        ]

                    },
                    {
                        "text": "${payload.data.mainText}",
                        "fontFamily": "georgia",
                        "fontSize": "50dp",
                        "textAlign": "center",
                        "textAlignVertical": "center",
                        "color": "red",
                        "id": "title",
                        "type": "Text",
                        "speech": "${payload.data.verseAudio}"
                    },
                    {
                        "id": "subTitle",
                        "fontSize": "30dp",
                        "text": "${payload.data.subText}",
                        "type": "Text",
                        "textAlign": "center",
                        "textAlignVertical": "center",
                        "width": "700dp",
                        "height": "32dp",
                        "paddingTop": "50dp",
                        "paddingBottom": "12dp"
                    }
                ]
            }
        ]
    }
}

aplvideo
10 |5000

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

Mohamed Sayed avatar image
Mohamed Sayed answered

I have found the cause of the problem, however I don't know why it caused the problem.

at the end of the intent that render the APL Document. I set shouldEndSession to True.
although True is the default, however, If I explicitly set it at the end of the intent, any future userEvent will never be received from the device.

once I removed the line, eveything worked fine

10 |5000

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

Andy Whitworth avatar image
Andy Whitworth answered

1. Have you registered the handler ?

2. If you change the event from onEnd to OnPlay (as a test), then does your lambda receive that event ?

This doc shows the end event being fired after the video ends (11s)

https://apl.ninja/document/AndyWhitworth/lrK4agBcqjTrcwuhfWLZrWATbOWR6hSb

10 |5000

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

Mohamed Sayed avatar image
Mohamed Sayed answered

This is how I registered the event handler with the same way as other request handler

sb.add_request_handler(APLUserEventHander())

I tried to send the event using AlexaButton

Same problem, no event is received from skill side.

I run from Test in developer console. and I can see the event fired when I clicked the button

{
    "event": {
        "header": {
            "namespace": "Alexa.Presentation.APL",
            "name": "UserEvent",
            "messageId": "messageId",
            "dialogRequestId": "cec9f174-2a8e-4adf-9c4e-c8396b6179ba"
        },
        "payload": {
            "presentationToken": "amzn1.as-tt.v1.ThirdPartySdkSpeechlet#TID#amzn1.ask.skill.a065dfbf-b270-4b46-8632-14d41e3da004:dG9rZW50ZXN0:",
            "arguments": [
                "AlexaButton1Click"
            ],
            "source": {
                "type": "TouchWrapper",
                "handler": "Press",
                "id": "Button1"
            },
            "components": {},
            "dialogRequestId": "cec9f174-2a8e-4adf-9c4e-c8396b6179ba"
        }
    },
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.

Andy Whitworth avatar image Andy Whitworth commented ·
And if you change the onEnd to onPlay (as a test) then do you receive an event when the video starts ?
0 Likes 0 ·
Mohamed Sayed avatar image
Mohamed Sayed answered

I tried using onPlay and got the same problem.
the skill does not receive any userEvent event, as stated, I created another APL with one button that sends a userEvent. tested from developer console, I can se the event from Device Log as shown in my previous reply. I really don't know what is the problem.
note that my skill is working on Aarabic local only. could that be a reason ?

10 |5000

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

Mohamed Sayed avatar image
Mohamed Sayed answered

I've also created request interceptor from AbstractRequestInterceptor

I can see all the requests coming to the skill, but not the userEvent ???

10 |5000

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

Mohamed Sayed avatar image
Mohamed Sayed answered

Is there anyway to diagnose weather or not the userEvent request reaches the skill endpoint ?

10 |5000

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