我正在尝试使用dialogflow v2实现来获取用户位置。我找到了一个示例here,但是app.SupportedPermissions.DEVICE_PRECISE_LOCATION
在dialogflow v2上返回了未定义。
我从下面的示例从v1迁移到v2,然后再次部署了它,但仍然遇到相同的错误。
conv.SupportedPermissions.DEVICE_PRECISE_LOCATION
实现V2
示例代码的实现V1
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);
});