Fulfillment

Webhook

Setting up a webhook allows you to pass information from a matched intent into a web service and get a result from it.

Requirements

Authentication

Authentication can be done in 2 ways:

Basic authentication with login and password.

Authentication with additional authentication headers.

If the integrated service doesn’t require any authentication, leave the authentication fields blank.

The service must use HTTPS and the URL must be publicly accessible.

Caution: Dialogflow does not support self-signed SSL certs. For information on SSL setup, please refer to this documentation.

Request

Your web service receives a POST request from Dialogflow. This is in the form of the response to a user query, matched by intents with webhook enabled. Be sure that your web service meets all the webhook requirements specific to the API version enabled in this agent.

If a request is sent from one of the messaging platforms, the originalRequest field is added to the response to a query.

This format is chosen in order to simplify the response parsing on the service side with the help of Dialogflow SDKs.

Note: In the case of an error or empty response, Dialogflow will send a standard response to the /query to the client. In this case, the agent response will contain the Response content defined in the triggered intent.

Limits

Timeout for service response – 5 seconds.

Data received in the response from the service – up to 64K.

Slot Filling

If you want to send requests for required parameters from Dialogflow to your web service, check the option Use webhook for slot filling in the Fulfillment section of the intent.

Example

Cloud Functions for Firebase

For simple webhook testing and implementation, you can use the Cloud Functions for Firebase area of the Fulfillment page. In most cases the free "Spark" tier of Firebase is all you'll need. Tier limitations and pricing information for the other tiers can be found on the Firebase pricing page.

To enable:

Click on Fulfillment in the left menu.

Click the switch for Inline Editor.

Some basic, functional code provided to help you get started.

To deploy your fulfillment, click the Deploy button under the code editor.

After clicking Deploy, Dialogflow will save your Cloud Function for Firebase and begin the deployment process. When deployment is complete, you'll see a timestamp next to the Deploy button, signifying the last time the function was deployed.

The link under the code editor can be used to visit the function's logs in the Firebase console. This is used to debug issues and get information on your function.

"Graduating" your code

Once you're ready to move your code out of the Fulfillment page, you can use the Download button to get a .ZIP file of your code in it's current state. Using the Firebase CLI, you can unzip your code locally and deploy more complex fulfillment code.

Limitations

Here is a list of things to be aware of when using the Cloud Functions for Firebase option:

If you modify your function outside of code editor, you can no longer use the Dialogflow editor to modify your Cloud Function for Firebase. Your function will continue to provide fulfillment for your agent, but if you need to make changes, you will need to do so in the Firebase console.

The function must be named "dialogflowFirebaseFulfillment". If you change the name of your function it will not deploy via Dialogflow. If you want to change the name of your function you can download the code, change the function name, and deploy through Firebase's CLI.

Code modified in the dialogflow editor cannot be saved or downloaded without being deployed.

Dialogflow's editor only supports two files: index.js and package.json (modifying package.json will install any dependencies you specify upon deployment)