I am developing a Google Assistant Action and want to create an event that can automatically launch an intent that I had. The problem is I cannot seem to find any good documentation on how to actually define an event so this way it launches an intent without having to communicate with the user in between.
To give you example.. I attached images of the intents I am trying to use. I want to have the user prompt get_location
intent with an utterance. From this my code checks if we have permissions already, and if we do not I want the intent request-permission
to be launched through an event. How do I set up the event in order for this to be done?
This is the conversation/work flow that I am looking for:
- User Says: 'Book a tee time near me'
- That launches my get_location intent
- get_location intent checks to see if permission was granted with isPermissionGranted()
- it realizes there is no permission granted
- launches request-permission intent
- prompt the user for permission
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 withisPermissionGranted()
.
- 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 callaskForPermission()
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 withisPermissionGranted()
.
- 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 forget_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.