dialogflow-es - dialogflow Webhookclient“request_”属性
问题描述
我正在尝试使用 Dialogflow 构建一个 facebook messenger 聊天机器人。在 dialogflow 实现内联编辑器中,我发现可以使用 agent.request_.body 来获取请求的正文。我假设“request_”是 WebhoodClient 对象的属性?但是我找不到任何详细说明的文档,您能否告知我的理解是否正确以及在哪里可以找到参考或文档?
const agent = new WebhookClient({ request, response });
console.log(JSON.stringify(agent.request_.body));
谢谢
解决方案
Google在此处提供 Dialogflow webhook 的文档,其中包括此示例 webhook 以检查参数并动态创建槽填充提示:
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function flight(agent) {
const city = agent.parameters['geo-city'];
const time = agent.parameters['time'];
const gotCity = city.length > 0;
const gotTime = time.length > 0;
if(gotCity && gotTime) {
agent.add(`Nice, you want to fly to ${city} at ${time}.`);
} else if (gotCity && !gotTime) {
agent.add('Let me know which time you want to fly');
} else if (gotTime && !gotCity) {
agent.add('Let me know which city you want to fly to');
} else {
agent.add('Let me know which city and time you want to fly');
}
}
let intentMap = new Map();
intentMap.set('flight', flight);
agent.handleRequest(intentMap);
});
我的猜测是添加
console.log(agent);
在定义飞行函数之前,然后检查日志以查看代理包含哪些对象,然后添加 console.log(agent.fakeObjectName) 的迭代,直到找到所需的信息。
如果您遵循Google 的 Codelabs 级别 2 中的操作中推荐的部署流程,您的日志将显示在 Firebase 控制台中,如下所示:
希望有帮助!
推荐阅读
- android - 带有 RecyclerView 和其他视图的 BottomSheet
- java - 调用改造没有价值
- hadoop - Namenode没有格式化就无法启动
- c# - 如何在 WPF 中使用 Helix 工具包 MeshBuilder 创建拉伸几何体?
- java - Fragment之间如何共享公共资源?
- android - Android NDK 和 CMake - 如何使用 CMake 生成 Makefile,该 Makefile 将使用他们提供的 .mk 文件构建第三方 .so
- swift - UIView 实时复制另一个视图的 CAAnimation?
- javascript - 使用 JavaScript 删除 iframe 中的 HTML 元素
- java - 从 Spark Java API 中的参数类型创建 DataType
- jquery - 不想在 jQuery 中多次对按钮执行操作?