Created
September 6, 2016 20:21
-
-
Save KameronKales/fb3ec1707edf06e7e61a35674b79ff77 to your computer and use it in GitHub Desktop.
app.js
This file contains 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
var express = require('express'); | |
var app = express(); | |
var bodyParser = require('body-parser'); | |
var request = require ('request'); | |
//api.ai pieces | |
const apiai = require("api.ai"); | |
const nlp = new apiai({ | |
token: "2eb7af67459f4d42b70a0593fd05c4c3"}); | |
//to parse json from the messenger client side | |
app.use(bodyParser.json()); | |
//basic get request to see if anything is working | |
app.get('/webhook', function(req, res) { | |
if (req.query['hub.mode'] === 'subscribe' && | |
req.query['hub.verify_token'] === 'kameron') { | |
console.log("Validating webhook"); | |
res.status(200).send(req.query['hub.challenge']); | |
} else { | |
console.error("Failed validation. Make sure the validation tokens match."); | |
res.sendStatus(403); | |
} | |
}); | |
var message = "lol"; | |
nlp.text(message, function (err, response) | |
{ | |
if (err) return console.log(err.stack); //=> Handle error else | |
{ // Your code to respond to message | |
console.log(response.result.fulfillment.speech); | |
//=> Will log something like "Jokes included free of charge." | |
} | |
}); | |
//server set up// | |
app.listen(process.env.PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @KameronKales, just wanted to let you know that this Gist is public and appears to be leaking your
api.ai
token, you may want to revoke it and/or remove this Gist :)