Bonding Alexa timer Api with Custom Task

Viewed 271

I've built a timer Api call.

timer_request_1 = {
    "duration": "PT15S",
    "timerLabel": "Change name",
    "creationBehavior": {
        "displayExperience": {
            "visibility": "VISIBLE"
        }
    },
    "triggeringBehavior": {
        "operation": {
            "type": "ANNOUNCE", 
            "textToAnnounce": [
                {
                    "locale": "en-US",
                    "text": "Would you like to proceed with the 40 minutes timer?"
                }
            ]
        },
        "notificationConfig": {
            "playAudible": False 
        }
    }
}

REQUIRED_PERMISSIONS = ["alexa::alerts:timers:skill:readwrite"]

class TimerIntentHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return ask_utils.is_intent_name("TimerIntent")(handler_input)
    
    def handle(self, handler_input):

        permissions = handler_input.request_envelope.context.system.user.permissions
        if not (permissions and permissions.consent_token):
            return (
                handler_input.response_builder
                .speak("Please give permissions to set timers using the alexa app.")
                .set_card(
                    AskForPermissionsConsentCard(permissions=REQUIRED_PERMISSIONS)
                )
                .response
            )
        
        timer_service = handler_input.service_client_factory.get_timer_management_service()                        
        timer_response = timer_service.create_timer(timer_request)
        
        if str(timer_response.status) == "Status.ON":
            session_attr = handler_input.attributes_manager.session_attributes
            if not session_attr:
                session_attr['lastTimerId'] = timer_response.id
                speech_text = 'Your 20 minutes timer has started!.'
                return (
                    handler_input.response_builder
                    .speak(speech_text)
                    .response
                    .ask("Would you like to proceed x task?")
                    )
        else:
            speech_text = 'Timer did not start'

        return (
            handler_input.response_builder
            .speak(speech_text)
            .response
        )

Next, I have followed the doc to:

  1. Create a new Custom Task:doc
  2. Create a handler for launch request doc
  3. Register the Custom Task doc
  4. Added LAUNCH_TASK with the name & version of the created custom task.

However, once user says stop to the timer, Alexa doesn't proceed with the countdown task. My intuition is that either timer API is not connected to the task despite following the protocol or Alexa shutdowns down when user says "stop" even though it shouldn't be the case when playaudio is True per the doc. Nevertheless, you are the expert. Does anyone know what I am missing?

My goal is to make a cookbook timer template in python as I believe it would be really helpful for python developers and could help with a lot of delicious meals & desserts to be cooked with Alexa :))

You can access the Repo here too.

Please help me out for the love of food :D

1 Answers

There is just a conflict up there:

Conflict between a built-in intent and custom intent

Occurs when an utterance maps to both your custom intent and one of the standard built-in intents. For example, a custom intent with the utterance "help" conflicts with the built-in AMAZON.HelpIntent. Alexa prioritizes your custom intent over the built-in, so in this example, "help" always resolves to your intent instead of the built-in. If you want the utterance to map to your custom intent rather than the built-in, leave this conflict in place.

You should consider Stop as reserved command/keyword since it's used for communication with Alexa in general - not only with your skill. However you can use Stop as part of your command ie: "Alexa, Stop my timer"

Related