How to request permission in actions in Google without SDK?

I would like to know the username, however I cannot use nodejs sdk since I use a different language.

How can I ask permission?

I would prefer a method with normal json answers.

+4
source share
3 answers

I hacked this minimum script to get the JSON response returned by nodejs sdk:

gaction.js

const DialogflowApp = require('actions-on-google').DialogflowApp;

const app = new DialogflowApp({
    request: {
        body: {
            result: {
                action: 'Test',
                contexts: []
            }
        },
        get: (h) => h
    },
    response: {
        append: (h, v) => console.log(`${h}: ${v}`),
        status: (code) => {
            return {send: (resp) => console.log(JSON.stringify(resp, null, 2))}
        }
    }
});
function testCode(app) {
    app.askForPermission('To locate you', app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
}
app.handleRequest(new Map().set('Test', testCode));

I'm still not an expert on node.js, so this may not be the optimal solution. When you installed node and run the command npm install actions-on-google, it will install the necessary dependencies.
Upon completion, you just need to run node gaction, which will create this output:

Google-Assistant-API-Version: Google-Assistant-API-Version
Content-Type: application/json
{
  "speech": "PLACEHOLDER_FOR_PERMISSION",
  "contextOut": [
    {
      "name": "_actions_on_google_",
      "lifespan": 100,
      "parameters": {}
    }
  ],
  "data": {
    "google": {
      "expect_user_response": true,
      "no_input_prompts": [],
      "is_ssml": false,
      "system_intent": {
        "intent": "assistant.intent.action.PERMISSION",
        "spec": {
          "permission_value_spec": {
            "opt_context": "To locate you",
            "permissions": [
              "DEVICE_PRECISE_LOCATION"
            ]
          }
        }
      }
    }
  }
}

JSON , Google . !

it works

+5

JSON-/ - API.AI Actions https://developers.google.com/actions/apiai/webhook

, data.google.permissions_request :

  • opt_context , , , .

  • permissions - , , .

    • NAME
    • DEVICE_COARSE_LOCATION
    • DEVICE_PRECISE_LOCATION
0

Source: https://habr.com/ru/post/1665445/


All Articles