在 Dialogflow 对话中积累响应参数,然后通过组合所有参数进行 web-hook 请求

Accumulating response parameters in Dialogflow conversation and then making a web-hook request by combining all parameters

我正在使用 Dialogflow 制作一个基本的旅行聊天机器人。假设我在第一个响应中获得登机地点,在第二个响应中获得着陆位置,在第三个响应中获得旅行日期。现在我想累积所有三个参数并对某个航班 API 进行自定义 webhook 响应。执行此操作的正确方法是什么? 目前我所做的是将每个上下文的生命周期增加到 15(假设最大对话长度),然后从 json 的 outputContexts 参数中提取参数。 json 回复已附在下方。

另一个用例可以是在 2 个后续对话中获取城市和日期,然后进行组合网络挂钩响应以获取天气预报。

{
  "responseId": "some id",
  "queryResult": {
    "queryText": "London",
    "action": "get_flights",
    "parameters": {
      "geo-city1": "London"
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Here is a webhook response.",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Here is a webhook response."
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/project name/agent/sessions/some id/contexts/awaiting_flight_boolean",
        "lifespanCount": 13,
        "parameters": {
          "date-time": "2020-11-14T12:00:00+05:30",
          "geo-city1.original": "London",
          "geo-city1": "London",
          "date-time.original": "2 days from now"
        }
      },
      {
        "name": "projects/project name/agent/sessions/some id/contexts/await_landing_city",
        "lifespanCount": 11,
        "parameters": {
          "geo-city1.original": "London",
          "date-time.original": "2 days from now",
          "BotName": "",
          "from.original": "Dubai",
          "date-time": "2020-11-14T12:00:00+05:30",
          "geo-city1": "London",
          "BotName.original": "",
          "from": "Dubai"
        }
      },
      {
        "name": "projects/project name/agent/sessions/some id/contexts/awaiting_date_of_travel",
        "lifespanCount": 12,
        "parameters": {
          "geo-city1": "London",
          "from": "Dubai",
          "geo-city1.original": "London",
          "from.original": "Dubai",
          "date-time.original": "2 days from now",
          "date-time": "2020-11-14T12:00:00+05:30"
        }
      },
      {
        "name": "projects/project name/agent/sessions/some id/contexts/awaiting_boarding_location",
        "lifespanCount": 14,
        "parameters": {
          "geo-city1": "London",
          "geo-city1.original": "London"
        }
      }
    ],
    "intent": {
      "name": "projects/project name/agent/intents/some id",
      "displayName": "BoardingTheFlight"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  }
}

由于我是 dialogflow 的新手,所以我想不出更好的解决方案。有人可以告诉 correct/easier 方法吗?

由于您是 Dialogflow 的新手,我想向您推荐 Understand fulfillment by integrating Dialogflow with Calendar codelab,您将能够在其中看到设置 fulfillment 的正确过程。

你的解决方案似乎是正确的,另外你可以检查这个tutorial这与你的情况相似。

Dialogflow 在 Github.

上也有一些请求和回复的例子