Как работать askForPermission () в Dialogflow? - PullRequest
0 голосов
/ 29 августа 2018

Я пытаюсь получить местоположение пользователя, используя диалоговое окно v2. Я нашел пример здесь , но app.SupportedPermissions.DEVICE_PRECISE_LOCATION возвращает undefined в диалоговом потоке 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);

});
...