Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 170 lines (118 sloc) 4.687 kB
9ecac9a @kyleconroy Major updates
kyleconroy authored
1 import webapp2
2 import util
3 from twilio import twiml
4 from twilio import rest
5
6 NUMBER = ""
7
8 # Change this to a sub account
9 ACCOUNT_SID = ""
10 AUTH_TOKEN = ""
11 APP_SID = ""
12
13 client = rest.TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
14
15 class BossHandler(webapp2.RequestHandler):
16
17 def get(self):
18 """Enqueue a caller into the entry queue"""
19 self.response.headers['Content-Type'] = 'application/xml'
20
21 resp = twiml.Response()
22 d = resp.dial()
23 d.conference("boss")
24
25 self.response.write(str(resp))
26
27
28 class WaitHandler(webapp2.RequestHandler):
29
30 def get(self):
31 """Tell a caller information about how long they have waited"""
32 self.response.headers['Content-Type'] = 'application/xml'
33
34 resp = twiml.Response()
35
36 messages = [
37 "You are number %s in line." % self.request.get('QueuePosition'),
38 "You've been in line for %s seconds." % self.request.get('QueueTime'),
04079d4 Update callcenter.py to use correct parameter name
Kevin Burke authored
39 "Average wait time is %s seconds." % self.request.get('AvgQueueTime'),
9ecac9a @kyleconroy Major updates
kyleconroy authored
40 ]
41
42 for message in messages:
43 resp.say(message)
44
45 resp.play("http://com.twilio.music.rock.s3.amazonaws.com/nickleus_-_"
46 "original_guitar_song_200907251723.mp3")
47
48 self.response.out.write(str(resp))
49
50
51 class EnqueueHandler(webapp2.RequestHandler):
52
53 def get(self):
54 """Enqueue a caller into the entry queue"""
55 self.response.headers['Content-Type'] = 'application/xml'
56
57 resp = twiml.Response()
58 resp.say("You are being enqueued now.")
03587f1 @kyleconroy Update Call In to use different content
kyleconroy authored
59 resp.enqueue('radio-callin-queue')
9ecac9a @kyleconroy Major updates
kyleconroy authored
60 self.response.write(str(resp))
61
62
63 class DequeueHandler(webapp2.RequestHandler):
64
65 def get(self):
66 """Enqueue a caller into the entry queue"""
67 self.response.headers['Content-Type'] = 'application/xml'
68
69 resp = twiml.Response()
70 resp.say("Looking for a caller")
71 d = resp.dial(record=True)
72 d.queue(self.request.params.get('queue', 'support'),
73 url="/twiml/record-consent")
74 resp.pause(length=10)
75 resp.redirect()
76 self.response.write(str(resp))
77
78
79 class ConsentHandler(webapp2.RequestHandler):
80
81 def get(self):
82 """Inform the caller that the call may be recorded"""
83 self.response.headers['Content-Type'] = 'application/xml'
84
85 resp = twiml.Response()
86 resp.say("This call may be recorded for quality purposes")
87
88 self.response.write(str(resp))
89
90
91 class MenuHandler(webapp2.RequestHandler):
92
93 def post(self):
94 choice = self.request.params('Digits')
95
96 if choice == '1':
97 self.redirect('/twiml/enqueue?queue=support')
98 elif choice == '2':
99 self.redirect('/twiml/enqueue?queue=sales')
100 elif choice == '3':
101 self.redirect('/twiml/enqueue?queue=marketing')
102 else:
103 self.redirect('/twiml/menu')
104
105 def get(self):
106 """Let the caller choose what department to queue into"""
107 self.response.headers['Content-Type'] = 'application/xml'
108
109 resp = twiml.Response()
110 gather = resp.gather()
111 gather.say("For support, press 1")
112 gather.say("For sales, press 2")
113 gather.say("For marketing, press 3")
114 resp.redirect()
115
116 self.response.write(str(resp))
117
118
119 class SupportHandler(webapp2.RequestHandler):
120
121 def get(self):
122 params = {
123 "token": util.generate_token(ACCOUNT_SID, AUTH_TOKEN, APP_SID)
124 }
125 self.response.out.write(render_template("index.html", params))
126
127
128 class CallHandler(webapp2.RequestHandler):
129
130 def get(self):
131 """Show a list of all the current calls"""
132 params = {
133 "calls": client.calls.iter(status="in-progress"),
134 }
135
136 self.response.out.write(render_template("calls.html", params))
137
138 def post(self):
139 sid = self.request.params.get('sid')
140
141 if sid == '':
04079d4 Update callcenter.py to use correct parameter name
Kevin Burke authored
142 return
9ecac9a @kyleconroy Major updates
kyleconroy authored
143
144 call = client.calls.get(sid)
145 call.redirect('/twiml/boss')
146
147
148 class FeedbackHandler(webapp2.RequestHandler):
149
150 def get(self):
151 """Show a list of all the text messages to this number"""
152 params = {
153 "messages": client.sms.messages.iter(),
154 }
155
156 self.response.out.write(render_template("messages.html", params))
157
158
159 app = webapp2.WSGIApplication([
160 ('/twiml/boss', BossHandler),
161 ('/twiml/wait', WaitHandler),
162 ('/twiml/menu', MenuHandler),
163 ('/twiml/dequeue', DequeueHandler),
164 ('/twiml/enqueue', EnqueueHandler),
165 ('/twiml/record-consent', ConsentHandler),
166 ('/web/support', SupportHandler),
167 ('/web/calls', SupportHandler),
168 ('/web/feedback', FeedbackHandler),
169 ], debug=True)
Something went wrong with that request. Please try again.