构建与测试 Alexa 技能:从代码实现到单元测试
1. 意图处理与异常处理
在开发 Alexa 技能时,意图处理是关键环节。为了响应特定意图,我们需要编写相应的处理函数。例如,为了反映帮助意图(Help intent),可以在 can_handle 方法中使用逻辑或(OR)操作添加该意图的判断条件:
def can_handle(self, handler_input):
return (ask_utils.is_request_type("IntentRequest")(handler_input) or
ask_utils.is_intent_name("AMAZON.HelpIntent")(handler_input))
若要添加更多意图,可继续使用逻辑或操作将它们串联起来。
同时,为了避免 Alexa 在出现错误时简单地停止并告知用户“Sorry, I don’t know that”,我们需要一个通用异常处理程序(Catch-All Exception Handler)。以下是该处理程序的代码示例:
class CatchAllExceptionHandler(AbstractExceptionHandler):
"""Generic error handling to capture any syntax or routing errors. If
you receive an error stating
超级会员免费看
订阅专栏 解锁全文
24

被折叠的 条评论
为什么被折叠?



