diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index b648a62..e329cde 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -110,6 +110,8 @@ class ApplicationBot: self.operator_room_id, "m.room.application", message_id ) + logging.debug(f"Processing reaction {reaction_key} for message {message_id}") + if isinstance(response, RoomGetStateEventResponse): ticket_id = response.content["ticket_id"] @@ -138,7 +140,7 @@ class ApplicationBot: ) elif reaction_key == "🟡": # Invite to ticket room - await self.invite_operator_direct(room, ticket_id, user_id) + await self.invite_operator_direct(room, ticket_id, sender) def extract_info_from_application_message(self, message_body): # Custom logic to extract user_id and ticket_id from the message @@ -148,7 +150,7 @@ class ApplicationBot: return user_id, ticket_id async def invite_operator_direct(self, room, ticket_id, user_id): - # Invite user to the operator's ticket room + # Invite operator to the ticket room state_event_key = f"ticket_{ticket_id}" response = await self.client.room_get_state_event( self.operator_room_id, "m.room.custom.ticket", state_event_key @@ -156,6 +158,17 @@ class ApplicationBot: if isinstance(response, RoomGetStateEventResponse): operator_room_id = response.content["operator_room"] + customer_room_id = response.content["customer_room"] + + await self.client.room_send( + customer_room_id, + "m.room.message", + { + "msgtype": "m.notice", + "body": "A moderator would like to join the room to discuss your application.", + }, + ) + await self.client.room_invite(operator_room_id, user_id) await self.client.room_send( room.room_id, @@ -229,7 +242,7 @@ class ApplicationBot: # Store message ID to ticket ID mapping in room state if isinstance(sent_message, RoomSendResponse): await self.client.room_put_state( - room_id=room.room_id, + room_id=self.operator_room_id, event_type="m.room.application", state_key=sent_message.event_id, content={"ticket_id": ticket_id},