简体   繁体   English

如何通过webhook在dialogflow上从Web演示回复消息

[英]how to reply message from web demo on dialogflow via webhook

I'm currently trying to add chatbot to my website. 我目前正在尝试将聊天机器人添加到我的网站。 I'm integrating web demo on the agent used for our lIne bot. 我正在将Web演示集成到用于我们的lIne机器人的代理上。 which some responses are handled by lambda webhook. 其中一些响应由lambda webhook处理。

what I'm asking is can we send responses to web demo using lambda? 我要问的是我们可以使用lambda将响应发送到Web演示吗? if can, then how do I send them? 如果可以的话,我该如何发送? there suppose to be some id right? 应该有身份证吗? and do we use HTTP post request to send them? 我们是否使用HTTP发布请求发送它们? I couldn't find an example. 我找不到一个例子。

and for some intent which has more than one response handled by dialogflow it can only send one of them. 对于某些意图,它有多个由dialogflow处理的响应,则只能发送其中之一。 why is that? 这是为什么? and what should I do so that I can send all of them via dialogflow? 我应该怎么做才能通过dialogflow发送所有这些信息?

Yes, it can be achieved and you can refer to give NodeJs code for that, 是的,可以实现,您可以参考为此提供NodeJs代码,

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. 对于每种intent ,我们都必须在dialogFlow中定义一个action

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. 因此,当用户输入任何查询时,都会触发您的Webhook,它将在switch案例中查找特定的操作并形成该案例,您可以将重播发送回您的机器人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM