question

Andre I H Ploszaj avatar image
Andre I H Ploszaj asked

Handling touchWrappers with python decorators

How can we catch touches in Python if I'm using decorator subscriptions? I'd think the following code would be the minimum, without even checking arguments, but that doesn't work.

# Doesn't work
@sb.request_handler(can_handle_func=is_request_type("Alexa.Presentation.APL.UserEvent"))
def touch_handler(handler_input):
    speak_output = "Touched!"
    return (
        handler_input.response_builder
            .speak(speak_output)
            .response
    )

TouchWrappers are set to:

"onPress": [
    {
        "type": "SendEvent",
        "arguments": [
            "colorSwatch",
            "${color}"
        ]
    }
]

I've added the array because APL creator interface would complain and add warnings if I would assign the event dict directly as "onPress": {...} like in the examples I saw.


I'm trying to learn how to convert the example bellow to the @sb.request_handler decorator style:

def can_handle(handler_input):
    return is_intent_name("RecipeIntent")(handler_input) or \
           (is_request_type('Alexa.Presentation.APL.UserEvent')(handler_input) and
            len(list(handler_input.request_envelope.request.arguments)) > 0 and
            list(handler_input.request_envelope.request.arguments)[0] == 'sauceInstructions')
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.

1 Answer

Andre I H Ploszaj avatar image
Andre I H Ploszaj answered

Woops, my mistake. That decorator style does work, problem was elsewhere in my code.
Sorry. Didn't mean to pollute the forum with reckless simple RTFM issues. I did spend most of yesterday knocking my head around this.

10 |5000

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