From ba51780941a8b966d065b724393a0e607045892e Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Thu, 27 Jun 2024 19:42:06 +0800 Subject: [PATCH 1/9] create tagging recording samples --- .gitignore | 4 +- .../call_1979aead-ffae-4ab6-a0ac-4cca7f286240 | 1 + tagging-recording/index.html | 176 ++++++++++++++++++ tagging-recording/partnerkey | 15 ++ tagging-recording/requirements.txt | 3 + tagging-recording/server.py | 163 ++++++++++++++++ 6 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 create mode 100644 tagging-recording/index.html create mode 100644 tagging-recording/partnerkey create mode 100644 tagging-recording/requirements.txt create mode 100644 tagging-recording/server.py diff --git a/.gitignore b/.gitignore index d49dae3..a2ee390 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ __pycache__ siteconfig.py siteconfig.pyc -.venv \ No newline at end of file +.venv +.vscode +.DS_Store diff --git a/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 b/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 new file mode 100644 index 0000000..f9cecd5 --- /dev/null +++ b/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 @@ -0,0 +1 @@ +58fa6baa-f86d-4d6a-a5cd-3b1535ed97a1 diff --git a/tagging-recording/index.html b/tagging-recording/index.html new file mode 100644 index 0000000..f3a9daa --- /dev/null +++ b/tagging-recording/index.html @@ -0,0 +1,176 @@ + + + + + + +

+

+

+ +
+
+ + + + + diff --git a/tagging-recording/partnerkey b/tagging-recording/partnerkey new file mode 100644 index 0000000..c3a0e7b --- /dev/null +++ b/tagging-recording/partnerkey @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDBcNF8bN6a8ekfmXTBiRBVGVZ93NDVo9lVnkGx+Ra9aOla5kwC +lt0Oup6phCqfhPPGej4L/O9flvELceM7Z+pacWPMskHmuzObUHMfcmTmKrBAmu8Z +qVkmnk7GaE9hU7GOgSB7j9PaDOAl0RB9MwazpQfe3zknvjhNJ3yQi9PK4QIDAQAB +AoGAVpnHb0jeL8f1ciwlVS+jnDWHvzlIVRzRg78h8idtwsZhEkzf4pjfxmRN+94r +ptbCvCyl8n/+OnE84L7P2Byhkax6rnjM8UTJ6P90btOv/tz81IF41Vx6FwUockgu +aQvTj47vP50hiGEeNH/3eZ2ywuIodYSxOfHxvHrpBqsHP0ECQQDrOfxQiGscEFcd +yVQD3wOX/aU19csU/Ufwv8dV3DZOlRekucfNjpVJjqb6kZUBWkbxyww0+pWmS1z+ +TIj94npNAkEA0oYi/07yTiyatLo2k8XWLK8sdV2fgP5W0Hbicpi2AwMG12LFYXHb +7oDgisubHz4P49Njq1ZZql+jF+7s0df05QJBANkgRyTXJ3daJe/avPBt1NVhTjTG +01RmjxdNDuTURlS3DoIA8sttR6QER2GXLCF5gW8DbBsjCyva+NXLM9CWUykCQHEb +pnP7a436wwf0wFv2wBJz73QDYC5C+Eu6hAHD8I5/ss5H//pR3TMwRPPtXqOTiaAD +NBqbI0O5bHvwX4aC+80CQAlTpTxLZNGXLiveWCo34BQG/Oilfm5QsN3w7dJ9Hkbg +SmzuFUAjBjcHaAUmbWjK+9xy24bDvpqAhkzt3NAAsqg= +-----END RSA PRIVATE KEY----- diff --git a/tagging-recording/requirements.txt b/tagging-recording/requirements.txt new file mode 100644 index 0000000..351fa60 --- /dev/null +++ b/tagging-recording/requirements.txt @@ -0,0 +1,3 @@ +cryptography==3.0 +PyJWT==1.7.1 +requests==2.24.0 diff --git a/tagging-recording/server.py b/tagging-recording/server.py new file mode 100644 index 0000000..186db4e --- /dev/null +++ b/tagging-recording/server.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python3 +""" +License: MIT License +Copyright (c) 2023 Miel Donkers + +Very simple HTTP server in python for logging requests +Usage:: + ./server.py [] +""" +from http.server import BaseHTTPRequestHandler, HTTPServer +import logging +import sys +import datetime +import json +import jwt +import os +import time +from os import walk + +sys.path.append('.') +import libhelplightning +import siteconfig + +current_dir = "/" + sys.path[0] + "/" + +class S(BaseHTTPRequestHandler): + def _set_response(self): + self.send_response(200) + self.send_header('Content-type', 'text/html') + self.end_headers() + + def get_logger(self, level=logging.DEBUG): + """ + Sets up logging to be shared across + all classes/functions. + """ + root = logging.getLogger() + root.setLevel(level) + ch = logging.StreamHandler(sys.stdout) + ch.setLevel(level) + root.addHandler(ch) + return root + + def generate_token(self, partner_key): + # create a date that expires in 1 hour + exp = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=3600) + + # load our private key, which is in pkcs8 format + with open(partner_key) as f: + secret = f.read() + + # generate a new JWT token that will be valid for one hour and sign it with our secret + payload = { + 'iss': 'Ghazal', + 'sub': f'Partner:{siteconfig.SITE_ID}', + 'aud': 'Ghazal', + 'exp': exp + } + + token = jwt.encode(payload, key=secret, algorithm='RS256') + + return token + + def save_data(self, call_id, uuid): + writepath = current_dir + call_id + mode = 'a' if os.path.exists(writepath) else 'w' + with open(writepath, mode) as f: + f.write(uuid + '\n') + + def get_call_from_uuid(self, uuids): + filenames = next(walk(current_dir), (None, None, []))[2] + prefix = 'call_' + files = filter(lambda x: x.startswith(prefix), filenames) + calls = list(files) + arr = [] + for f in calls: + with open(current_dir + f, 'r') as file: + lines = file.readlines() + for line in lines: + line = line.strip() + if line in uuids: + arr.append(f) + + + myset = set(arr) + logging.info("\n %s", list(myset)) + return list(myset) + + def get_call_attachments(self, call_ids): + logger = self.get_logger(level=logging.INFO) + token = self.generate_token(siteconfig.PARTNER_KEY) + e_client = libhelplightning.GaldrClient( + logger, + siteconfig.HELPLIGHTNING_ENDPOINT, + siteconfig.API_KEY, + token = token + ) + attachments = [] + for id in call_ids: + time.sleep(0.100) + resp = e_client.get(f'/api/v1r1/enterprise/calls/{id}/attachments') + for e in resp: + attachments.append({"uuid": e.get("uuid"), "url": e.get("signed_url")}) + + return attachments + + def do_GET(self): + self.path = current_dir + 'index.html' + logging.info("GET request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(self.headers)) + file_to_open = open(self.path[1:]).read() + self._set_response() + self.wfile.write(bytes(file_to_open, 'utf-8')) + + def do_POST(self): + content_length = int(self.headers['Content-Length']) # <--- Gets the size of data + post_data = self.rfile.read(content_length) # <--- Gets the data itself + logging.info("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n", + str(self.path), str(self.headers), post_data.decode('utf-8')) + + call_data = json.loads(post_data.decode('utf-8')) + + type = call_data.get("type") + category = call_data.get("category") + + if type == "call" and category == "attachment_created": + uuid = call_data.get("data").get("attachment").get("uuid") + call_id = call_data.get("data").get("call_id") + logging.info("\nAttachment: \n call_id: %s \n uuid: %s \n", call_id, uuid) + self.save_data(call_id, uuid) + + response = "" + if type == "download": + uuids = call_data.get("uuids") + call_ids = self.get_call_from_uuid(uuids) + attachments = self.get_call_attachments(call_ids) + res = filter(lambda x: x['uuid'] in uuids, attachments) + response = json.dumps(list(res)) + + self._set_response() + self.send_header('Content-Type', 'application/json') + self.wfile.write(response.encode('utf-8')) + +def run(server_class=HTTPServer, handler_class=S, port=8899): + logging.basicConfig(level=logging.INFO) + #logging.info(sys.path) + server_address = ('', port) + httpd = server_class(server_address, handler_class) + logging.info('Starting httpd...\n') + try: + httpd.serve_forever() + except KeyboardInterrupt: + pass + httpd.server_close() + logging.info('Stopping httpd...\n') + + +if __name__ == '__main__': + from sys import argv + + if len(argv) == 2: + run(port=int(argv[1])) + else: + run() From be786dbd475d505c27d511c7496080fadb1bbdea Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Thu, 27 Jun 2024 19:46:25 +0800 Subject: [PATCH 2/9] update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a2ee390..dad1e51 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ siteconfig.pyc .venv .vscode .DS_Store +/tagging-recording/call_* From 77b618d80d72e1d15e21287ffc1952526a8e42b3 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Thu, 27 Jun 2024 19:48:14 +0800 Subject: [PATCH 3/9] remove key file --- tagging-recording/partnerkey | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 tagging-recording/partnerkey diff --git a/tagging-recording/partnerkey b/tagging-recording/partnerkey deleted file mode 100644 index c3a0e7b..0000000 --- a/tagging-recording/partnerkey +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQDBcNF8bN6a8ekfmXTBiRBVGVZ93NDVo9lVnkGx+Ra9aOla5kwC -lt0Oup6phCqfhPPGej4L/O9flvELceM7Z+pacWPMskHmuzObUHMfcmTmKrBAmu8Z -qVkmnk7GaE9hU7GOgSB7j9PaDOAl0RB9MwazpQfe3zknvjhNJ3yQi9PK4QIDAQAB -AoGAVpnHb0jeL8f1ciwlVS+jnDWHvzlIVRzRg78h8idtwsZhEkzf4pjfxmRN+94r -ptbCvCyl8n/+OnE84L7P2Byhkax6rnjM8UTJ6P90btOv/tz81IF41Vx6FwUockgu -aQvTj47vP50hiGEeNH/3eZ2ywuIodYSxOfHxvHrpBqsHP0ECQQDrOfxQiGscEFcd -yVQD3wOX/aU19csU/Ufwv8dV3DZOlRekucfNjpVJjqb6kZUBWkbxyww0+pWmS1z+ -TIj94npNAkEA0oYi/07yTiyatLo2k8XWLK8sdV2fgP5W0Hbicpi2AwMG12LFYXHb -7oDgisubHz4P49Njq1ZZql+jF+7s0df05QJBANkgRyTXJ3daJe/avPBt1NVhTjTG -01RmjxdNDuTURlS3DoIA8sttR6QER2GXLCF5gW8DbBsjCyva+NXLM9CWUykCQHEb -pnP7a436wwf0wFv2wBJz73QDYC5C+Eu6hAHD8I5/ss5H//pR3TMwRPPtXqOTiaAD -NBqbI0O5bHvwX4aC+80CQAlTpTxLZNGXLiveWCo34BQG/Oilfm5QsN3w7dJ9Hkbg -SmzuFUAjBjcHaAUmbWjK+9xy24bDvpqAhkzt3NAAsqg= ------END RSA PRIVATE KEY----- From d5b6e47b2122ffc20f71fb87fa432011f39c2e93 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Fri, 28 Jun 2024 13:54:35 +0800 Subject: [PATCH 4/9] add select option for sites --- .../call_1979aead-ffae-4ab6-a0ac-4cca7f286240 | 1 - tagging-recording/index.html | 63 ++++++++++++------- 2 files changed, 40 insertions(+), 24 deletions(-) delete mode 100644 tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 diff --git a/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 b/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 deleted file mode 100644 index f9cecd5..0000000 --- a/tagging-recording/call_1979aead-ffae-4ab6-a0ac-4cca7f286240 +++ /dev/null @@ -1 +0,0 @@ -58fa6baa-f86d-4d6a-a5cd-3b1535ed97a1 diff --git a/tagging-recording/index.html b/tagging-recording/index.html index f3a9daa..e4cf723 100644 --- a/tagging-recording/index.html +++ b/tagging-recording/index.html @@ -32,8 +32,14 @@ -

-

+ + + +

+

+

@@ -48,29 +54,30 @@ var recordings; addEventListener("DOMContentLoaded", (event) => { - popup = window.open('https://app-dev.helplightning.net.cn/'); + document.getElementById("btnStart").disabled = false; + document.getElementById("btnStop").disabled = true; recordings = new Array(); - let rec = { - "name": "recording_" + generateName(), - "uuid": "58fa6baa-f86d-4d6a-a5cd-3b1535ed97a1", - "url": "..." - } - - recordings.push(rec) }); - + function openSite() { + url = document.getElementById("sites").innerText; + popup = window.open(url); + } function startRecording() { popup.postMessage({ type: 'START_RECORDING' }, '*'); + document.getElementById("btnStart").disabled = true; + document.getElementById("btnStop").disabled = false; } function stopRecording() { popup.postMessage({ type: 'STOP_RECORDING' }, '*'); + document.getElementById("btnStart").disabled = false; + document.getElementById("btnStop").disabled = true; } function refresh() { @@ -100,7 +107,7 @@ let rec = { "name": "recording_" + generateName(), "uuid": event.data.uuid, - "url": "..." + "url": "" } recordings.push(rec) @@ -124,15 +131,22 @@ var text1 = document.createTextNode(arr[i].name); var text2 = document.createTextNode(arr[i].uuid); - var url = document.createElement('a'); - var linkText = document.createTextNode("link"); - url.appendChild(linkText); - url.title = "link"; - url.href = arr[i].url; td1.appendChild(text1); td2.appendChild(text2); - td3.appendChild(url); + + if (arr[i].url === "") { + var url = document.createElement('a'); + var linkText = document.createTextNode("link"); + url.appendChild(linkText); + url.title = "link"; + url.href = arr[i].url; + url.target = "_blank"; + td3.appendChild(url); + } else { + var t = document.createTextNode(""); + td3.appendChild(t); + } tr.appendChild(td1); tr.appendChild(td2); @@ -144,12 +158,15 @@ } function print(json) { - new_recordings = new Array(); - for (const r of json) { - let found = recordings.find((element) => r["uuid"] === element["uuid"]); - found.url = r.url; + if (json.length != 0) { + new_recordings = new Array(); + for (const r of json) { + let found = recordings.find((element) => r["uuid"] === element["uuid"]); + found.url = r.url; + + new_recordings.push(found); + } - new_recordings.push(found); create_table(new_recordings); recordings.length = 0; recordings = new_recordings; From 4f1f7e14769fe9a524f1b7b4520c0233d6c44362 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Sat, 29 Jun 2024 12:29:53 +0800 Subject: [PATCH 5/9] get url from attachment id --- tagging-recording/index.html | 42 ++++++++++++++++++++++++---- tagging-recording/server.py | 53 +++++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 27 deletions(-) diff --git a/tagging-recording/index.html b/tagging-recording/index.html index e4cf723..8af79c4 100644 --- a/tagging-recording/index.html +++ b/tagging-recording/index.html @@ -40,10 +40,12 @@

-

+

+ +

@@ -100,12 +102,24 @@ .then((json) => print(json)); } + function reset() { + fetch("http://127.0.0.1:8899", { + method: "POST", + body: JSON.stringify({ + type: "reset" + }), + headers: { + "Content-type": "application/json; charset=UTF-8" + } + }) + .then((response) => reset_page())} + window.addEventListener( "message", (event) => { if (event.data.type === "RECORDING_STARTED") { let rec = { - "name": "recording_" + generateName(), + "name": generateName(), "uuid": event.data.uuid, "url": "" } @@ -122,6 +136,19 @@ document.getElementById("rec_div").firstChild.remove(); var table = document.createElement('table'); + + var header = table.createTHead(); + var row = header.insertRow(0); + + var cell1 = row.insertCell(0); + cell1.innerHTML = "Tag" + + var cell2 = row.insertCell(1); + cell2.innerHTML = "UUID" + + var cell3 = row.insertCell(2); + cell3.innerHTML = "URL" + for (var i = 0; i < arr.length; i++) { var tr = document.createElement('tr'); @@ -136,6 +163,9 @@ td2.appendChild(text2); if (arr[i].url === "") { + var t = document.createTextNode(""); + td3.appendChild(t); + } else { var url = document.createElement('a'); var linkText = document.createTextNode("link"); url.appendChild(linkText); @@ -143,9 +173,6 @@ url.href = arr[i].url; url.target = "_blank"; td3.appendChild(url); - } else { - var t = document.createTextNode(""); - td3.appendChild(t); } tr.appendChild(td1); @@ -190,4 +217,9 @@ return name; } + + function reset_page() { + recordings.length = 0; + create_table(recordings); + } diff --git a/tagging-recording/server.py b/tagging-recording/server.py index 186db4e..0a658aa 100644 --- a/tagging-recording/server.py +++ b/tagging-recording/server.py @@ -61,32 +61,35 @@ def generate_token(self, partner_key): return token - def save_data(self, call_id, uuid): + def save_data(self, call_id, uuid, attachement_id): writepath = current_dir + call_id mode = 'a' if os.path.exists(writepath) else 'w' with open(writepath, mode) as f: - f.write(uuid + '\n') + f.write(uuid + ',' + str(attachement_id) + '\n') - def get_call_from_uuid(self, uuids): + def get_cached_files(self): filenames = next(walk(current_dir), (None, None, []))[2] prefix = 'call_' files = filter(lambda x: x.startswith(prefix), filenames) - calls = list(files) - arr = [] + return list(files) + + def get_attachments_from_uuid(self, uuids): + calls = self.get_cached_files() + dictionary = {} for f in calls: with open(current_dir + f, 'r') as file: lines = file.readlines() for line in lines: line = line.strip() - if line in uuids: - arr.append(f) + data = line.split(",") + if data[0] in uuids: + dictionary[data[1]] = f # {attachment_id: call_id} - myset = set(arr) - logging.info("\n %s", list(myset)) - return list(myset) + logging.info("\n %s", dictionary) + return dictionary - def get_call_attachments(self, call_ids): + def get_call_attachments(self, call_attachment_dict): logger = self.get_logger(level=logging.INFO) token = self.generate_token(siteconfig.PARTNER_KEY) e_client = libhelplightning.GaldrClient( @@ -96,11 +99,10 @@ def get_call_attachments(self, call_ids): token = token ) attachments = [] - for id in call_ids: + for attachment_id, call_id in call_attachment_dict.items(): time.sleep(0.100) - resp = e_client.get(f'/api/v1r1/enterprise/calls/{id}/attachments') - for e in resp: - attachments.append({"uuid": e.get("uuid"), "url": e.get("signed_url")}) + resp = e_client.get(f'/api/v1r1/enterprise/calls/{call_id}/attachments/{attachment_id}') + attachments.append({"uuid": resp.get("uuid"), "url": resp.get("signed_url")}) return attachments @@ -112,6 +114,7 @@ def do_GET(self): self.wfile.write(bytes(file_to_open, 'utf-8')) def do_POST(self): + response = "{}" content_length = int(self.headers['Content-Length']) # <--- Gets the size of data post_data = self.rfile.read(content_length) # <--- Gets the data itself logging.info("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n", @@ -124,17 +127,23 @@ def do_POST(self): if type == "call" and category == "attachment_created": uuid = call_data.get("data").get("attachment").get("uuid") + attachement_id = call_data.get("data").get("attachment").get("id") call_id = call_data.get("data").get("call_id") - logging.info("\nAttachment: \n call_id: %s \n uuid: %s \n", call_id, uuid) - self.save_data(call_id, uuid) - response = "" + logging.info("\nAttachment: id - %s \n call_id: %s \n uuid: %s \n", attachement_id, call_id, uuid) + self.save_data(call_id, uuid, attachement_id) + + if type == "download": uuids = call_data.get("uuids") - call_ids = self.get_call_from_uuid(uuids) - attachments = self.get_call_attachments(call_ids) - res = filter(lambda x: x['uuid'] in uuids, attachments) - response = json.dumps(list(res)) + call_attachment_dict = self.get_attachments_from_uuid(uuids) + attachments = self.get_call_attachments(call_attachment_dict) + response = json.dumps(attachments) + + if type == "reset": + files = self.get_cached_files() + for f in files: + os.remove(current_dir + f) self._set_response() self.send_header('Content-Type', 'application/json') From 8a0817b5e4d2ca28114165a55eaf1bb0b6d04009 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Tue, 2 Jul 2024 10:14:26 +0800 Subject: [PATCH 6/9] add README document --- tagging-recording/README.md | 43 +++++++++++++++++++ tagging-recording/index.html | 66 +++++++++++++++++++++--------- tagging-recording/requirements.txt | 3 -- 3 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 tagging-recording/README.md delete mode 100644 tagging-recording/requirements.txt diff --git a/tagging-recording/README.md b/tagging-recording/README.md new file mode 100644 index 0000000..2b9dbf0 --- /dev/null +++ b/tagging-recording/README.md @@ -0,0 +1,43 @@ +## Requirements + +- Python 3 and Pip + +## Install Dependencies + +Make sure you have run the following in the parent directory: +``` +pip install -r requirements.txt +``` + +## Configuring the Script + +Please make sure you have configured the `siteconfig.py` in the parent directory. + +## Set up a Reverse Proxy + +This script will start up an HTTP server on port 8899. +It is recommanded to set up another public web service and forward the web hook request to server. + +## Usage + +The script will start up a web server on port 8899 and will listen for +incoming webhooks of type `call` with a category of `attachment_created`. + +Each time it gets a new `attachment_created` event, the script will +save the attachment id and uuid to the file named with call id. + +``` +> cat call_34c78f14-55a7-4d16-86c1-a6fe7837cf26 +5895ec01-c02c-42db-983a-9fdae98d0ace,31675 +a7c1de42-9900-41e6-9ef4-cdabf01d45e3,31674 +95d4f7a9-d5b8-46df-a3fc-504c51845910,31676 +4aec6d2a-263d-4227-9248-6d3d10592668,31677 +f4a753f2-ee63-4ec7-adaf-5044c88a7dcd,31678 + +``` + +To run this script: + +``` +python3 server.py +``` diff --git a/tagging-recording/index.html b/tagging-recording/index.html index 8af79c4..be34d50 100644 --- a/tagging-recording/index.html +++ b/tagging-recording/index.html @@ -36,6 +36,7 @@

@@ -45,7 +46,7 @@
-

+

@@ -62,7 +63,8 @@ }); function openSite() { - url = document.getElementById("sites").innerText; + var e = document.getElementById("sites"); + url = e.options[e.selectedIndex].text; popup = window.open(url); } @@ -117,18 +119,34 @@ window.addEventListener( "message", (event) => { - if (event.data.type === "RECORDING_STARTED") { - let rec = { - "name": generateName(), - "uuid": event.data.uuid, - "url": "" + if (event.data.type === "RECORDING_STARTED" && event.data.uuid != null) { + document.getElementById("btnStart").disabled = true; + document.getElementById("btnStop").disabled = false; + + let found = recordings.find((element) => event.data.uuid === element["uuid"]); + if (found === undefined) { + let rec = { + "name": generateName(), //randomly tagging the recordings + "uuid": event.data.uuid, + "status": "STARTED", + "url": "" + } + + recordings.push(rec) } - - recordings.push(rec) - - create_table(recordings); + } else if (event.data.type === "RECORDING_STOPPED" && event.data.uuid != null) { + document.getElementById("btnStart").disabled = false; + document.getElementById("btnStop").disabled = true; + + rec = { + "uuid": event.data.uuid, + "url": "", + "status": "STOPPED" + } + updateRecordings([rec]) } + create_table(recordings); } ); @@ -186,17 +204,25 @@ function print(json) { if (json.length != 0) { - new_recordings = new Array(); - for (const r of json) { - let found = recordings.find((element) => r["uuid"] === element["uuid"]); - found.url = r.url; + updateRecordings(json) + create_table(recordings); + } + } - new_recordings.push(found); - } + function updateRecordings(uuids) { + for (const u of uuids) { + let found = recordings.find((element) => u["uuid"] === element["uuid"]); + if (found === undefined) { + found = u; + found.name = generateName(); + } + new_found = found; + recordings.pop(found); + + new_found.url = u.url; + new_found.status = u.status; - create_table(new_recordings); - recordings.length = 0; - recordings = new_recordings; + recordings.push(new_found); } } diff --git a/tagging-recording/requirements.txt b/tagging-recording/requirements.txt deleted file mode 100644 index 351fa60..0000000 --- a/tagging-recording/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -cryptography==3.0 -PyJWT==1.7.1 -requests==2.24.0 From eb8b140b88f8a8b9c63c1a9dbbbdcbdf20957319 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Tue, 2 Jul 2024 10:26:08 +0800 Subject: [PATCH 7/9] add more docs for README --- tagging-recording/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tagging-recording/README.md b/tagging-recording/README.md index 2b9dbf0..7c929de 100644 --- a/tagging-recording/README.md +++ b/tagging-recording/README.md @@ -35,6 +35,15 @@ a7c1de42-9900-41e6-9ef4-cdabf01d45e3,31674 f4a753f2-ee63-4ec7-adaf-5044c88a7dcd,31678 ``` +We will tag the recording automatically when receive the `RECORDING_STARTED` event from citron. + +In `index.html`, we have one post function to backend: + +``` +POST http://127.0.0.1:8899 {'type': 'download', uuids: [....]} +``` +This will try to look and parse the call files(if have one), then match the uuid with the attachment id and get the `signed_url` back. + To run this script: From 06626d218e8eb0e36caae9a15667b566380e3546 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Tue, 2 Jul 2024 10:29:52 +0800 Subject: [PATCH 8/9] add more docs for README --- tagging-recording/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tagging-recording/README.md b/tagging-recording/README.md index 7c929de..2167039 100644 --- a/tagging-recording/README.md +++ b/tagging-recording/README.md @@ -19,6 +19,7 @@ This script will start up an HTTP server on port 8899. It is recommanded to set up another public web service and forward the web hook request to server. ## Usage +This script use `window.postMessage` to interacting with citron. So make sure open HL page with button on top of current page. The script will start up a web server on port 8899 and will listen for incoming webhooks of type `call` with a category of `attachment_created`. From e92c3d2bea76f7f34fb2d33f26c2b3b9b7c4b9c9 Mon Sep 17 00:00:00 2001 From: Calix Hu Date: Fri, 5 Jul 2024 18:09:35 +0800 Subject: [PATCH 9/9] persist data --- tagging-recording/index.html | 105 ++++++++++++++--------------------- tagging-recording/server.py | 60 +++++++++++++++++--- 2 files changed, 92 insertions(+), 73 deletions(-) diff --git a/tagging-recording/index.html b/tagging-recording/index.html index be34d50..ae20ff3 100644 --- a/tagging-recording/index.html +++ b/tagging-recording/index.html @@ -41,12 +41,12 @@

-

+

-

+

@@ -54,12 +54,11 @@