Created
April 16, 2019 12:25
-
-
Save howethomas/76266e4238a409df72b010eba1f4d678 to your computer and use it in GitHub Desktop.
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
const express = require('express') | |
const app = express() | |
var bodyParser = require('body-parser') | |
const port = 5000 | |
// parse application/x-www-form-urlencoded | |
app.use(bodyParser.urlencoded({ extended: false })) | |
// parse application/json | |
app.use(bodyParser.json()) | |
app.post('/webhook', function(request, response){ | |
console.log(request.body); // your JSON | |
if (request.body.msg.direction == 'egress') { | |
console.log("We aren't reacting to outbound messages") | |
response.send({}); // echo the result back | |
return; | |
} | |
if (request.body.msg.txt.trim() == "end") { | |
r = { | |
commands: { | |
end_session: true | |
} | |
} | |
response.send(r); // echo the result back | |
return; | |
} | |
if (request.body.msg.txt.trim() == "transfer") { | |
r = { | |
commands: { | |
transfer: "support" | |
} | |
} | |
response.send(r); // echo the result back | |
return; | |
} | |
if (request.body.msg.txt.trim() == "notify") { | |
r = { | |
commands: { | |
notify: "notify called" | |
} | |
} | |
response.send(r); // echo the result back | |
return; | |
} | |
r = { | |
messages: [ | |
{ | |
txt: "This is a message. Wooo." | |
}, | |
{ | |
txt: "This is another message. Whoa." | |
} | |
], | |
whispers: [ | |
{ | |
txt: "Hey we are whispering http://www.cnn.com/" | |
}, | |
{ | |
txt: "Hey we are whispering http://www.foxnews.com/" | |
} | |
], | |
customerTags: [ | |
"notReal:VeryNotReal", | |
"notRealer:VeryNotRealer" | |
], | |
agentTags: [ | |
"notAtAllReal:VeryNotAtAllReal", | |
"imaginary:friend" | |
], | |
metaData: { | |
hasInterest: true, | |
sentimentScore: 7, | |
locationCode: "02668", | |
} | |
} | |
response.send(r); // echo the result back | |
}); | |
app.get('/', (req, res) => res.send('Hello World!')) | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment