Requesting User Location from Google Actions with Api.ai

感情迁移 提交于 2019-12-05 02:59:35

问题


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.


回答1:


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"
}



回答2:


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



来源:https://stackoverflow.com/questions/42043499/requesting-user-location-from-google-actions-with-api-ai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!