如果您有 2 个意图,例如意图 1 和意图 2,让我们举个例子。(注意:请在意图实现部分为那些意图“启用 Webhook”)
意图 1 短语:
意图 1 响应:
intent-1 输出上下文:
意图 2 事件
意图 2 响应
现在使用 Node/Python 或任何您熟悉的语言创建 API。我在 Node 中创建了 API 并在 webhook 中进行了配置。
这是示例代码:
const express = require('express');
const fetch = require('node-fetch');
const app = express()
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Starting server at ${port}`);
});
app.use(express.json())
app.post('/webhook/v2', async (req, res) => {
console.log("Dialogflow: Received a POST request");
if (!req.body) return res.sendStatus(400)
let responseObj = {
"followupEventInput": {
"name": "test",
},
"source": ""
}
return res.json(responseObj)
})
所以在这里我将返回{"followupEventInput": {"name": "test",}
所有 webhook 调用(因为它是为了测试目的。你可以在这里使用你自己的业务逻辑,并在此基础上添加 followupEventInput 作为响应)。所以在配置webhook后,当我尝试在Dialogflow模拟器中输入Hi/Hello(即intent-1的训练短语)时,Dialogflow会检测到intent-1并调用webhook。对于 webhook 响应,我们设置了followupEventInput,所以在内部它会调用 intent-2 并显示 intent-2 响应。
对于测试,您可以检查在模拟器中为 intent-1 设置的输出上下文。(你好)
在这里,我附上了可能对您有所帮助的结果图像。

如果您仍有任何疑问,请告诉我。