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?
Internet of Things Stack Exchange is a question and answer site for builders and users of networked sensors and control devices in the contexts of smart homes, industry automation, or environmental sensors. It only takes a minute to sign up.
Sign up to join this communityYes, 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.