Search code examples
dialogflow-esdialogflow-es-fulfillment

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


I am making a basic travel chatbot using Dialogflow. Suppose that I get the boarding location in one response, landing location in 2nd response and the date of travel in third response from bot. Now I want to accumulate all three parameters and make a custom webhook response to some flight API. What's the correct way to do this? Currently what I've done is increase the life span of each of the context to 15(max conversation length possible let's say) and then extract the parameters from outputContexts parameter from json. The json response has been attached below.

Another use case can be getting city and date in 2 follow up conversations and then making a combined web-hook response to fetch weather forecast.

{
  "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"
  }
}

I am unable to come up with a better soultion as I am new to dialogflow. Can someone tell the correct/easier way to do this?


Solution

  • As you are new to the Dialogflow, I would like to recommend you Understand fulfillment by integrating Dialogflow with Calendar codelab, where you will be able to see the correct process of setting up fulfillment.

    Your solution seems to be correct, additionally you can check this tutorial which is similar to your scenario.

    Dialogflow also has some examples of requests and replies on Github.