forked from angl/waiter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.py
executable file
·51 lines (39 loc) · 1.69 KB
/
host.py
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
from flask import Flask, request, redirect
import twilio.twiml
import twilio.rest
@app.route("/host", methods=['GET', 'POST'])
def handle_host_entrance():
global robotSidToUserNumber
userNumber = request.values.get('From', None)
# make the call to customer service
call = client.calls.create(to=customerServiceNumber, from_=hostNumber,
url=hostUrl + "/host/%s/customer_service" % userNumber)
# make the call to the robot
call = client.calls.create(to=robotNumber, from_=hostNumber,
url=hostUrl + "/host/%s/robot" % userNumber)
robotSidToUserNumber[ call.sid ] = userNumber
confName = "conf-%s" % userNumber
print "send user to conference %s" % confName
resp = twilio.twiml.Response()
resp.say("Welcome")
with resp.dial(method="POST") as d:
d.conference(name=confName, muted=False)
return str(resp)
@app.route("/host/<userNumber>/customer_service", methods=['GET', 'POST'])
def handle_host_call_customer_service(userNumber):
confName = "conf-%s" % userNumber
print "send customer service to conference %s" % confName
resp = twilio.twiml.Response()
resp.say("Welcome Customer Representative")
with resp.dial(method="POST") as d:
d.conference(name=confName, muted=False, endConferenceOnExit=True)
return str(resp)
@app.route("/host/<userNumber>/robot", methods=['GET', 'POST'])
def handle_host_call_robot(userNumber):
confName = "conf-%s" % userNumber
print "send robot to conference %s" % confName
resp = twilio.twiml.Response()
resp.say("Welcome Robot")
with resp.dial(method="POST") as d:
d.conference(name=confName, muted=False)
return str(resp)