I'm trying to make a chatbot using nodejs webhook and dialogflow ES FULFILLMENT. I create the intent "Greeting" and I just want to get the answer from chat bot. This is my code
c
onst express = require("express");
const app = express();
const { WebhookClient } = require("dialogflow-fulfillment");
app.get("/", function (req, res) {
res.send("Hello World");
});
app.post("/webhook", express.json(), function (req, res) {
const agent = new WebhookClient({ request: req, response: res });
console.log("Dialogflow Request headers: " + JSON.stringify(req.headers));
console.log("Dialogflow Request body: " + JSON.stringify(req.body));
console.log("--------------------------------------------------------");
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?`);
}
function greetings(agent) {
agent.add(`Hello, what's your name?`);
}
function reply(agent) {
agent.add(`Hi Chris, How can I help you?`);
}
let intentMap = new Map();
intentMap.set("Default Welcome Intent", welcome);
intentMap.set("Default Fallback Intent", fallback);
intentMap.set("Greetings", greetings);
intentMap.set("Reply", reply);
agent.handleRequest(intentMap);
});
let port = 3000;
app.listen(port, () => {
console.log("Estamos ejecutando el servidor en el puerto " + port);
});
The webhook got activated when user say "Hi" then when the customer type again the bot does not work anymore. How can I do this?