Yes, it can be achieved and you can refer to give NodeJs code for that,
const express = require("express");
const bodyParser = require("body-parser");
const apiai = require("apiai");
const request = require("request");
const app = express();
app.use(bodyParser.json());
app.set("port", process.env.PORT || 5000);
app.post("/", (req, res) => {
//console.log(req.body)
const action = req.body.result.action;
if (!req.body || !req.body.result || !req.body.result.parameters) {
return res.status(400).send("Bad Request");
}
console.log("--------------------------------");
console.log("Action =>", action);
console.log("--------------------------------");
switch (action) {
case "price.search":
const webhookReply = `Sorry NO book found in store.`;
res.status(200).json({
source: "webhook",
speech: webhookReply,
displayText: webhookReply
});
break;
default:
break;
}
});
app.listen(app.get("port"), function() {
console.log("* Webhook service is listening on port:" + app.get("port"));
});
For every intent
, there will be an action
of that we have to define in dialogFlow.
So when the user enters any query your webhook will get triggered it will
go in the switch case to find the particular action and form that case you can send back the replay to your bot.