It sounds like in your current implementation, you have a flow like this:
- User says "Book a tee time nearby".
get_location
intent is matched.
- In the webhook for
get_location
, you check if the user has previously granted permission with isPermissionGranted()
.
- If they have previously granted, you move forward with looking up their local course.
- If they have not previously granted, you call
ask
from the webhook to ask the user's permission to ask them for permission to get their location.
- If they say "yes", the
request-permission
intent is matched.
- In the webhook for
request-permission
, you call askForPermission()
and the Assistant asks the user for permission to get their location.
- You now move forward with looking up their local course.
In this case, the dialog will be as follows:
User: Book a tee time nearby
App: Can I ask permission to get your location?
User: Yes
App: [from Assistant] Can I access your location?
User: Yes
App: Thanks, your local course is Pebble Beach and I booked you a tee time.
You're trying to avoid the process starting in step 4, where you ask the user's permission to ask them for permission to get their location.
In order to do this, you can implement the following flow:
- User says "Book a tee time nearby".
get_location
intent is matched.
- In the webhook for
get_location
, you check if the user has previously granted permission with isPermissionGranted()
.
- If they have previously granted, you move forward with looking up their local course.
- If they have not previously granted, you should call
askForPermission()
, still in the webhook for get_location
. The Assistant will ask the user for permission to get their location.
- To handle the response from the permission request, you need to create a new intent and add to it an event named
actions_intent_PERMISSION
(see the docs for reference). This event will cause the intent to be triggered when the user has granted location permission.
- Build a webhook for this new intent that, in its webhook, confirms the permission with
isPermissionGranted()
and then moves forward with looking up their local course.
Now, the dialog will be as follows:
User: Book a tee time nearby
App: [from Assistant] Can I access your location?
User: Yes
App: Thanks, your local course is Pebble Beach and I booked you a tee time.