6

I want to write an app that will relay information about public transport via the Google Assistant if prompted.

Does the Google Assistant SDK allow an app to send text to be read out?

1 Answer 1

3

Yes, the Google Assistant supports Actions which allow developers to respond to requests from users. Actions can only respond if prompted, they cannot speak unannounced at this time.

Using the Actions SDK, you must first define some actions:

{
  "actions": [
    {
      "name": "MAIN",
      "intent": {
        "name": "actions.intent.MAIN"
      },
      "fulfillment": {
        "conversationName": "demoApp"
      }
    }
  ],
  "conversations": {
    "demoApp": {
      "name": "demoApp",
      "url": "https://example.com/demoApp"
    }
  }
}

This would use the fulfillment demoApp to respond to the command 'Ok Google, talk to [action name]'. This essentially amounts to a request to the specified URL.

You then need to write some server code to handle these requests. Google provide a library for Node.js which might be helpful. I'm just going to quote the example code there as it's sufficiently clear and helpful to point you in the right direction.

'use strict';

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

exports.<insertCloudFunctionName> = (req, res) => {
  const app = new ActionsSdkApp({request: req, response: res});

  function mainIntent (app) {
    // Put your message here, using app.tell.
    app.tell('Hello, world!');
  }

  let actionMap = new Map();
  actionMap.set(app.StandardIntents.MAIN, mainIntent);
  app.handleRequest(actionMap);
}

You then just need to deploy and submit your app. You would need to put your logic to determine what text to say inside of mainIntent, or create new intents as necessary.

2
  • "they cannot speak unannounced at this time" Could you use the "broadcast" command? Nov 30, 2017 at 16:59
  • @firedude144 Not really — the way that Actions are currently used makes this impossible. Your action can only communicate with the Google Assistant if Google's servers make a request to your action, and they'll only do that if asked to do so by voice command. I wouldn't be surprised if this comes in future, but it won't work yet.
    – Aurora0001
    Nov 30, 2017 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.