I have a question about webhook connect.
I edited usually by inline editor of dialogflow.
But now I want to edit in my local.
So I did some setting watching two examples.
https://chatbotsmagazine.com/creating-nodejs-webhook-for-dialogflow-2b050f76cd75
https://github.com/dialogflow/fulfillment-temperature-converter-nodejs
[1] I made file,
(1) Users/a/firebase.js
(2) Users/a/functions/index.js (with package module)
(3) webhook server by ngrok.
(4) I attached this link 'https://ngrok~~/webhook' on dialogflow webhook
[2] firebase.js has
{}
[3] index.js has
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
const admin = require('firebase-admin');
const server = express();
//admin.initializeApp();
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((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 hello(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('hello', hello);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
var port = process.env.PORT || 3000;
// create serve and configure it.
server.get('/getName',function (req,res){
res.send('Swarup Bam');
});
server.listen(port, function () {
console.log("Server is up and running...");
});
And server starts locally with ngrok port 3000
.
I've written server.listen
in my code.
But it seems that it doesn't have webhook post in my code.
So, in conclusion, when I write 'hello' in my dialogflow , ngrok gives a 404 not found
error.