-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateRoom.py
58 lines (50 loc) · 1.96 KB
/
CreateRoom.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
52
53
54
55
56
57
58
from flask import request as r
from flask_restful import Resource
import requests as req
from requests.auth import HTTPBasicAuth
from util import get_random_string
user = 'SK20841af8008834611f84e7590630f467'
pwd = 'oRob0tiWhYPm9gLQChE9FxX1vViOsI2U'
def create_transform(b):
d = b
a = {}
a["id"] = d["sid"]
a["roomUniqueName"] = d["unique_name"]
a["roomSID"] = None
a["rooomstatus"] = d["status"]
a["maxparticipants"] = d["max_participants"]
a["type"] = d["type"]
a["startAt"] = None
a["endDt"] = None
a["duration"] = 0
a["createdDt"] = d["date_created"]
a["modifiedDt"] = d["date_updated"]
a["participants"] = []
return a
class CreateRoom(Resource):
def post(self):
request = r.get_json()
head = {"Content-Type": "application/x-www-form-urlencoded"}
payload = {
"MaxParticipants": 4,
"Type": "group-small"
}
if request is not None: # dict type
if (request['roomUniqueName'] is not None):
payload["UniqueName"] = str(request['roomUniqueName']) + \
get_random_string(4)
if (request['maxParticipants']):
if (request['maxParticipants'] > 4):
payload["Type"] = "group"
payload['MaxParticipants'] = request['maxParticipants']
if (request['RecordParticipantConnect'] is not None):
payload["RecordParticipantsOnConnect"] = request["RecordParticipantConnect"]
else:
return {"message": "Bad request please retry"}, 400
call = req.post('https://video.twilio.com/v1/Rooms/', auth=HTTPBasicAuth(
user, pwd), headers=head, data=payload)
return call.json(), 201
if call.status_code == 400:
if call.json()['code'] == 53113:
return {'message': "Room already exists"}, 400
return {'message': "Room name is invalid"}, 400