feat(bot): enhance ticket room invitation process

Added customer notification when a moderator invites themselves to a ticket room, improving transparency and communication. Corrected parameter for inviting operators to ensure proper user identification. Fixed room state update targeting, enhancing data accuracy.
This commit is contained in:
Kumi 2024-11-09 16:37:17 +01:00
parent 652206a21a
commit c1032fd1c5
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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},