<p>Alexa ASKïu SDK Psuedo代码:
这是新ASK\usdk的伪代码,它是ALEXA\usdk的前身。
还请注意,我在NodeJS中工作,但结构可能是相同的</p>
<ul>
<li>带回调的外部函数-Lambda函数处理程序
<ul>
<li>CanHandle函数
<ul>
<li>包含确定此处理程序是否为正确处理程序的逻辑。HandlerInput变量包含请求数据,因此您可以检查并查看intent是否==“A specific intent”,然后返回true。否则返回false。或者你可以说得更具体些。(通过意图解雇处理程序是非常基本的。你可以更进一步,并根据意图和状态解雇处理程序。你知道吗</li>
</ul></li>
<li>句柄函数
<ul>
<li>哪个“canHandle”函数返回true这是将要运行的代码。处理程序有几个可以执行的函数。它可以读取会话属性,根据调用的意图更改会话属性,制定字符串响应,读取和写入更持久的属性存储(如dynamodb),并创建和触发alexa响应。你知道吗</li>
</ul></li>
</ul></li>
</ul>
<p>handerInput包含您需要的所有内容。我强烈建议您使用调试器在Pycharm中运行测试代码,然后检查handlerInput变量。你知道吗</p>
<p>响应生成器也非常重要,它允许您添加语音、后续提示、卡片、引出槽值等。
<code>handler_input.response_builder</code></p>
<p>要检查的示例
<a href="https://github.com/alexa/skill-sample-python-helloworld-classes/blob/master/lambda/py/hello_world.py" rel="nofollow noreferrer">https://github.com/alexa/skill-sample-python-helloworld-classes/blob/master/lambda/py/hello_world.py</a></p>
<pre><code>class HelloWorldIntentHandler(AbstractRequestHandler):
"""Handler for Hello World Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("HelloWorldIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = "Hello Python World from Classes!"
return (
handler_input.response_builder
.speak(speak_output)
# .ask("add a reprompt if you want to keep the session open for the user to respond")
.response
)
</code></pre>