From 635a490ad5b45ea1ce1b88919cdca99307aebf55 Mon Sep 17 00:00:00 2001 From: Jeremiah K <17190268+jeremiah-k@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:12:36 -0500 Subject: [PATCH] Attempt to retrieve the device_id using whoami() --- matrix_utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/matrix_utils.py b/matrix_utils.py index e12f479..6c41a12 100644 --- a/matrix_utils.py +++ b/matrix_utils.py @@ -3,7 +3,7 @@ import re import certifi import ssl -from typing import List +from typing import List, Union from nio import ( AsyncClient, AsyncClientConfig, @@ -11,6 +11,8 @@ RoomMessageText, RoomMessageNotice, UploadResponse, + WhoamiResponse, + WhoamiError, ) from config import relay_config from log_utils import get_logger @@ -60,7 +62,17 @@ async def connect_matrix(): matrix_client.access_token = matrix_access_token matrix_client.user_id = bot_user_id - # Now we can proceed without the device_id + # Attempt to retrieve the device_id using whoami() + whoami_response = await matrix_client.whoami() + if isinstance(whoami_response, WhoamiError): + logger.error(f"Failed to retrieve device_id: {whoami_response.message}") + matrix_client.device_id = None + else: + matrix_client.device_id = whoami_response.device_id + if matrix_client.device_id: + logger.info(f"Retrieved device_id: {matrix_client.device_id}") + else: + logger.warning("device_id not returned by whoami()") # Fetch the bot's display name response = await matrix_client.get_displayname(bot_user_id)