如何从express在dialogflow中制作欢迎消息?

时间:2019-07-10 01:29:52

标签: express dialog

我在“默认欢迎”意图中为welcome设置了事件,但是当我打开Dialogflow时,它不会自动触发消息,

我确实想收到一条消息,并在打开Dialogflow机器人时显示欢迎消息,如何在Express中做到这一点?我读到我们需要发送Request来做到这一点,但是如何在Express中做到这一点?

这是我的快递网络挂钩

const [express, cors] = [
  require("express"),
  require("cors"),
];
const { WebhookClient } = require("dialogflow-fulfillment");
const app = express();

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

app.use(
  cors({
    origin: "*"
  })
);


function fallback(agent) {
  agent.add('sorry, can you repeat that?')
}

function welcome(agent) {
  agent.add("Hi there, i am a bot , and i will help u ")
}

function WebhookProcessing(req, res) {
  const agent = new WebhookClient({ request: req, response: res });

  let intentMap = new Map();
  intentMap.set("DefaultFallback", fallback);
  intentMap.set("DefaultWelcomeIntent", welcome);

  agent.handleRequest(intentMap);
}

// Webhook
app.post("/", function(req, res) {
  console.log(">>> LOCAL SERVER RUNNING <<<");
  WebhookProcessing(req, res);
});

app.listen(process.env.PORT || 8080);

0 个答案:

没有答案