Skip to content

Commit

Permalink
fix(ux): on agent response: auto mark as 'Replied' (frappe#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad authored and kurogeek committed May 25, 2023
1 parent a7f808f commit fbf86e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
32 changes: 17 additions & 15 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
default_ticket_outgoing_email_account,
)

from helpdesk.utils import publish_event


class HDTicket(Document):
@staticmethod
Expand Down Expand Up @@ -110,6 +112,9 @@ def by_priority(query: Query, direction: Order):
"Last modified on": "modified",
}

def publish_update(self):
publish_event("helpdesk:ticket-update", {"name": self.name})

def autoname(self):
return self.name

Expand All @@ -132,6 +137,7 @@ def after_insert(self):
def on_update(self):
self.handle_ticket_activity_update()
self.remove_assignment_if_not_in_team()
self.publish_update()

def handle_ticket_activity_update(self):
"""
Expand All @@ -157,11 +163,6 @@ def handle_ticket_activity_update(self):
self.name, f"{field_maps[field]} set to {self.as_dict()[field]}"
)

event = "helpdesk:ticket-update"
room = get_website_room()
data = {"name": self.name}
frappe.publish_realtime(event, message=data, room=room, after_commit=True)

def remove_assignment_if_not_in_team(self):
"""
Removes the assignment if the agent is not in the team.
Expand Down Expand Up @@ -298,10 +299,7 @@ def assign_agent(self, agent):
agent_name = frappe.get_value("HD Agent", agent, "agent_name")
log_ticket_activity(self.name, f"assigned to {agent_name}")

event = "helpdesk:ticket-assignee-update"
data = {"name": self.name}
room = get_website_room()
frappe.publish_realtime(event, message=data, room=room, after_commit=True)
publish_event("helpdesk:ticket-assignee-update", {"name": self.name})

def get_assigned_agent(self):
if self._assign:
Expand Down Expand Up @@ -436,6 +434,16 @@ def reply_via_agent(

communication.insert(ignore_permissions=True)

# Mark status, unconditionally.
self.status = "Replied"
self.save()

if skip_email_workflow:
return

if not sender_email:
frappe.throw(_("Can not send email. No sender email set up!"))

_attachments = []

for attachment in attachments:
Expand All @@ -445,12 +453,6 @@ def reply_via_agent(
file_doc.save(ignore_permissions=True)
_attachments.append({"file_url": file_doc.file_url})

if skip_email_workflow:
return

if not sender_email:
frappe.throw(_("Can not send email. No sender email set up!"))

reply_to_email = sender_email.email_id
template = (
"new_reply_on_customer_portal_notification"
Expand Down
11 changes: 9 additions & 2 deletions helpdesk/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from bs4 import BeautifulSoup
import frappe
import re

import frappe
from bs4 import BeautifulSoup
from frappe.realtime import get_website_room


def publish_event(event: str, data: dict):
room = get_website_room()
frappe.publish_realtime(event, message=data, room=room, after_commit=True)


def extract_mentions(html):
if not html:
Expand Down

0 comments on commit fbf86e6

Please sign in to comment.