Search code examples
actions-on-googleapi-ai

Launching an Intent with an Event with API.AI in a Google Action


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

Here is how my intents are setup: enter image description here

enter image description here


Solution

  • It sounds like in your current implementation, you have a flow like this:

    1. User says "Book a tee time nearby".
    2. get_location intent is matched.
    3. 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.
    4. 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.
    5. If they say "yes", the request-permission intent is matched.
    6. In the webhook for request-permission, you call askForPermission() and the Assistant asks the user for permission to get their location.
    7. 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:

    1. User says "Book a tee time nearby".
    2. get_location intent is matched.
    3. 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.
    4. 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.
    5. 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.
    6. 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.