感谢您抽出时间阅读此查询。我正在使用谷歌云功能和firebase实现一个Dialogflow机器人。
用例,我希望设计的是 用户说“我希望了解有关纽约的信息” 对话流使用Geo.City参数捕获意图“lookingForInformation”为“New York”,Action为getInfo。
我已经设置了Google云功能,并与Apiai和Firebase集成。
我的Firebase Json看起来像
{
information :
{
1 :
{
destinationName : "New Jersey",
DestinationInfo : "Its a nice place"
},
2 :
{
destinationName : "London",
DestinationInfo : "Its a lovely place"
},
}
}
我的Google云端功能如下
function processV1Request (request, response) {
let action = request.body.result.action; // https://dialogflow.com/docs/actions-and-parameters
let parameters = request.body.result.parameters; // https://dialogflow.com/docs/actions-and-parameters
let inputContexts = request.body.result.contexts; // https://dialogflow.com/docs/contexts
let requestSource = (request.body.originalRequest) ? request.body.originalRequest.source : undefined;
const googleAssistantRequest = 'google'; // Constant to identify Google Assistant requests
const app = new DialogflowApp({request: request, response: response});
// Create handlers for Dialogflow actions as well as a 'default' handler
const actionHandlers = {
// The default welcome intent has been matched, welcome the user (https://dialogflow.com/docs/events#default_welcome_intent)
// Default handler for unknown or undefined actions
'checkDestination': () =>{
// Use the Actions on Google lib to respond to Google requests; for other requests use JSON
if (requestSource === googleAssistantRequest) {
let responseToUser = {
speech: 'I wish to check destinations', // spoken response
text: 'I wish to check destinations' // displayed response
};
sendGoogleResponse(responseToUser);
} else {
console.log(mySet);
let responseToUser = {
speech: 'I wish to check destinations', // spoken response
text: 'I wish to check destinations' // displayed response
};
sendResponse(responseToUser);
}
},
};
如果参数geo.city在我的数据库中作为有效目标存在,我希望更新上面的上述云函数来查询firebase数据库。如果是,它应该从数据库返回信息,如果“否”,它应该回答“抱歉,我没有关于这个城市的信息”。
温馨的问候