-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (47 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var express = require('express'); // Express
var bodyParser = require("body-parser"); // Parse request body
// Application Port (Default = 8080)
const PORT = process.env.PORT || 8080;
// Initialize express with body parser middleware
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Method to handle a request on /
app.get('/', function (req, res) {
res.send('Nothing to see here.');
});
// Method to handle a post request from Manychat
app.post('/manychat', function (req, res) {
// Get subscriber data from request body
var manychat = req.body;
console.log(manychat);
/*
* MANYCHAT FIELDS:
*
* id
* key
* page_id
* status
* first_name
* last_name
* name
* gender
* profile_pic
* locale
* language
* timezone
*/
// Provide a JSON response back to Manychat
res.json({
version: "v2",
content: {
messages:[
{ type: "text", text: "Hello world."},
]}
});
});
// Begin Application
app.listen(PORT, function() {
console.log('Application listening on port ' + PORT);
});