Patrick Jackson
Patrick Jackson

Reputation: 19436

Requesting User Location from Google Actions with Api.ai

Google Actions can provide you with the user's location, name, and few other details. How can this be done on Api.ai without the nodejs SDK? All examples from Google are using the Nodejs sdk.

According to the Conversation Api it is just a matter of putting the correct json in the response, however it is unclear how to get Api.ai to fill in this json.

I've read the docs here , but am still unclear.

Sample code, or more detailed documentations, would be great for the non nodejs developers. I'm working in Java, however a good explanation of how Api.ai builts the response json for Google Actions would be helpful for developers of all languages.

Upvotes: 3

Views: 1004

Answers (2)

Patrick Jackson
Patrick Jackson

Reputation: 19436

There is now another option for Java programmers working with Actions on Google. There is an open source port of the official SDK to Java/Kotlin. API is very similar, so for location it would be something like:

app.askForLocation()

https://github.com/TicketmasterMobileStudio/actions-on-google-kotlin

Upvotes: 0

Bela Vizy
Bela Vizy

Reputation: 1164

You have to study the API.AI HTTP API here. As a reference, try to setup the node examples - this way you can see the JSON files in action.

For the permissions try the Name Psychic example.

Your outgoing JSON will be something like this:

{
  "contextOut": [
    {
      "lifespan": 100, 
      "name": "_actions_on_google_", 
      "parameters": {}
    }, 
    {
      "lifespan": 1, 
      "name": "requesting_permission", 
      "parameters": {}
    }
  ], 
  "data": {
    "google": {
      "expect_user_response": true, 
      "is_ssml": false, 
      "no_input_prompts": [], 
      "permissions_request": {
        "opt_context": "To send you something", 
        "permissions": [
          "DEVICE_PRECISE_LOCATION"
        ]
      }
    }
  }, 
  "speech": "PLACEHOLDER_FOR_PERMISSION"
}

Upvotes: 1

Related Questions