1

I have built a simple intent using google dialogflow console. It essentially leads the other party through answering 4 questions and then hits a webhook endpoint via ngrok on my dev box.

The endpoint returns the following application/json payload:

{
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Larry Johnson, thank you for choosing XYZ Corp. Your info is on the way!"
        ]
      }
    }
  ]
}

It's hitting a Laravel application for the diaglogflow webhook (no slot fulfillment) and working as expected if I perform the flow from the dialogflow console:

enter image description here

Raw API Response

{
  "responseId": "933d20f8-1b43-41f4-8667-51e2e49a6703-18dedd3b",
  "queryResult": {
    "queryText": "5pm to 8pm",
    "parameters": {
      "callback_date": [
        "2023-03-10T12:00:00-05:00"
      ],
      "callback_time": [
        {
          "endTime": "2023-03-05T20:00:00-05:00",
          "startTime": "2023-03-05T17:00:00-05:00"
        }
      ],
      "loan_type": "second",
      "loan_amount": 250000,
      "person": {
        "name": "John Johonson"
      }
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "John Johonson, thank you for letting us know the best time to contact you. We will call you between 17:00:00/20:00:00 on 2023-03-10T12:00:00-05:00. If you need to update your availability, text \"update info\" to this number or call 800-555-1212.",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Thank you for choosing XYZ Corp"
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/norse-journey-343620/agent/sessions/eb3f7bb1-b2d7-b4df-4371-58cb9100a546/contexts/loan",
        "lifespanCount": 5,
        "parameters": {
          "callback_time": [
            {
              "startTime": "2023-03-05T17:00:00-05:00",
              "endTime": "2023-03-05T20:00:00-05:00"
            }
          ],
          "callback_date": [
            "2023-03-10T12:00:00-05:00"
          ],
          "loan_amount": 250000,
          "loan_type.original": "second",
          "person.original": "John Johonson",
          "callback_time.original": [
            "5pm to 8pm"
          ],
          "person": {
            "name": "John Johonson"
          },
          "callback_date.original": [
            "friday"
          ],
          "loan_amount.original": "250,000",
          "loan_type": "second"
        }
      }
    ],
    "intent": {
      "name": "projects/norse-journey-343620/agent/intents/7aa3f1c0-dfc7-4a8e-9fa3-88100dfdca26",
      "displayName": "AFTER-HRS-INQ",
      "endInteraction": true
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "end_conversation": true,
      "webhook_latency_ms": 2259
    },
    "languageCode": "en",
    "sentimentAnalysisResult": {
      "queryTextSentiment": {}
    }
  },
  "webhookStatus": {
    "message": "Webhook execution successful"
  }
}

The text, "Thank you for choosing XYZ Corp" is outputted to the dialogflow console as expected.

On the other hand, if I call the dialogflow ES api through a php application, the webhook is still hit and the routines all run correctly and the dialogflow trace (from dialogflow console -> History) shows it was successful, no errors, but for some reason it seems to be ignoring the fulfillmentMessages instruction returned by the webhook.

The php application is reacting to a Twilio webhook for an incoming SMS message. My php backend takes the text from the sms and submits to google dialogflow api, resulting in our google dialogflow webhook being hit, just as if I went through the flow manually using dialogflow console.

The obvious difference is that my php app hitting dialogflow api vs running through the flow in the dialogflow console. I am missing the difference after a day or so of chewing on this.

My webhook api is still being hit in either case and the result returned from the webhook appears to have the correct fulfillmentMessage structure returned in both cases. Our existing api to dialogflow works otherwise in our application and this appears to work as well, except that it is not using the fulfillmentMessages instruction returned from the webhook and instead, uses the default text configured for the intent inside of the dialogflow console when the webhook is hit as a result of my php api call to dialogflow.

Output from dialogflow console when webhook is hit as a result of an php api call to dialogflow. Note that it indicates the webhook was successful, no parse errors, etc.

{
  "id": "681914f0-8c0b-429f-b516-5fb6e6754a94-18dedd3b",
  "fulfillmentText": "larry johnson, thank you for letting us know the best time to contact you. We will call you between 06:00:00/21:00:00 on 2023-03-08T12:00:00-05:00. If you need to update your availability, text \"update info\" to this number or call 800-555-1212.",
  "language_code": "en",
  "queryText": "6am to 9pm",
  "webhookPayload": {},
  "intentDetectionConfidence": 1,
  "action": "",
  "webhookSource": "",
  "parameters": {
    "callback_date": [
      "2023-03-08T12:00:00-05:00"
    ],
    "callback_time": [
      {
        "endTime": "2023-03-06T21:00:00-05:00",
        "startTime": "2023-03-06T06:00:00-05:00"
      }
    ],
    "loan_type": "second",
    "person": {
      "name": "larry johnson"
    },
    "loan_amount": "200000.0"
  },
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Thank you for choosing XYZ Corp"
        ]
      }
    }
  ],
  "diagnosticInfo": {
    "end_conversation": true,
    "webhook_latency_ms": "1115.0"
  },
  "webhookStatus": {
    "webhookStatus": {
      "message": "Webhook execution successful"
    },
    "webhookUsed": true
  },
  "outputContexts": [
    {
      "lifespanCount": 5,
      "name": "loan",
      "parameters": {
        "callback_time.original": [
          "6am to 9pm"
        ],
        "callback_date": [
          "2023-03-08T12:00:00-05:00"
        ],
        "loan_type": "second",
        "loan_amount": "200000.0",
        "loan_amount.original": "200000",
        "loan_type.original": "second",
        "callback_time": [
          {
            "endTime": "2023-03-06T21:00:00-05:00",
            "startTime": "2023-03-06T06:00:00-05:00"
          }
        ],
        "person.original": "larry johnson",
        "callback_date.original": [
          "wed"
        ],
        "person": {
          "name": "larry johnson"
        }
      }
    }
  ],
  "intent": {
    "isFallback": false,
    "displayName": "AFTER-HRS-INQ",
    "id": "7aa3f1c0-dfc7-4a8e-9fa3-88100dfdca26"
  }
}

Again, sending back from my webhook endpoint, the same structure to set the text to display back.

{
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Thank you for choosing XYZ Corp"
        ]
      }
    }
  ]
}

Any help or insights is greatly appreciated.

0 Answers0