Skip to content

Instantly share code, notes, and snippets.

@apkelly
Last active April 21, 2017 14:54
Show Gist options
  • Save apkelly/037e96defab192e3e2fa7a04e8626c5e to your computer and use it in GitHub Desktop.
Save apkelly/037e96defab192e3e2fa7a04e8626c5e to your computer and use it in GitHub Desktop.
Cloud Function for ChicagoRoboto talk.
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const Assistant = require('actions-on-google').ApiAiAssistant;
exports.myAction = (req, res) => {
const assistant = new Assistant({request: req, response: res});
console.log('Request headers: ' + JSON.stringify(req.headers));
console.log('Request body: ' + JSON.stringify(req.body));
// Fulfill action business logic
function responseHandler (assistant) {
// Complete your fulfillment logic and send a response
assistant.ask('Im sorry to hear that your ' + assistant.getArgument('body-parts') + ' hurts. Does anything else hurt?', ['I didnt hear you', 'What else is causing you pain', 'I guess this concludes our consultation']);
}
const actionMap = new Map();
actionMap.set('describe-symptoms', responseHandler);
assistant.handleRequest(actionMap);
};
@apkelly
Copy link
Author

apkelly commented Apr 21, 2017

Learn more about the ApiAiAssistant class here https://developers.google.com/actions/reference/ApiAiAssistant

The webhook request/response format is described here https://developers.google.com/actions/reference/webhook-format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment