Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Express.JS integration sample #90

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions samples/express-js-integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Test_Agent",
"version": "0.0.1",
"description": "Test Google Assistant Agent webhook",
"main": "server.js",
"author": "Abhinav Tyagi, New Delhi, India",
"dependencies": {
"dialogflow-fulfillment": "^0.4.1",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"actions-on-google": "^2.2.0"
}
}
43 changes: 43 additions & 0 deletions samples/express-js-integration/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const {WebhookClient} = require('dialogflow-fulfillment');
const express = require('express');
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));



function welcome (agent) {
agent.add(`Welcome to Express.JS webhook!`);
}

function fallback (agent) {
// console.info(`unknown -- ${agent.originalRequest}`);
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}

function WebhookProcessing(req, res) {
const agent = new WebhookClient({request: req, response: res});
console.info(`agent set`);

let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('<INTENT_NAME_HERE>', yourFunctionHandler);
agent.handleRequest(intentMap);
}


// Webhook
app.post('/', function (req, res) {
console.info(`\n\n>>>>>>> S E R V E R H I T <<<<<<<`);
WebhookProcessing(req, res);
});

app.listen(8080, function () {
console.info(`Assistant webhook listening on port 8080!`)
});