-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
79 lines (64 loc) · 2.49 KB
/
server.py
File metadata and controls
79 lines (64 loc) · 2.49 KB
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
import datetime
from flask import Flask
from flask import request
from flask.json import jsonify
from automation import WebexAutomation
app = Flask(__name__)
running_automations = {}
def auth(token):
return token == "jhf85yb#fl43d"
@app.route('/join', methods=['POST'])
def join_meeting():
try:
args = request.get_json()
name = args["name"]
email = args["email"]
url = args["url"]
header = request.headers
auth_token = header["authentication"]
if(auth(auth_token)):
automation = WebexAutomation(url)
length = len(running_automations)
id = str(length + 1) + str(datetime.datetime.now())
running_automations[id] = automation
automation = running_automations[id]
result, error = automation.joinMeeting(name, email)
print(result, error)
if result:
return jsonify({"success": True, "message": "connected successfully", "id": id})
return jsonify({"success": result, "error": error})
except Exception as e:
print(str(e))
return jsonify({"success": False, "error": str(e)})
@app.route("/exit", methods=["POST"])
def exit_meeting():
try:
args = request.get_json()
auth_token = request.headers["authentication"]
id = str(args["id"])
print("existing from meeting")
print(running_automations)
if(auth(auth_token) and running_automations.get(id) != None):
print("founded")
automation = running_automations[id]
automation.close_meeting()
return jsonify({"success": True, "message": "exited from meeting"})
else:
return jsonify({"success": False, "message": "Not a valid id or token"})
except Exception as e:
print(str(e))
return jsonify({"success": False, "error": str(e)})
@app.route("/message", methods=["POST"])
def message():
args = request.get_json()
auth_token = request.headers["authentication"]
id = str(args["id"])
if(auth(auth_token) and running_automations.get(id) != None):
automation = running_automations[id]
result, error = automation.message(str(args["chat_message"]))
if result:
return jsonify({"success": True, "message": "messaeg sent successfully"})
return jsonify({"success": result, "error": error})
return jsonify({"success": False, "error": "Not valid"})
if __name__ == "__main__":
app.run(debug=True, port=5003)