我正在使用对话框流程在chatbot上工作,使用google上的操作获取用户的位置,我正在使用服务器端代码,如下所示
const functions = require('firebase-functions');
const DialogflowApp = require('actions-on-google').DialogflowApp;
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const requestPermission = (app) => {
app.askForPermission('To locate you', app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
};
const userInfo = (app) => {
if (app.isPermissionGranted()) {
const address = app.getDeviceLocation().address;
if (address) {
app.tell(`You are at ${address}`);
}
else {
// Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates
// and a geocoded address on voice-activated speakers.
// Coarse location only works on voice-activated speakers.
app.tell('Sorry, I could not figure out where you are.');
}
} else {
app.tell('Sorry, I could not figure out where you are.');
}
};
const app = new DialogflowApp({request, response});
const actions = new Map();
actions.set('request_permission', requestPermission);
actions.set('user_info', userInfo);
app.handleRequest(actions);
});
一旦触发request_permission意图,这将向我的应用程序发送 request_permission 操作,并根据我的服务器端代码运行帮助方法askForPermission(...)
这将对Google上的操作发送PLACEHOLDER_FOR_PERMISSION
响应,这将进一步触发“要找到您,我只需要从Google获取您的街道地址。这样可以吗?“消息并将此作为对话框流程的响应返回,而不是接收 PLACEHOLDER_FOR_PERMISSION 作为对话框流程中的响应。任何人请帮助我错过了什么在这?有任何建议....
答案 0 :(得分:1)
请求您应该在代理方面获得许可,例如谷歌援助或Facebook,并且您的样本仅在谷歌援助中运作良好,但您无法直接在dialgflow上进行测试。