Request user location without nodejs library

I was able to query the user's location using the action-on-google nodejs library, but I am more of a java guy and I need to do it in java.

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

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

Requesting user location from Google Actions with Api.ai

From the links above, I learn that this is possible with only json reponses.

I 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: Unspeakable 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 is the comeback: TEXT PLACEHOLDER

I wanted to know if I am making it possible or not. If so, what am I doing wrong?

Please, help.

+3


source to share


1 answer


To begin with, yes, it is possible. You can use JSON to request permission. All node.js libraries are JSON formatting help.

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

First, I suspect there are several fields that are causing problems in API.AI/Google in the first example. Two fields that are null conversationToken.state

and expectedInputs.inputPrompt.noInputPrompts

are probably causing problems. The field state

must be just a string (any string is ok) and noInputPrompts

must be an empty array.



Also, you indicate that you are using API.AI, which requires more information to send back, and most of the directions you provided are in the section data.google

(which you have in the second example, but not your first). See https://api.ai/docs/fulfillment#response for basic API.AI response layout and https://developers.google.com/actions/apiai/webhook#response for additional fields used by Google Helper.

Here's the output 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"
                    ]
                }
            }
        }
    }
}


      

+1


source







All Articles