diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index 763ce26..8f278e3 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -90,7 +90,9 @@ class ApplicationBot: await self.open_ticket(room, event.state_key) async def reaction_callback(self, room: MatrixRoom, event): - logging.debug(f"Received reaction event: {event}") + # Ignore reactions from the bot itself + if event.sender == self.client.user_id: + return relation = event.source["content"].get("m.relates_to", {}) message_id = relation.get("event_id") @@ -105,6 +107,12 @@ class ApplicationBot: # Extract information from the event message_body = event.body sender = event.sender + + logging.info( + f"Processing reaction {reaction_key} from {sender} in {room.room_id}" + ) + logging.info(f"Message: {message_body}") + if message_body.startswith("Application received from"): # Extract user_id and ticket_id from the "apply" message user_id, ticket_id = self.extract_info_from_application_message( @@ -129,7 +137,6 @@ class ApplicationBot: def extract_info_from_application_message(self, message_body): # Custom logic to extract user_id and ticket_id from the message - # Message format might be "Application received from in Ticket #" parts = message_body.split() user_id = parts[3] # "from " ticket_id = parts[6][1:] # "Ticket #" @@ -203,7 +210,7 @@ class ApplicationBot: # Message format formatted_message = f"Application received from {sender} in Ticket #{ticket_id}: {message_body}" # Send the message to the operator room - await self.client.room_send( + sent_message = await self.client.room_send( self.operator_room_id, "m.room.message", { @@ -212,6 +219,42 @@ class ApplicationBot: }, ) + # React to the message with approve, reject, and invite emojis + if isinstance(sent_message, RoomMessageText): + await self.client.room_send( + room.room_id, + "m.reaction", + { + "m.relates_to": { + "rel_type": "m.annotation", + "event_id": sent_message.event_id, + "key": "🟢", + }, + }, + ) + await self.client.room_send( + room.room_id, + "m.reaction", + { + "m.relates_to": { + "rel_type": "m.annotation", + "event_id": sent_message.event_id, + "key": "🟡", + }, + }, + ) + await self.client.room_send( + room.room_id, + "m.reaction", + { + "m.relates_to": { + "rel_type": "m.annotation", + "event_id": sent_message.event_id, + "key": "🔴", + }, + }, + ) + await self.relay_message(room, sender, message_body) async def approve_or_reject_application(self, room, sender, command, approved):