在Dialogflow中,我有一个名为GetLocation的Intent。用户可以输入一个短语,例如:我想看印度,而参数“ 位置”存储该位置。对于我的Paramater,其名称为“ 位置”,其实体为sys.location
。对话流能够识别我的位置。
接下来,对话框流将写入我的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);
}
答案 0 :(得分:0)
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/