如何在Dialogflow上工作askForPermission()?

时间:2018-08-29 11:55:05

标签: javascript dialogflow fulfillment

我正在尝试使用dialogflow v2实现来获取用户位置。我找到了一个示例here,但是app.SupportedPermissions.DEVICE_PRECISE_LOCATION在dialogflow v2上返回了未定义。

我从下面的示例从v1迁移到v2,然后再次部署了它,但仍然遇到相同的错误。

  

conv.SupportedPermissions.DEVICE_PRECISE_LOCATION

实现V2

enter image description here

示例代码的实现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);

});

0 个答案:

没有答案