From b33f905b3c0288ae13304442f76b7859a9895bdf Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 8 Nov 2024 13:06:25 +0100 Subject: [PATCH] fix(bot): add sender info and error handling Include the sender's name in bot notifications to enhance user communication. Introduce exception handling and logging when relaying messages to improve debugging and reliability. --- src/matrix_applicationbot/classes/bot.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index 73fe693..0cbcc5c 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -485,7 +485,7 @@ class ApplicationBot: "m.room.message", { "msgtype": "m.text", - "body": f"Your application #{ticket_id} has been created. Please check your DMs.", + "body": f"{sender} Your application #{ticket_id} has been created. Please check your DMs.", }, ) @@ -626,9 +626,13 @@ class ApplicationBot: ) # Relay the entire event content to the target room - await self.client.room_send( - target_room_id, "m.room.message", event.source["content"] - ) + try: + await self.client.room_send( + target_room_id, "m.room.message", event.source["content"] + ) + except Exception as e: + logging.error(f"Failed to relay message: {e}") + logging.debug(f"Event source: {event.source}") async def help_command(self, room, sender): if await self.is_operator(sender):