Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask permission in Actions on Google without the SDK?

I would like to know the name of the user, however I cannot use the nodejs sdk since I use another language.

How can I ask for permission?

I would prefer a way with the normal json responses.

like image 631
rekire Avatar asked Jan 01 '17 09:01

rekire


1 Answers

I hacked this minimal script to get the JSON reponse which the nodejs sdk would return:

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 no node.js expert so this might be not an optimal solution. When you have installed node and run the command npm install actions-on-google, this will install the necessary dependencies.
When done 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"
            ]
          }
        }
      }
    }
  }
}

If you send now the JSON above you will be asked from Google Home. Have fun!

it works

like image 164
rekire Avatar answered Sep 19 '22 17:09

rekire