fix: add digest methods

This commit is contained in:
Shivam Mishra
2024-04-08 19:53:07 +05:30
parent f45f357e16
commit 6da2795b2c
2 changed files with 68 additions and 25 deletions
@@ -0,0 +1,51 @@
<p>Hello {{ user.available_name }},</p>
<p>This is a digest of the missed SLAs in your conversations:</p>
{% for conversation, missed_slas in missed_slas_by_conversation %}
<div style='margin-bottom: 20px;'>
<h3>Conversation: {{ conversation.display_id }}</h3>
<table style='width: 100%; border-collapse: collapse;'>
<thead>
<tr>
<th style='text-align: left; border-bottom: 1px solid #ccc; padding: 5px;'>
SLA Policy
</th>
<th style='text-align: left; border-bottom: 1px solid #ccc; padding: 5px;'>
Missed Event
</th>
<th style='text-align: left; border-bottom: 1px solid #ccc; padding: 5px;'>
Missed At
</th>
</tr>
</thead>
<tbody>
{% for missed_sla in missed_slas %}
{% for sla_event in missed_sla.sla_events %}
<tr>
<td style='padding: 5px;'>
{{ missed_sla.applied_sla.sla_policy.name }}
</td>
<td style='padding: 5px;'>{{ sla_event.event }}</td>
<td style='padding: 5px;'>
{{ sla_event.created_at | date: '%b %d, %Y %I:%M %p' }}
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
<p>
<a href='{{ conversation_url }}' target='_blank'>View Conversation</a>
</p>
</div>
{% endfor %}
<p>
Please take the necessary actions to address these missed SLAs and ensure
timely responses to the conversations.
</p>
<p>
Best regards,<br>
Your SLA Monitoring System
</p>
@@ -1,38 +1,30 @@
module Enterprise::AgentNotifications::ConversationNotificationsMailer
def sla_missed_first_response(conversation, agent, sla_policy)
def missed_slas_digest(user, missed_slas)
return unless smtp_config_set_or_development?
@agent = agent
@conversation = conversation
@sla_policy = sla_policy
subject = "Conversation [ID - #{@conversation.display_id}] missed SLA for first response"
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
send_mail_with_liquid(to: @agent.email, subject: subject) and return
end
@user = user
@missed_slas = missed_slas
subject = 'Missed SLAs Digest'
def sla_missed_next_response(conversation, agent, sla_policy)
return unless smtp_config_set_or_development?
# Group missed SLAs by conversation using each_with_object
@missed_slas_by_conversation = @missed_slas.each_with_object({}) do |missed_sla, result|
applied_sla = missed_sla[:applied_sla]
sla_events = missed_sla[:sla_events]
conversation = applied_sla.conversation
@agent = agent
@conversation = conversation
@sla_policy = sla_policy
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
send_mail_with_liquid(to: @agent.email, subject: "Conversation [ID - #{@conversation.display_id}] missed SLA for next response") and return
end
result[conversation] ||= []
result[conversation] << {
sla_events: sla_events,
applied_sla: applied_sla
}
end
def sla_missed_resolution(conversation, agent, sla_policy)
return unless smtp_config_set_or_development?
@agent = agent
@conversation = conversation
@sla_policy = sla_policy
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
send_mail_with_liquid(to: @agent.email, subject: "Conversation [ID - #{@conversation.display_id}] missed SLA for resolution time") and return
send_mail_with_liquid(to: @user.email, subject: subject) and return
end
def liquid_droppables
super.merge({
sla_policy: @sla_policy
missed_slas_by_conversation: @missed_slas_by_conversation
})
end
end