-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.py
More file actions
62 lines (56 loc) · 2.1 KB
/
index.py
File metadata and controls
62 lines (56 loc) · 2.1 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
from ringcentral import SDK
import os
import json
from dotenv import load_dotenv
dotenv_path = '.env'
load_dotenv(dotenv_path)
from flask import Flask, jsonify, render_template, request
app = Flask(__name__)
platform = None
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', title='Home')
@app.route('/readlog', methods=['GET'])
def login():
global platform
if os.environ.get("ENVIRONMENT_MODE") == "sandbox":
rcsdk = SDK(os.environ.get("CLIENT_ID_SB"), os.environ.get("CLIENT_SECRET_SB"), 'https://platform.devtest.ringcentral.com')
username = os.environ.get("USERNAME_SB")
pwd = os.environ.get("PASSWORD_SB")
else:
rcsdk = SDK(os.environ.get("CLIENT_ID_PROD"), os.environ.get("CLIENT_SECRET_PROD"), 'https://platform.ringcentral.com')
username = os.environ.get("USERNAME_PROD")
pwd = os.environ.get("PASSWORD_PROD")
platform = rcsdk.platform()
try:
platform.login(username, '', pwd)
res = readCallLogs()
return json.dumps(res)
except Exception as e:
errorRes = {"calllog_error":"Cannot login."}
return errorRes
def readCallLogs() :
global platform
access = request.args.get('access', "account")
endpoint = "/account/~/extension/~/call-log";
if access == "account":
endpoint = "/account/~/call-log";
try:
params = request.args.get('params', None)
if params != None:
configs = json.loads(params)
response = platform.get(endpoint, configs)
jsonObj = json.loads(response.response()._content)
return jsonObj['records']
else:
errorRes = {"calllog_error":"Mising query parameters"}
return errorRes
except Exception as e:
error = str(e)
if error.find("ReadCompanyCallLog") != -1:
errorRes = {"calllog_error":"You do not have admin role to access account level. You can choose the extension access level."}
return errorRes
else:
errorRes = {"calllog_error":"Cannot access call log."}
return errorRes