Python中用于Dialogflow的实现Webhook

时间:2019-12-17 16:39:30

标签: python flask dialogflow actions-on-google

我想使用Flask在Python中开发一个Webhook。我在网上找到的所有文档和教程都是针对Node.js的。

如何在Webhook中使用Python来包含针对某些意图的建议芯片和操作卡?

1 个答案:

答案 0 :(得分:1)

如果您查看Responses doc for Google上的操作,则会看到可以使用的JSON响应,而不是Node.js。

带有建议芯片的回复具有以下格式:

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "These are suggestion chips."
            }
          },
          {
            "simpleResponse": {
              "textToSpeech": "Which type of response would you like to see next?"
            }
          }
        ],
        "suggestions": [
          {
            "title": "Suggestion 1"
          },
          {
            "title": "Suggestion 2"
          },
          {
            "title": "Suggestion 3"
          }
        ],
        "linkOutSuggestion": {
          "destinationName": "Suggestion Link",
          "url": "https://assistant.google.com/"
        }
      }
    }
  }
}

或者,您可以从第三方开发人员那里找到一个预先存在的库来提供实现,例如flask-dialogflow