我正试着通过和Alexa说话来发推特。我想把我的代码放在AWS Lambda上,并通过Alexa触发函数。
我已经有一个Python代码,可以成功地推送某些字符串。我还设法创建了一个zip文件并将其部署到Lambda上(代码依赖于"tweepy“包)。然而,我不能通过Alexa来触发函数,我知道我需要使用处理程序和ASK-SDK (Alexa Service Kit),但我在这个阶段有点迷茫。有没有人能告诉我这些处理器是如何工作的,并帮助我了解大局?
发布于 2019-07-22 11:48:35
Alexa ASK_SDK伪代码:这是新ASK_SDK的伪代码,它是ALEXA_SDK的前身。还要注意的是,我在NodeJS中工作,但结构可能是相同的
带回调的
触发处理程序
- Handle Function
- Which ever "canHandle" function returns true this is the code that will be run. The handler has a few functions it can perform. It can read the session attributes, change the session attributes based on the intent that was called, formulate a string response, read and write to a more persistant attribute store like dynamodb and create and fire an alexa response.
handerInput包含了您需要的所有内容。我强烈建议在Pycharm中使用调试器运行测试代码,然后检查handlerInput变量。
response builder也非常重要,它允许您添加语音、后续提示、卡片、引出槽值等。handler_input.response_builder
检查https://github.com/alexa/skill-sample-python-helloworld-classes/blob/master/lambda/py/hello_world.py的示例
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
)发布于 2019-07-26 05:52:01
对于您关于捕获用户输入以进行type的问题,请使用AMAZON.SearchQuery插槽类型。在可以收集多少文本和捕获质量方面,您可能会遇到一些限制,但SearchQuery插槽是开始的地方。
https://stackoverflow.com/questions/57134770
复制相似问题