Alexa Skill需要超过8秒才能完成Lambda。

huangapple go评论67阅读模式
英文:

Alexa Skill needs more than 8s for a Lambda to complete

问题

我正在使用Alexa的Python库编写一个Lambda函数,该函数调用了一些API。有时,这需要超过8秒的时间。这就是当Alexa设置为超时时的情况。

虽然我在API中找到了一个规范来帮助处理这个问题,但我还没有找到任何特定适用于为此编写的Python库的代码示例。我在哪里可以找到这样的代码示例来延迟响应?

英文:

I'm using Alexa's Python libraries to write a Lambda that hits a couple of APIs. Sometimes, this takes more than 8s. That's when Alexa is set to timeout.

class CustomIntentHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("CustomIntentHandler")(handler_input)

    def handle(self, handler_input):
        f = open('secrets.json')
        secrets = json.load(f)
        f.close
        
        # bulk of the code omitted (it works, it just takes too long sometimes)

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

While I have found a specification in the API to help with this matter by deferring the response, I haven't been able to find any code samples that apply specifically to the Python libraries written for this. Where can I find such code samples to defer the response?

答案1

得分: 1

渐进式响应是在需要准备完整响应用户请求时保持用户参与的良好选择。

如果您对此选项感兴趣,请在以下链接找到更多信息:https://developer.amazon.com/en-US/docs/alexa/custom-skills/send-the-user-a-progressive-response.html

这是一个很好的示例:
https://github.com/alexa-samples/progressive-response-demo

英文:

Progressive responses are a good option in this case where you need to keep the user engaged while your skill prepares a full response to the user's request.

If you are interest in this option, please find more information on this link https://developer.amazon.com/en-US/docs/alexa/custom-skills/send-the-user-a-progressive-response.html

This is a good example:
https://github.com/alexa-samples/progressive-response-demo

huangapple
  • 本文由 发表于 2023年5月25日 07:40:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定