This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotline.php
363 lines (288 loc) · 10.3 KB
/
hotline.php
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php
/**
* Holiday Hotline Class
*/
class Holiday_Hotline {
/**
* Options
* @var array
*/
var $options;
/**
* Response
* @var object
*/
var $response;
function __construct() {
// Include Vendor classes
try {
require('./vendor/autoload.php');
} catch (Exception $e) {
echo 'You must install vendor dependencies with "composer install"';
}
// Set options for voice
$this->options = array(
'baseHost' => 'http://' . $_SERVER['HTTP_HOST'],
'baseUrl' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?',
'voice' => 'woman',
'language' => 'en-gb'
);
// Set our response headers
header('Content-Type: application/xml; charset=utf-8');
// Initialize our response TWIML object
$this->response = new Services_Twilio_Twiml;
// Process the input
$digits = isset( $_REQUEST['Digits'] ) ? (int)$_REQUEST['Digits'] : null;
$action = isset( $_GET['action'] ) ? $_GET['action'] : null;
$this->process_input( $action, $digits );
}
/**
* Call a gather statement with the passed options
* @param array $options Options for the Gather statement
* @return object Response object
*/
public function _gather( $options, $message ) {
$this->response->gather( $options )
->say( $message, array(
'voice' => $this->options['voice'],
'language' => $this->options['language']
));
return $this->response;
}
/**
* Say message with defaults
* @param string $message Message to say
* @return object Modified TWIML object
*/
public function _say( $message ) {
$this->response->say(
$message,
array(
'voice' => $this->options['voice'],
'language' => $this->options['language']
)
);
return $this->response;
}
/**
* Print out information about Happy Medium
* @return object Response
*/
public function about() {
$this->_say("
Happy Medium is a full-service interactive agency in Des Moines, Iowa, offering
advertising, social media management, media buying, website development,
search engine optimization, and graphic design services.
Happy Medium's offerings aren't limited to a physical location,
which allows the ambitious interactive agency to serve clients of
various sizes and locations.
Learn more by visiting It's A Happy Medium dot Com
or by calling 5 1 5, 2 1 8, 14 77.
");
$this->main_menu();
return $this->response;
}
/**
* Print out a baking menu
* @return object Response
*/
public function baking_menu() {
$this->_gather(array(
'action' => $this->options['baseUrl'] . http_build_query( array(
'action' => 'baking_menu'
)),
'numDigits' => 1,
'finishOnKey' => ''
), "
Press 1 for Turkey.
Press 2 for Ham.
Press 3 for Duck.
Press 9 to return to the main menu.
Press 0 to repeat the options.
");
return $this->response;
}
/**
* Print out baking tips
* @param string $food Food type
* @return object Response
*/
public function baking_tips( $food ) {
switch ( $food ) {
case 'turkey':
$this->_say("
Tips for cooking turkey:
Thawing a frozen turkey requires patience.
The safest method is to thaw turkey in the refrigerator.
Cooking times will differ depending on whether your bird was purchased fresh or frozen.
Remember to carve your turkey with a very sharp or electric knife.
");
break;
case 'ham':
$this->_say("
Tips for cooking ham:
Almost all hams have either been partially or fully cooked before they are packaged.
A partially cooked ham has been brought to an internal temperature
of 137 degrees fahrenheit, which kills any bacteria.
A fully cooked ham will require about 10 minutes per pound in
order to be heated all the way through.
");
break;
case 'duck':
$this->_say("
Tips for cooking duck:
By properly cooking duck, you can eliminate up to 70% of the fat,
which leaves a delicious, crisp skin.
Confit duck comes from an old method of preserving meat by seasoning
it and slowly cooking it in its own fat. The cooked meat was then packed
into a crock and covered with its cooking fat which acted as a seal and
preservative. This method produces a particularly tender meat.
");
break;
default:
$this->baking_menu();
break;
}
// Return to the baking menu afterward
$this->baking_menu();
return $this->response;
}
/**
* Speak and gather the main menu
* @return object Response
*/
public function main_menu() {
$this->_gather(array(
'action' => $this->options['baseUrl'] . http_build_query( array(
'action' => 'main_menu'
)),
'numDigits' => 1,
'finishOnKey' => ''
), "
Press 1 for a holiday carol sung by Happy Medium team members.
Press 2 for a holiday baking tip.
Press 3 for winter travel tips.
Press 4 to learn more about Happy Medium.
Press 0 to repeat the options.
");
return $this->response;
}
/**
* Play a holiday carol
* @return object Response
*/
public function play_carol() {
$this->response->play( $this->options['baseHost'] . '/assets/let_it_snow.mp3' );
$this->main_menu();
return $this->response;
}
/**
* Process the input passed to the hotline
* @param string $action Action (optional)
* @param int $digits Digits (optional)
* @return this Self
*/
public function process_input( $action, $digits ) {
if ( ! empty($action) ) {
// Do something
switch ( $action ) {
/**
* Someone chose an option from the main menu
*/
case 'main_menu':
if ( ! is_int($digits) ) {
$this->main_menu();
return;
}
switch ( $digits ) {
case 1:
$this->play_carol();
break;
case 2:
$this->baking_menu();
break;
case 3:
$this->winter_travel_tips();
break;
case 4:
$this->about();
break;
case 0:
$this->main_menu();
break;
default:
$this->main_menu();
break;
}
break;
/**
* Someone chose an option from the baking menu
*/
case 'baking_menu':
if ( ! is_int($digits) ) {
$this->main_menu();
return;
}
switch ( $digits ) {
case 1:
$this->baking_tips('turkey');
break;
case 2:
$this->baking_tips('ham');
break;
case 3:
$this->baking_tips('duck');
break;
case 9:
$this->main_menu();
break;
case 0:
$this->baking_menu();
break;
default:
$this->baking_menu();
break;
}
default:
$this->main_menu();
break;
}
} else {
// If no action or digits, do welcome
$this->welcome();
}
// Print once
print $this->response;
return $this;
}
/**
* Say a welcome message
* @return object Response
*/
public function welcome() {
$this->_say("Welcome to the Happy Medium Holiday Hotline, spreading Christmas cheer since 2014.");
// Automatically start the main menu, which prints the response
$this->main_menu();
return $this->response;
}
/**
* Print out winter travel tips
* @return object Response
*/
public function winter_travel_tips() {
$this->_say("
Winter driving trips:
Avoid driving while you’re fatigued. Getting the proper amount of rest
before taking on winter weather tasks reduces driving risks.
Never warm up a vehicle in an enclosed area, such as a garage.
Make certain your tires are properly inflated.
Never mix radial tires with other tire types.
Keep your gas tank at least half full to avoid gas line freeze-up.
If possible, avoid using your parking brake in cold, rainy and snowy weather.
");
$this->main_menu();
return $this->response;
}
}
// Execute
new Holiday_Hotline();