Skip to content

Instantly share code, notes, and snippets.

@antonyharfield
Last active April 26, 2024 09:05
Show Gist options
  • Save antonyharfield/b76f0556d7e696ba981005a78a8253ec to your computer and use it in GitHub Desktop.
Save antonyharfield/b76f0556d7e696ba981005a78a8253ec to your computer and use it in GitHub Desktop.
A fulfillment web hook for Dialogflow supporting local dev and Firebase Cloud Functions
const express = require('express')
const { WebhookClient } = require('dialogflow-fulfillment')
const app = express()
app.get('/', (req, res) => res.send('online'))
app.post('/dialogflow', express.json(), (req, res) => {
const agent = new WebhookClient({ request: req, response: res })
function welcome () {
agent.add('Welcome to my agent!')
}
let intentMap = new Map()
intentMap.set('Default Welcome Intent', welcome)
agent.handleRequest(intentMap)
})
module.exports = app
const functions = require('firebase-functions')
const app = require('./app')
exports.app = functions.https.onRequest(app)
const app = require('./app')
app.listen(process.env.PORT || 8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment