Last active
April 29, 2017 03:00
-
-
Save Danetag/0ed9685d245807b189a8d79e931ac8a0 to your computer and use it in GitHub Desktop.
Actions on Google - App setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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