Skip to content

Instantly share code, notes, and snippets.

@Danetag
Last active April 29, 2017 03:00
Show Gist options
  • Select an option

  • Save Danetag/0ed9685d245807b189a8d79e931ac8a0 to your computer and use it in GitHub Desktop.

Select an option

Save Danetag/0ed9685d245807b189a8d79e931ac8a0 to your computer and use it in GitHub Desktop.
Actions on Google - App setup
'use strict';
// enable debugging if desired
process.env.DEBUG = 'actions-on-google:*';
// SDK
const Assistant = require('actions-on-google').ApiAiAssistant;
// Express App
const app = express();
app.use(bodyParser.json({type: 'application/json'}));
app.use(express.static('./'));
// Constants
const INTENTS = require('./constants/intents');
const ANSWERS = require('./constants/answers');
// Welcome Action
const welcome = function(assistant) {
assistant.ask(ANSWERS.WELCOME);
}
app.post('/', function (req, res) {
const assistant = new Assistant({request: req, response: res});
const actionMap = new Map();
// Actions
actionMap.set(assistant.StandardIntents.MAIN, welcome);
actionMap.set(INTENTS.INPUT_WELCOME, welcome);
assistant.handleRequest(actionMap);
});
if (module === require.main) {
// Start the server
const server = app.listen(process.env.PORT || 8080, function () {
const port = server.address().port;
console.log('App listening on port %s', port);
});
}
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment