首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何集成Lambda、Alexa和我的代码(Python - Tweepy)?

如何集成Lambda、Alexa和我的代码(Python - Tweepy)?
EN

Stack Overflow用户
提问于 2019-07-21 23:53:44
回答 2查看 185关注 0票数 0

我正试着通过和Alexa说话来发推特。我想把我的代码放在AWS Lambda上,并通过Alexa触发函数。

我已经有一个Python代码,可以成功地推送某些字符串。我还设法创建了一个zip文件并将其部署到Lambda上(代码依赖于"tweepy“包)。然而,我不能通过Alexa来触发函数,我知道我需要使用处理程序和ASK-SDK (Alexa Service Kit),但我在这个阶段有点迷茫。有没有人能告诉我这些处理器是如何工作的,并帮助我了解大局?

EN

回答 2

Stack Overflow用户

发布于 2019-07-22 11:48:35

Alexa ASK_SDK伪代码:这是新ASK_SDK的伪代码,它是ALEXA_SDK的前身。还要注意的是,我在NodeJS中工作,但结构可能是相同的

带回调的

  • 外部函数- Lambda函数处理程序
    • CanHandle Function
      • 包含用于确定此处理程序是否为正确处理程序的逻辑。HandlerInput变量包含请求数据,因此您可以检查并查看intent == "A specific intent“是否随后返回true。否则返回false。或者你可以去更具体的地方。(通过意图触发处理程序是非常基本的。您可以更进一步,根据Intent和State.

触发处理程序

代码语言:javascript
复制
- 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的示例

代码语言:javascript
复制
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
        )
票数 0
EN

Stack Overflow用户

发布于 2019-07-26 05:52:01

对于您关于捕获用户输入以进行type的问题,请使用AMAZON.SearchQuery插槽类型。在可以收集多少文本和捕获质量方面,您可能会遇到一些限制,但SearchQuery插槽是开始的地方。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57134770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档