Created
June 24, 2018 04:36
-
-
Save jan53n/a529a301d973564a6ef99b40744b1dc9 to your computer and use it in GitHub Desktop.
running dialogflow-fulfillment on private server (without using firebase-functions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const {WebhookClient} = require('dialogflow-fulfillment'); | |
const {Card, Suggestion} = require('dialogflow-fulfillment'); | |
process.env.DEBUG = 'dialogflow:debug'; | |
var processWebhook = function(request, response) { | |
const agent = new WebhookClient({ request, response }); | |
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); | |
console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); | |
function welcome(agent) { | |
agent.add(`Welcome to my agent!`); | |
} | |
function fallback(agent) { | |
agent.add(`I didn't understand`); | |
agent.add(`I'm sorry, can you try again?`); | |
} | |
let intentMap = new Map(); | |
intentMap.set('Default Welcome Intent', welcome); | |
intentMap.set('Default Fallback Intent', fallback); | |
agent.handleRequest(intentMap); | |
}; | |
app.use( express.json() ); | |
app.post('/', (req, res) => processWebhook( req, res )); | |
app.listen(8888, () => console.log('App listening on port 8888!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
composer.json
{ "name": "ohh.. finally!", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "serve": "node index.js" }, "author": "", "license": "ISC", "dependencies": { "dialogflow-fulfillment": "*", "express": "*", "body-parser": "*", "actions-on-google": "*" } }