-
Notifications
You must be signed in to change notification settings - Fork 16
/
LineMockServer.js
154 lines (145 loc) · 5.01 KB
/
LineMockServer.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.get('/', function(req, res){
res.send('Hello world');
});
app.post('/message/reply',function(req, res){
console.log('>>>>>> RETRIEVED OBJECT FROM BOT SERVER <<<<<<');
showTime();
console.dir(req.body);
console.log('>>>>>> -------------------------------- <<<<<<');
res.json(req.body);
});
app.post('/message/push', function(req, res){
console.log('>>>>>> RETRIEVED OBJECT FROM BOT SERVER <<<<<<');
showTime();
console.dir(req.body);
console.log('>>>>>> -------------------------------- <<<<<<');
res.json(req.body);
});
app.get('/profile/:userId', function(req, res){
var users = {
'member_1':{
'displayName': 'Spongebob',
'userId': 'member_1',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_2':{
'displayName': 'Patrick Star',
'userId': 'member_2',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_3':{
'displayName': 'Sandy Squirrel',
'userId': 'member_3',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_4':{
'displayName': 'Mr. Crab',
'userId': 'member_4',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_5':{
'displayName': 'Plankton',
'userId': 'member_5',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_6':{
'displayName': 'Larry Lobster',
'userId': 'member_6',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_7':{
'displayName': 'SquidWard Tentacle',
'userId': 'member_7',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_8':{
'displayName': 'Mrs Puff',
'userId': 'member_8',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_9':{
'displayName': 'Gary the snails',
'userId': 'member_9',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_10':{
'displayName': 'Squilliam',
'userId': 'member_10',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_11':{
'displayName': 'Pearl',
'userId': 'member_11',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_12':{
'displayName': 'Flying dutchman',
'userId': 'member_12',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_13':{
'displayName': 'Neptunus',
'userId': 'member_13',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_14':{
'displayName': 'Karen robot',
'userId': 'member_14',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_15':{
'displayName': 'Mermaid man',
'userId': 'member_15',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
'member_16':{
'displayName': 'Barnacle boys',
'userId': 'member_16',
'pictureUrl': 'http://placeholder.it/256x256',
'statusMessage': 'exampleStatusMessage',
},
};
var selectedUser = users[req.params.userId];
showTime();
console.log("Returning profile for userId = "+req.params.userId);
console.dir(selectedUser);
res.json(selectedUser);
});
app.post('*', function(req, res){
console.log('>>>>>> RETRIEVED OBJECT FROM BOT SERVER <<<<<<');
showTime();
console.dir(req.body);
console.log('>>>>>> -------------------------------- <<<<<<');
res.json(req.body);
});
app.listen(8000, function(){
console.log("listening on port 8000");
});
function showTime(){
var options = {
timeZone: 'Asia/Jakarta',
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
},
formatter = new Intl.DateTimeFormat([], options);
console.log(formatter.format(new Date()));
}