forked from crtr0/twilio-copter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (109 loc) · 2.3 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
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
var Hapi = require('hapi')
, twilio = require('twilio')
, arDrone = require('ar-drone')
, client = arDrone.createClient({ 'ip': '192.168.1.10' });
var options = {
views: {
path: 'views',
engines: {
hjs: 'handlebars'
}
}
};
var server = new Hapi.Server(+process.env.PORT || 8080 , options);
var sms = function(request) {
var resp = new twilio.TwimlResponse();
switch(request.payload.Body.toUpperCase()) {
case 'TAKEOFF':
client.takeoff();
resp.message('Taking Off!');
request.reply(resp.toString());
break;
case 'LAND':
client.land();
resp.message('Landing!');
request.reply(resp.toString());
break;
case 'FLIP':
flip();
resp.message('Flipping!');
request.reply(resp.toString());
break;
default:
resp.message("Sorry, don't understand that command :(");
request.reply(resp.toString());
}
};
var voice = function(request) {
request.reply.view('voice');
};
var option = function(request) {
switch (request.payload.Digits) {
case "*":
client.takeoff();
break;
case "#":
client.land();
break;
case "1":
client.up(0.3);
client.after(300, function() {
this.stop();
});
break;
case "2":
client.front(0.2);
client.after(100, function() {
this.stop();
});
break;
case "4":
client.counterClockwise(0.5);
client.after(100, function() {
this.stop();
});
break;
case "6":
client.clockwise(0.5);
client.after(100, function() {
this.stop();
});
break;
case "7":
client.down(0.3);
client.after(300, function() {
this.stop();
});
break;
case "8":
client.back(0.2);
client.after(100, function() {
this.stop();
});
break;
case "9":
client.up(0.7);
client.after(1000, function() {
this.stop();
this.animate('flipLeft', 300);
});
break;
request.reply.view('option');
}
}
server.route({
method: 'POST',
path: '/sms',
handler: sms
});
server.route({
method: 'POST',
path: '/voice',
handler: voice
});
server.route({
method: 'POST',
path: '/voice/option',
handler: option
});
server.start();