绑定 Alexa 计时器 Api 与自定义任务

Bonding Alexa timer Api with Custom Task

我建立了一个计时器 Api 调用。

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
        )

接下来,我已经按照doc进行了:

  1. 创建新的自定义任务:doc
  2. 为启动请求创建处理程序doc
  3. 注册自定义任务doc
  4. 已添加 LAUNCH_TASK 创建的自定义任务的名称和版本。

但是,一旦用户对计时器说停止,Alexa 就不会继续执行倒计时任务。我的直觉是,尽管遵循了协议,但计时器 API 未连接到任务,或者当用户说“停止”时 Alexa 关闭,即使 playaudio 是 [=13] 时不应该出现这种情况=] 根据 doc。然而,你是专家。有谁知道我错过了什么?

我的目标是在 python 中制作一个食谱计时器模板,因为我相信这对 python 开发人员非常有帮助,并且可以帮助制作许多美味的饭菜和甜点亚历克莎 :))

您也可以在这里访问 Repo

请帮我解决对食物的热爱:D

上面只有一个 conflict:

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.

您应该将 Stop 视为保留 command/keyword,因为它通常用于与 Alexa 进行通信 - 不仅与您的技能有关。但是,您可以使用 Stop 作为命令的一部分,即:“Alexa,停止我的计时器”