dialogflow-es - 如何在 Dialogflow 实现中获取当前意图的名称?
问题描述
我想在实现中获取当前意图的名称,以便我可以根据我所处的不同意图处理不同的响应。但我找不到它的功能。
function getDateAndTime(agent) {
date = agent.parameters.date;
time = agent.parameters.time;
// Is there any function like this to help me get current intent's name?
const intent = agent.getIntent();
}
// I have two intents are calling the same function getDateAndTime()
intentMap.set('Start Booking - get date and time', getDateAndTime);
intentMap.set('Start Cancelling - get date and time', getDateAndTime);
解决方案
request.body.queryResult.intent.displayName
将给出意图名称。
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function getDateAndTime(agent) {
// here you will get intent name
const intent = request.body.queryResult.intent.displayName;
if (intent == 'Start Booking - get date and time') {
agent.add('booking intent');
} else if (intent == 'Start Cancelling - get date and time'){
agent.add('cancelling intent');
}
}
let intentMap = new Map();
intentMap.set('Start Booking - get date and time', getDateAndTime);
intentMap.set('Start Cancelling - get date and time', getDateAndTime);
agent.handleRequest(intentMap);
});
但是如果你使用两个不同的函数会更有意义intentMap.set
推荐阅读
- asp.net - 使用VB注册和登录ASP.net后如何在新页面显示名称
- python - 遍历列表以创建库存检查器
- python - 动画matplotlib图,Y轴点排列不正确
- swift - 秒表在后台运行 - 快速
- git - Flutter Doctor 脚本抛出错误然后崩溃
- python - Python struct模块从文件中读取多个浮点数
- angularjs - Angularfire ReferenceError:未定义 Firebase
- spring - 当http服务器响应404时未调用Spring WebClient异步回调
- java - Collectors.groupingBy 和 mapping 构造一个映射
- dji-sdk - 将任务航点上传到 DJI 无人机 (A3) 时出现 DATA_NOT_ENOUGH 错误