fix: adds missing conversation update rule evaluation missing for event EventConversationTeamAssigned

refactor code
This commit is contained in:
Abhinav Raut
2025-06-14 19:55:24 +05:30
parent 2bf45f32de
commit b7d4b187e8
2 changed files with 23 additions and 22 deletions

View File

@@ -494,11 +494,16 @@ func (c *Manager) UpdateConversationUserAssignee(uuid string, assigneeID int, ac
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
}
// Refetch the conversation to get the updated details.
conversation, err := c.GetConversation(0, uuid)
if err != nil {
return err
}
// Trigger webhook for conversation assigned and evaluate automation rules.
c.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationUserAssigned)
c.webhookStore.TriggerEvent(wmodels.EventConversationAssigned, conversation)
// Send email to assignee.
if err := c.SendAssignedConversationEmail([]int{assigneeID}, conversation); err != nil {
c.lo.Error("error sending assigned conversation email", "error", err)
@@ -508,19 +513,12 @@ func (c *Manager) UpdateConversationUserAssignee(uuid string, assigneeID int, ac
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
}
// Trigger webhook for conversation assigned and evaluate automation rules.
conversation, err = c.GetConversation(0, uuid)
if err == nil {
c.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationUserAssigned)
c.webhookStore.TriggerEvent(wmodels.EventConversationAssigned, conversation)
}
return nil
}
// UpdateConversationTeamAssignee sets the assignee of a conversation to a specific team and sets the assigned user id to NULL.
func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor umodels.User) error {
// Store previous assigned team ID to apply SLA policy if team has changed.
// Store previously assigned team ID to apply SLA policy if team has changed.
conversation, err := c.GetConversation(0, uuid)
if err != nil {
return err
@@ -536,27 +534,29 @@ func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor
return nil
}
// Apply SLA policy if team has changed and the new team has an SLA policy.
if previousAssignedTeamID != teamID && teamID > 0 {
// Team changed?
if previousAssignedTeamID != teamID {
team, err := c.teamStore.Get(teamID)
if err != nil {
return nil
}
// Fetch the conversation again to get the updated details.
conversation, err := c.GetConversation(0, uuid)
if err != nil {
return nil
}
if team.SLAPolicyID.Int > 0 {
systemUser, err := c.userStore.GetSystemUser()
if err != nil {
return nil
}
// Fetch the conversation again to get the updated assignee details.
conversation, err := c.GetConversation(0, uuid)
if err != nil {
return nil
}
if err := c.ApplySLA(conversation, team.SLAPolicyID.Int, systemUser); err != nil {
return nil
}
}
// Evaluate automation rules for conversation team assignment.
c.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationTeamAssigned)
}
return nil
}
@@ -599,17 +599,18 @@ func (c *Manager) UpdateConversationPriority(uuid string, priorityID int, priori
c.lo.Error("error updating conversation priority", "error", err)
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
}
if err := c.RecordPriorityChange(priority, uuid, actor); err != nil {
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
}
c.BroadcastConversationUpdate(uuid, "priority", priority)
// Evaluate automation rules for conversation priority change.
conversation, err := c.GetConversation(0, uuid)
if err == nil {
c.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationPriorityChange)
}
// Record activity.
if err := c.RecordPriorityChange(priority, uuid, actor); err != nil {
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
}
c.BroadcastConversationUpdate(uuid, "priority", priority)
return nil
}

View File

@@ -464,7 +464,7 @@ func (m *Manager) InsertMessage(message *models.Message) error {
m.webhookStore.TriggerEvent(wmodels.EventMessageCreated, message)
// Evaluate automation rules for outgoing message event.
conversation, err := m.GetConversation(message.ConversationID, message.ConversationUUID)
conversation, err := m.GetConversation(0, message.ConversationUUID)
if err == nil {
m.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationMessageOutgoing)
}