diff --git a/utils/message.py b/utils/message.py index fcc72b3..3369f38 100644 --- a/utils/message.py +++ b/utils/message.py @@ -8,6 +8,7 @@ MATRIX_TOKEN = os.environ.get('MATRIX_TOKEN') MATRIX_HOMESERVER = os.environ.get('MATRIX_HOMESERVER') LOG_ALL_EVENTS = os.environ.get('LOG_ALL_EVENTS') +MATRIX_PROTO = os.environ.get('MATRIX_SERVER_PROTO') or "https" # Method to log events to rooms def log_event_to_rooms(event=None, webhooktype='generic'): @@ -19,7 +20,7 @@ def log_event_to_rooms(event=None, webhooktype='generic'): 'body': event, } - r = requests.get(f'https://{MATRIX_HOMESERVER}/_matrix/client/v3/joined_rooms?access_token={MATRIX_TOKEN}') + r = requests.get(f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/v3/joined_rooms?access_token={MATRIX_TOKEN}') if r.status_code != 200: log.error(f'Something bad happened: {r.text}') @@ -30,7 +31,7 @@ def log_event_to_rooms(event=None, webhooktype='generic'): joined_rooms = json.loads(r.text) for room in joined_rooms.get('joined_rooms'): - msg = f'https://{MATRIX_HOMESERVER}/_matrix/client/r0/rooms/{room}/send/fi.jae.webhooklog?access_token={MATRIX_TOKEN}' + msg = f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/r0/rooms/{room}/send/fi.jae.webhooklog?access_token={MATRIX_TOKEN}' r = requests.post(msg, data=json.dumps(payload)) if r.status_code != 200: log.error(f'Something bad happened: {r.text}') @@ -47,7 +48,7 @@ def send_to_matrix(message=None): 'formatted_body': markdown.markdown(message) } - r = requests.get(f'https://{MATRIX_HOMESERVER}/_matrix/client/v3/joined_rooms?access_token={MATRIX_TOKEN}') + r = requests.get(f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/v3/joined_rooms?access_token={MATRIX_TOKEN}') if r.status_code != 200: log.error(f'Something bad happened: {r.text}') @@ -55,7 +56,7 @@ def send_to_matrix(message=None): joined_rooms = json.loads(r.text) for room in joined_rooms.get('joined_rooms'): - msg = f'https://{MATRIX_HOMESERVER}/_matrix/client/r0/rooms/{room}/send/m.room.message?access_token={MATRIX_TOKEN}' + msg = f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/r0/rooms/{room}/send/m.room.message?access_token={MATRIX_TOKEN}' r = requests.post(msg, data=json.dumps(payload)) if r.status_code != 200: log.error(f'Something bad happened: {r.text}') diff --git a/utils/roomutil.py b/utils/roomutil.py index 28d8a8c..970da13 100644 --- a/utils/roomutil.py +++ b/utils/roomutil.py @@ -10,6 +10,7 @@ # Env variables MATRIX_TOKEN = os.environ.get('MATRIX_TOKEN') MATRIX_HOMESERVER = os.environ.get('MATRIX_HOMESERVER') +MATRIX_PROTO = os.environ.get('MATRIX_SERVER_PROTO') or "https" # Check rooms for joins def check_matrix_rooms_for_joins(): @@ -18,7 +19,7 @@ def check_matrix_rooms_for_joins(): room_log.fatal('NO HOMESERVER ADDRESS NOR TOKEN, CANNOT PROCEED') return - r = requests.get(f'https://{MATRIX_HOMESERVER}/_matrix/client/v3/sync?access_token={MATRIX_TOKEN}') + r = requests.get(f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/v3/sync?access_token={MATRIX_TOKEN}') if r.status_code == 200: json_data = json.loads(r.text) rooms = json_data.get('rooms') @@ -28,4 +29,4 @@ def check_matrix_rooms_for_joins(): else: for room in rooms['invite']: room_log.info(f'Joining room {room}') - r = requests.post(f'https://{MATRIX_HOMESERVER}/_matrix/client/v3/join/{room}?access_token={MATRIX_TOKEN}') + r = requests.post(f'{MATRIX_PROTO}://{MATRIX_HOMESERVER}/_matrix/client/v3/join/{room}?access_token={MATRIX_TOKEN}')