question

Jamie Poole avatar image
Jamie Poole asked ·

Custom Event from Gadget not picked up by Event Handler

Hi,

I've followed all the documentation to a T -- my event from my gadget is firing according to AGT (I modified it to output to console when sending an event).

The namespace is the same, event is both correct on Skill and Gadget according to the Request logs.

Everything "looks" like it should be working but when an event is received, my Skill doesn't handle it.

Could there be anything obvious in the process I might be overlooking?

Here is my code:

python

from agt import AlexaGadget

class MyGadget(AlexaGadget):
    ...
    
    def Send(self, payload):
        self.send_custom_event("Custom.MyGadgetNamespace", "EventName", payload)

skill (NodeJS)

canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
    ...
    return handlerInput.responseBuilder
        .addDirective({
            "type": "CustomInterfaceController.StartEventHandler",
            "token": UUID.v4(),
            "expiration": {
                "durationInMilliseconds": duration,
                "expirationPayload": {
                    "state": "It's expired!"
                }
            },
            "eventFilter": {
                "filterExpression": {
                    "and": [
                        { "==": [
                            { "var": "header.namespace" },
                            "Custom.MyGadgetNamespace"
                        ]},
                        { "==": [
                            { "var": "endpoint.endpointId" },
                            endpointId
                        ]}
                    ]
                },
                "filterMatchAction": "SEND_AND_TERMINATE"
            }
        })
        .withShouldEndSession(false)
        .getResponse();
}
canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'CustomInterfaceController.EventsReceived';
},
handle(handlerInput) {
    ...
    console.log(`== CUSTOM EVENT == ${JSON.stringify(handlerInput.requestEnvelope.request.events[0]}`);
    ...
}
exports.handler = Alexa.SkillBuilders.standard()
    .addRequestHandlers(
        LaunchHandler,
        EventsReceivedHandler,
        ...
    )
    ...
    .lambda();


Can anyone help?


Cheers,

Jamie

gadgets toolkit
10 |2000 characters needed characters left characters exceeded

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

Jason@Amazon avatar image
Jason@Amazon answered ·

The actual code itself looks fine - an area where I can think of that would result in your endpoint not handling the request would be if the handler that you added hasn't been added to the list of request handlers. Check out this sample for details:

https://github.com/alexa/Alexa-Gadgets-Raspberry-Pi-Samples/blob/master/src/examples/color_cycler/skill/NodeJS/lambda/custom/index.js#L14-L33

2 comments
10 |2000 characters needed characters left characters exceeded

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

Hi Jason, thanks for the reply -- yep definitely added and referenced in the skill builder. I've updated my code to show the SkillBuilder object on our index.js file.

The annoying thing is that SENDING a directive to the Gadget is working fine, the gadget receives the payload with no issue.

It's just the receiving an event / StartEventHandler directive that is causing issues.

0 Likes 0 ·

I have also been using that code as reference, everything in our code is the same as that code.

0 Likes 0 ·
Jamie Poole avatar image
Jamie Poole answered ·

I found the solution, I was accidentally returning a non-SSML object in the speak response and it was throwing a silent error. Also, it seems like it was preventing the entire Handler from running -- including sending Diagnostics logs to CloudWatch.


Perhaps something Amazon can provide an error for?

1 comment
10 |2000 characters needed characters left characters exceeded

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

Glad you managed to resolve the issue! If there's an error with the response, there usually is an error on CloudWatch so I'm not sure what the issue is here. If you're facing issues in the future on this, feel free to reach out again and we'll try to find why it's not properly throwing an error.

0 Likes 0 ·