-
Notifications
You must be signed in to change notification settings - Fork 0
/
inbound.js
216 lines (190 loc) · 10.1 KB
/
inbound.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
var Twilio = require('twilio');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var http = require('http');
var httpRequest = require('request');
var bodyParser = require('body-parser');
app.use(bodyParser());
app.post('/', function(request, response) {
var diningHall = request.body.Body;
var resp = new Twilio.TwimlResponse();
response.writeHead(200, {'Content-type': 'text/xml'});
var date = new Date();
var dateString = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
var hour = date.getHours();
switch (diningHall.toLowerCase()) {
case "hill":
httpRequest("http://37440b7e.ngrok.com/hill", function(err, res, body) {
if (!err) {
var meals = JSON.parse(body);
var currentMeal;
//return breakfast, lunch, or dinner based on hour
if (date.getDay() == 0 || date.getDay() == 6) {
if (hour > 10 && hour < 16) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
} else {
if (hour > 0 && hour < 12) {
currentMeal = meals.breakfast;
} else if (hour > 11 && hour < 15) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
}
var resp = new Twilio.TwimlResponse();
resp.message("Hill's menu, " + dateString + "\n" + currentMeal);
console.log(meals.lunch);
response.end(resp.toString());
}
})
break;
case "commons":
httpRequest("http://37440b7e.ngrok.com/commons", function(err, res, body) {
if (!err) {
var meals = JSON.parse(body);
var currentMeal;
//return breakfast, lunch, or dinner based on hour
if (date.getDay() == 0 || date.getDay() == 6) {
if (hour > 10 && hour < 16) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
} else {
if (hour > 0 && hour < 12) {
currentMeal = meals.breakfast;
} else if (hour > 11 && hour < 15) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
}
var resp = new Twilio.TwimlResponse();
resp.message("Commons's menu, " + dateString + "\n" + currentMeal);
response.end(resp.toString());
}
})
break;
case "kc":
httpRequest("http://37440b7e.ngrok.com/kc", function(err, res, body) {
if (!err) {
var meals = JSON.parse(body);
var currentMeal;
//return breakfast, lunch, or dinner based on hour
if (date.getDay() == 0 || date.getDay() == 6) {
if (hour > 10 && hour < 16) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
} else {
if (hour > 0 && hour < 12) {
currentMeal = meals.breakfast;
} else if (hour > 11 && hour < 15) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
}
//if closed
var resp = new Twilio.TwimlResponse();
if (currentMeal == undefined) resp.message("Kings Court is closed today");
else resp.message("Kings Court's menu, " + dateString + "\n" + currentMeal);
if (resp.toString() == "undefined") {
response.end("Closed");
} else {
response.end(resp.toString());
}
}
})
break;
case "kings court":
httpRequest("http://37440b7e.ngrok.com/kc", function(err, res, body) {
if (!err) {
var meals = JSON.parse(body);
var currentMeal;
//return breakfast, lunch, or dinner based on hour
if (date.getDay() == 0 || date.getDay() == 6) {
if (hour > 10 && hour < 16) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
} else {
if (hour > 0 && hour < 12) {
currentMeal = meals.breakfast;
} else if (hour > 11 && hour < 15) {
currentMeal = meals.lunch;
} else {
currentMeal = meals.dinner;
}
}
//if closed
var resp = new Twilio.TwimlResponse();
if (currentMeal == undefined) resp.message("Kings Court is closed today");
else resp.message("Kings Court's menu, " + dateString + "\n" + currentMeal);
if (resp.toString() == "undefined") {
response.end("Closed");
} else {
response.end(resp.toString());
}
}
})
case "hours":
resp.message(diningHoursByDate());
response.end(resp.toString());
break;
default:
resp.message("Invalid! For Menus, reply with \"Hill\", \"Commons\", or \"KC\". For Hours, reply with \"Hours\"");
break;
}
})
app.listen(1337);
console.log('Visit http://localhost:1337/ in your browser to see your TwiML document!');
function diningHoursByDate() {
var n = new Date().getDay();
if(n===0){ //Sunday
return "Today is Sunday. \n \n 1920 COMMONS \n Brunch: 11 am - 3 pm \n Dinner: 5 pm - 8 pm \n \n HILL \n Brunch: " + "11 am - 3 pm" + "\n" + "Dinner: " + "5 pm - 8 pm" + "\n" + "Express: " + "8 pm - 12 am" +
"\n \n" + "KINGS COURT" + "\n" + "Closed on weekends."; //Sunday is good
}
else if(n==1){ //Monday
return "Today is Monday." + "\n \n" +
"1920 COMMONS" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 9 pm" +
"\n \n " + "HILL" + "\n" + "Breakfast: " + "7:30 am - 10 am" + "\n" + "Light Breakfast: " + "10 am - 11 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Light Lunch: " + "2 pm - 5 pm" + "\n" + "Dinner: " + "5 pm - 8 pm" + "\n" + "Express: " + "8 pm - 12 am" +
"\n \n" + "KINGS COURT" + "\n" + "Breakfast: " + "8:30 am - 10:30 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 8 pm"; //Mon - Thurs good
}
else if (n==2){ //Tuesday
return "Today is Tuesday." + "\n \n" +
"1920 COMMONS" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 9 pm" +
"\n \n" + "HILL" + "\n" + "Breakfast: " + "7:30 am - 10 am" + "\n" + "Light Breakfast: " + "10 am - 11 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Light Lunch: " + "2 pm - 5 pm" + "\n" + "Dinner: " + "5 pm - 8 pm" + "\n" + "Express: " + "8 pm - 12 am" +
"\n \n" + "KINGS COURT" + "\n" + "Breakfast: " + "8:30 am - 10:30 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 8 pm"; //Mon - Thurs good
}
else if (n==3){ //Wednesday
return "Today is Wednesday." + "\n \n" +
"1920 COMMONS" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 9 pm" +
"\n \n" + "HILL" + "\n" + "Breakfast: " + "7:30 am - 10 am" + "\n" + "Light Breakfast: " + "10 am - 11 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Light Lunch: " + "2 pm - 5 pm" + "\n" + "Dinner: " + "5 pm - 8 pm" + "\n" + "Express: " + "8 pm - 12 am" +
"\n \n" + "KINGS COURT" + "\n" + "Breakfast: " + "8:30 am - 10:30 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 8 pm"; //Mon - Thurs good
}
else if (n==4){ //Thursday
return "Today is Thursday." + "\n \n" +
"1920 COMMONS" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 9 pm" +
"\n \n" + "HILL" + "\n" + "Breakfast: " + "7:30 am - 10 am" + "\n" + "Light Breakfast: " + "10 am - 11 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Light Lunch: " + "2 pm - 5 pm" + "\n" + "Dinner: " + "5 pm - 8 pm" + "\n" + "Express: " + "8 pm - 12 am" +
"\n \n" + "KINGS COURT" + "\n" + "Breakfast: " + "8:30 am - 10:30 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 8 pm"; //Mon - Thurs good
}
else if(n==5){ //Friday
return "Today is Friday." + "\n \n" +
"1920 COMMONS" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 7:30 pm" +
"\n \n" + "HILL" + "\n" + "Breakfast: " + "7:30 am - 10 am" + "\n" + "Light Breakfast: " + "10 am - 11 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Light Lunch: " + "2 pm - 5 pm" + "\n" + "Dinner: " + "5 pm - 7 pm" +
"\n \n" + "KINGS COURT" + "\n" + "Breakfast: " + "8:30 am - 10:30 am" + "\n" + "Lunch: " + "11 am - 2 pm" + "\n" + "Dinner: " + "5 pm - 8 pm"; //Mon - Thurs good
}
else{ //Saturday
return "Today is Saturday." + "\n \n" +
"1920 COMMONS" + "\n" + "Brunch: " + "11 am - 3 pm" + "\n" + "Dinner: " + "5 pm - 7 pm" +
"\n \n" + "HILL" + "\n" + "Brunch: " + "11 am - 3 pm" + "\n" + "Dinner: " + "5 pm - 7 pm" +
"\n \n" + "KINGS COURT" + "\n" + "Closed on weekends."; //Saturday good
}
}