简体   繁体   中英

Actions on Google - Suddenly keeps getting into fallback Permission

On my device, it remembers that the location permission has been accepted and follow up intents and everything else works. But on the simulator it doesn't want to remember anymore. It keeps saying:

Sorry, I didn't understand. Right away but first, I need to get your current location from Google. Is that alright?

No matter what if you say yes, no whatever it won't go. Like it is still in that intent where he is asking for location permission. This is my webhook and provided some screenshots of the simulator and debug.

    app.intent('location_permission_question', (conv) => {
        if (conv.user.storage.currentReservationID) {
            return conv.ask(`No can't do, you have an active reservation.`)
        }

        return conv.ask(new Permission({
            context: `Right away but first`,
            permissions:
                ['DEVICE_PRECISE_LOCATION'],
        }));
    });

    app.intent('handler_permission_location_details', (conv, params, permissionGranted) => {
        if (!permissionGranted) {
            return conv.close(`I can't help you then.`);
        }

        const userLatitude = conv.device.location.coordinates.latitude;
        const userLongitude = conv.device.location.coordinates.longitude;
        conv.user.storage.currentUserLocationLatitude = userLatitude;
        conv.user.storage.currentUserLocationLongitude = userLongitude;

        return clientInitGetNewLocations(conv, userLatitude, userLongitude, false)
    });


    app.intent('choose_car', (conv, {carModel}) => {
        if (!conv.data.cars[carModel]) {
            if (conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
                conv.ask(new Suggestions('Next Location'));
            }
            return conv.ask(`I'm sorry but that car model isn't available at ${conv.data.currentLocation.name} you can choose between ${conv.data.carsNames.toString().replaceAll(',', ' and ')}. Which one do you want?`);
        }
        let car = conv.data.cars[carModel][0];
        conv.user.storage.carWaitingForConfirmation = car;
        let carName = car.carModelID.manufacturer;
        const battery = car.batteryChargeLevel;
        const pricePerKM = car.pricing.pricePerKM;
        const pricePerMinDay = car.pricing.pricePerDayMin;
        const pricePerMinNight = car.pricing.pricePerNightMin;

        if (conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
            conv.ask(new Suggestions(['Yes', 'No']));
        }
        return conv.ask(`${carName} at ${conv.data.currentLocation.name} has ${battery}% of battery and costs ${pricePerMinDay}€ per minute and ${pricePerKM}€ per kilometer. Is that okay?`);
    }
);

在此处输入图像描述在此处输入图像描述在此处输入图像描述在此处输入图像描述

UPDATE #1 I tested it on real device and there it works normally. It looks like, the problem lies in actions-on-google.

Seems strange that it works on device but not emulator.

But actually, I think that it should rather be the handler_permission_location_details intent that declares the event actions_intent_PERMISSION in Dialogflow.

I also have an agent that implements location permission to find nearby supermarkets. And this is a short snippet that works. The Locate supermarkets - Resolve permission intent is a followup to Locate supermarkets .

app.intent('Locate supermarkets', conv => {
    conv.ask(new aog.Permission({
        permissions: 'DEVICE_PRECISE_LOCATION',
        context: 'To look for supermarkets near you'
    }));
});

app.intent('Locate supermarkets - Resolve permission', (conv) => {
    if (!!conv.arguments.get('PERMISSION')) {
       // permission granted
    } else {
       // permission NOT granted
    }
});

It's the Locate supermarkets - Resolve permission that declares the actions_intent_PERMISSION event and implements the handler of result

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM