Dialogflow web hooks: how to develop locally and deploy to Cloud Functions

Antony Harfield
Dec 29, 2018 · 8 min read

1. Start with a template and run it locally

2. Use ngrok to serve local http to public https

npm install ngrok --save-dev
  ...
"scripts": {
"tunnel": "ngrok http 8080"
},
Running ngrok to obtain a public https URL for your local server
Configure Dialogflow’s Fulfillment to use an ngrok forwarding URL

3. Reloading (nodemon) and debugging (VS Code)

npm install nodemon --save-dev
  "scripts": {
"dev": "nodemon --inspect simpleServer.js",
"tunnel": "ngrok http 8080"
},
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]

4. Code style (optional)

npm install standard --save-dev
"scripts": {
...
"lint": "standard"
},

5. (a) Deployment to Cloud Functions for Firebase

exports.dialogflowFirebaseFulfillment = 
functions.https.onRequest((request, response) => { ... })
Running an express app through Cloud Functions

Next, the deployment…

Deploy a web hook to Cloud Functions on Firebase
  "scripts": {
...
"deploy-cf": "firebase deploy --only functions"
},

Local Node.js vs Cloud Functions

5. (b) Deployment to Google App Engine (bonus!)

"scripts": {
...
"deploy-ae": "gcloud app deploy --project [yourprojectid]"
},

Summary

Antony Harfield

Written by

Coding in Phitsanulok… Computer Scientist at Naresuan University, Consultant at Apptitude, and Developer at Rainforest Connection

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade