3

I was successfully able to request user location with help of action-on-google nodejs library, but I am more of java guy, and I need to do this in java.

https://developers.google.com/actions/assistant/helpers#json

How can I request the user's location in API.ai?

Requesting User Location from Google Actions with Api.ai

From above links, I find out that it is possible with just json reponses.

I've created my poc app in api.ai, which returns below json reponses

1

{
    "conversationToken": {
        "state": null,
        "data": {}
    },
    "expectUserResponse": true,
    "expectedInputs": [
        {
            "inputPrompt": {
                "initialPrompts": [
                    {
                        "textToSpeech": "PLACEHOLDER_FOR_PERMISSION"
                    }
                ],
                "noInputPrompts": null
            },
            "possibleIntents": [
                {
                    "intent": "actions.intent.PERMISSION",
                    "inputValueData": {
                        "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
                        "optContext": "Requesting Location.",
                        "permissions": [
                            "DEVICE_COARSE_LOCATION"
                        ]
                    }
                }
            ]
        }
    ]
}

This returns : Unparseable Json Response

2

{
    "contextOut": [
        {
            "lifespan": 100,
            "name": "_actions_on_google_",
            "parameters": null
        },
        {
            "lifespan": 5,
            "name": "requesting_permission",
            "parameters": null
        }
    ],
    "data": {
        "google": {
            "expect_user_response": true,
            "is_ssml": false,
            "no_input_prompts": null,
            "permissions_request": {
                "opt_context": "Requesting Location.",
                "permissions": [
                    "DEVICE_COARSE_LOCATION"
                ]
            }
        }
    },
    "speech": "PLACEHOLDER_FOR_PERMISSION"
}

This return : PLACEHOLDER TEXT

I wanted to know that way I am doing it is possible or not. If yes, what I am doing wrong ?

Please help.

Sukh
  • 670
  • 5
  • 12
  • Now there is an unofficial Java/Kotlin SDK. It has all the features of the nodejs and very similar api. I maintain the project and will be updating docs and readme soon, but it is ready for use and is on maven central. https://github.com/TicketmasterMobileStudio/actions-on-google-kotlin – Patrick Jackson Aug 15 '17 at 12:47
  • @Patrick thanks, I will take a look – Sukh Aug 15 '17 at 13:31

1 Answers1

1

For starters - yes, this is possible. You can use JSON to request the permission. All the node.js libraries do is help format the JSON.

Most of this looks correct, but I think there are two different types of errors here.

The first is that I suspect there are a few fields that are causing problems at API.AI/Google in your first example. The two fields that are null, conversationToken.state and expectedInputs.inputPrompt.noInputPrompts, are likely causing problems. The state field should just be a string (any string is fine) and the noInputPrompts should be an empty array.

Furthermore, you indicate that you're using API.AI, which requires additional information to be sent back and most of what you've indicated to be in a data.google section (which you have in your second example, but not your first). See https://api.ai/docs/fulfillment#response for the base layout of an API.AI response and https://developers.google.com/actions/apiai/webhook#response for the additional fields used by the Google Assistant.

Here is some output that I generated that works:


{
    "speech": "PLACEHOLDER_FOR_PERMISSION",
    "contextOut": [
        {
            "name": "_actions_on_google_",
            "lifespan": 100,
            "parameters": {}
        }
    ],
    "data": {
        "google": {
            "expectUserResponse": true,
            "isSsml": false,
            "noInputPrompts": [],
            "systemIntent": {
                "intent": "actions.intent.PERMISSION",
                "data": {
                    "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
                    "optContext": "To pick you up",
                    "permissions": [
                        "NAME",
                        "DEVICE_PRECISE_LOCATION"
                    ]
                }
            }
        }
    }
}

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • thank you so much for your help. It work as I wanted. :) – Sukh Aug 09 '17 at 03:15
  • Hi @Prisoner, I have a question : Once we get user name and location permission, is there any way we can store the permission for that session only and whenever it's required, I just get it, is it possible ? – Sukh Aug 09 '17 at 20:02
  • For additional/different questions, it is best if you ask another SO question rather than try to use comments to followup. In this case, however, it has already been asked and answered: https://stackoverflow.com/questions/45044623/google-assistant-location-permissions-not-stored-between-requests If that answers your question, upvote the question and answer. If not - ask a new question with as much info as you can. – Prisoner Aug 09 '17 at 20:17