【问题标题】:How can I create a bot in Amazon Lex for getting weather update?如何在 Amazon Lex 中创建机器人以获取天气更新?
【发布时间】:2021-01-24 09:10:23
【问题描述】:

我正在尝试获取天气更新。 Python 代码运行良好,但我无法将其嵌入 Amazon Lex。它显示收到的错误响应。

from botocore.vendored import requests
    # using openweathermap api 
    api_address = 'http://api.openweathermap.org/data/2.5/weather?appid=__api_key_here__&q='
    city = input("Enter city >> ")

    url = api_address + city

    json_data = requests.get(url).json()
    formatted_data = json_data['weather'][0]['main']
    desc_data = json_data['weather'][0]['description']
    print(formatted_data)
    print(desc_data)
    # print(json_data)

【问题讨论】:

    标签: amazon-web-services chatbot weather


    【解决方案1】:
    • 确保 api 运行完美的 python 代码。
    • 取决于您需要将类型保持为 ElicitSlot 或 ElicitInten 的下一个状态
    • 如果您使用 lambda 作为 lex 的后端,我们需要以以下格式发送响应。
    • 您可以参考 Lambda 响应格式的链接 Lambda response formats

            {
          "dialogAction": {
            "type": "Close",
            "fulfillmentState": "Fulfilled",
            "message": {
              "contentType": "PlainText",
              "content": "Thanks, your pizza has been ordered."
            },
            "responseCard": {
              "version": integer-value,
              "contentType": "application/vnd.amazonaws.card.generic",
              "genericAttachments": [
                  {
                     "title":"card-title",
                     "subTitle":"card-sub-title",
                     "imageUrl":"URL of the image to be shown",
                     "attachmentLinkUrl":"URL of the attachment to be associated with the card",
                     "buttons":[ 
                         {
                            "text":"button-text",
                            "value":"Value sent to server on button click"
                         }
                     ]
                  } 
              ] 
            }
          }
        }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 2019-09-30
      • 1970-01-01
      • 2018-10-17
      相关资源
      最近更新 更多