NodeJS Webhook for Dialogflow Fulfillment

Abhinav Kumar
3 min readFeb 29, 2020
Photo by Nicolas Picard on Unsplash

When you are building an agent on Dialogflow, it is important to set up webhook fulfillment especially when your agent grows and has a number of intents. It becomes difficult to manage those intent and intent handlers, especially when you are dealing with any 3rd party API or building a multi-channel agent within the default provided Inline Editor(Powered by Cloud Functions for Firebase). So, it’s a good idea to create and set up a webhook server from your local codebase.

So, let's create a NodeJS webhook fulfillment

Prerequisite: Beginner-level knowledge of JavaScript, NodeJS, ExpressJS, Dialogflow

Steps:

  1. Create an agent, it will have Default Fallback Intent, Default Welcome Intent and enable webhook call for Default Welcome Intent
Default welcome Intent
Default Welcome Intent

Now enable the webhook call for this intent. You can find the option in the fulfillment section at the bottom.

Enable webhook call
Enable webhook call

Similarly, enable webhook call for Default Fallback Intent. This option lets your agent call the webhook API with a post request. You can enable webhook calls for all those intents that required some backend processing, database query, or any this-party API integration.

2. Now let's create the webhook server.

create app.js file, add one API route with ‘/dialogflow’. All the agent webhook requests will be handled by this route.

When the agent will grow, it will have a number of intent based on different functionality. It is recommended to create a different intent handler file, based on the feature.

--

--

Abhinav Kumar

Software Engineer @Zalando, Living in Germany, Tech enthusiast, Story Teller, Write about my learning and experiences in tech and in life.