Skip to content

Instantly share code, notes, and snippets.

@jan53n
Created June 24, 2018 04:36
Show Gist options
  • Save jan53n/a529a301d973564a6ef99b40744b1dc9 to your computer and use it in GitHub Desktop.
Save jan53n/a529a301d973564a6ef99b40744b1dc9 to your computer and use it in GitHub Desktop.
running dialogflow-fulfillment on private server (without using firebase-functions)
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!'));
@jan53n
Copy link
Author

jan53n commented Jun 24, 2018

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": "*" } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment