firebase - DialogFlow 参数值
问题描述
在 Dialogflow 中,我有一个名为 GetLocation 的 Intent。用户可以输入一个短语,例如:我想看看印度,参数“位置”存储该位置。对于我的参数,它的名称是“位置”,它的实体是sys.location
. Dialog Flow 能够识别我的位置。
接下来,Dialog Flow写入我的Firebase数据库并写入数据库的位置参数(位置:(来自DialogFlow的位置)。问题是,它不是正常写入数据库的位置参数,而是更改了“位置”到管理区域:(来自 DialogFlow 的位置)。如何阻止它重命名 firebase 数据库中的位置参数?
这是我的履行代码:
function yourFunctionHandler(agent) {
const location = agent.parameters.Location;
return admin.database().ref('locations').transaction((locations) => {
if(locations !== null) {
locations.place = location;
agent.add(`Our recorded locations ` + location);
}
return location;
}, function(error, isSuccess) {
});
// return admin.database().ref('/locations/place').set(location);
}
解决方案
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function handleAge(agent) {
const age = agent.parameters.age;
agent.add(`Thank you...`);
return admin.database().ref('ageInfo').transaction((ageInfo) => {
if(ageInfo !== null) {
let oldAverage = ageInfo.runningAverage;
let oldTotalCount = ageInfo.totalCount;
let newAverage = (oldAverage * oldTotalCount + age) / (oldTotalCount + 1);
ageInfo.runningAverage = newAverge;
ageInfo.totalCount+=1;
agent.add(`Average age stored` + newAverage);
}
return ageInfo;
}, function(error, isSuccess) {
console.log('error: ' + isSuccess);
});
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('AskAge', handleAge);
agent.handleRequest(intentMap);
});
URL= http://www.peterfessel.com/2018/07/google-dialogflow-chatbot-realtime-database-tutorial-read-write/
推荐阅读
- installation - Inno Setup Disable checkbox if another checkbox被选中
- c# - 如何在 C# 中将变量从方法发送到调用方方法的 catch 块?
- javascript - 从 CSV 文件导入数据
- php - 如何重命名 wordpress 插件的菜单标签?
- php - 如何在 codeigniter 中更改数据库的列 2 小时。2 小时后,它在 php codeigniter 中重置为默认值
- php - 如何将我的函数连接到 Symfony 4 中的模板?
- database - 哪个是用于 UWP 的 Unity 的最佳数据库?
- javascript - 如何在刷新时保存页面元素
- php - 获取表单提交时动态单选按钮的 $_post 值
- jsf - 未找到 WebSphere JSF 属性(在等效于有效的设置上)