• You only handle the fulfillment • Not yet widely available to build “Ok Google, Play Charlie Brown Movie on Chromecast using DStv Now.” Conversation Actions • Two-way dialog with users • Your action manages the conversation • Can be built and deployed today. “Ok Google, Let me talk to Spelling Master” Types of Actions
can I assist you today? When is the next Liverpool Game on? The next match is on Thursday at 12. Would you like me to set a reminder? Ok Google, let me talk to DStv!
Intent - a mapping between what a user says and what action should be taken • Entities - concepts that are often specific to a domain as a way of mapping natural language phrases. • Actions - the steps your application will take when specific intents are triggered by user inputs • Contexts -current context of the user expression. This is useful for differentiating phrases which might be vague and have different meaning depending on what was spoken previously. Source: https://docs.api.ai/docs/key-concepts
express = require('express'); let bodyParser = require('body-parser'); let app = express(); app.use(bodyParser.json({type: 'application/json'})); Template Code defined in app.js file app.post('/', function (req, res) { const assistant = new Assistant({request: req, response: res}); // Fulfill action business logic … }); if (module === require.main) { // Start the server let server = app.listen(process.env.PORT || 8080, function () { let port = server.address().port; console.log('App listening on port %s', port); }); } module.exports = app;
require(‘moment'); const QUERY_CONTENT_ACTION = 'query_content'; const ARGUMENT_PROGRAM_NAME = 'program_name'; app.post('/', function (req, res) { const assistant = new Assistant({request: req, response: res}); function getNextAiringOfProgram(assistant){ let showName = assistant.getArgument(ARGUMENT_PROGRAM_NAME); request(‘https://gook.com;searchTerm='+ showName, function (error, response, body) { }) } if (!error && response.statusCode == 200) { var event = JSON.parse(body); var dateTimeFormatted = new moment(event.startDateTime); assistant.tell(event.title + ' will air on ' + dateTimeFormatted.format('dddd Do [at] hh:mm a')); } else { assistant.tell('I\'m sorry, there was an error trying to process your request.’); let actionMap = new Map(); actionMap.set(QUERY_CONTENT_ACTION, getNextAiringOfProgram); assistant.handleRequest(actionMap);
Run the node server locally from folder 3. Deploy to Google Cloud 4. Set web hook fulfilment URL $ npm install $ npm start $ gcloud init $ gcloud app deploy
• No option to configure this. • Be aware - the timezone you are receiving on the server is not the timezone of the client. • Solution: Request users device location and determine timezone from there