-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add push/email notification support for SLA (#9140)
* feat: update SLA evaluation logic * Update enterprise/app/services/sla/evaluate_applied_sla_service.rb Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> * chore: refactor spec to bring down expecations in a single block * chore: fix process_account_applied_sla spec * chore: add spec to test multiple nrt misses * feat: persist sla notifications * feat: revert persist sla notifications * feat: add SLA push/email notification support * chore: refactor sla_status to include active_with_misses * chore: add support for sla push/email notifications * chore: refactor * chore: add liquid templates * chore: add spec for liquid templates * chore: add spec for sla email notifications * chore: add spec for SlaPolicyDrop * chore: refactor to ee namespace * chore: set enterprise test type to mailer * feat: enable sla notification settings only if SLA enabled * chore: refactor * chore: fix spec --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
- Loading branch information
1 parent
6956436
commit 16282f6
Showing
13 changed files
with
270 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...rs/agent_notifications/conversation_notifications_mailer/sla_missed_first_response.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p>Hi {{user.available_name}},</p> | ||
|
||
<p> | ||
Conversation #{{conversation.display_id}} in {{ inbox.name }} | ||
has missed the SLA for first response under policy {{ sla_policy.name }}. | ||
</p> | ||
|
||
<p> | ||
<a href="{{action_url}}">Please address immediately.</a> | ||
</p> |
10 changes: 10 additions & 0 deletions
10
...ers/agent_notifications/conversation_notifications_mailer/sla_missed_next_response.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p>Hi {{user.available_name}},</p> | ||
|
||
<p> | ||
Conversation #{{conversation.display_id}} in {{ inbox.name }} | ||
has missed the SLA for next response under policy {{ sla_policy.name }}.. | ||
</p> | ||
|
||
<p> | ||
<a href="{{action_url}}">Please address immediately.</a> | ||
</p> |
10 changes: 10 additions & 0 deletions
10
...ailers/agent_notifications/conversation_notifications_mailer/sla_missed_resolution.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p>Hi {{user.available_name}},</p> | ||
|
||
<p> | ||
Conversation #{{conversation.display_id}} in {{ inbox.name }} | ||
has missed the SLA for resolution time under policy {{ sla_policy.name }}. | ||
</p> | ||
|
||
<p> | ||
<a href="{{action_url}}">Please address immediately.</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SlaPolicyDrop < BaseDrop | ||
def name | ||
@obj.try(:name) | ||
end | ||
|
||
def description | ||
@obj.try(:description) | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
enterprise/app/mailers/enterprise/agent_notifications/conversation_notifications_mailer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Enterprise::AgentNotifications::ConversationNotificationsMailer | ||
def sla_missed_first_response(conversation, agent, sla_policy) | ||
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 | ||
|
||
def sla_missed_next_response(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 next response") and return | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Enterprise::ApplicationRecord | ||
def droppables | ||
super + %w[SlaPolicy] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
describe SlaPolicyDrop do | ||
subject(:sla_policy_drop) { described_class.new(sla_policy) } | ||
|
||
let!(:sla_policy) { create(:sla_policy) } | ||
|
||
it 'returns name' do | ||
expect(sla_policy_drop.name).to eq sla_policy.name | ||
end | ||
|
||
it 'returns description' do | ||
expect(sla_policy_drop.description).to eq sla_policy.description | ||
end | ||
end |
54 changes: 54 additions & 0 deletions
54
...terprise/mailers/enterprise/agent_notifications/conversation_notifications_mailer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'rails_helper' | ||
|
||
# rails helper is using infer filetype to detect rspec type | ||
# so we need to include type: :mailer to make this test work in enterprise namespace | ||
RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :mailer do | ||
let(:class_instance) { described_class.new } | ||
let!(:account) { create(:account) } | ||
let(:agent) { create(:user, email: 'agent1@example.com', account: account) } | ||
let(:conversation) { create(:conversation, assignee: agent, account: account) } | ||
|
||
before do | ||
allow(described_class).to receive(:new).and_return(class_instance) | ||
allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true) | ||
end | ||
|
||
describe 'sla_missed_first_response' do | ||
let(:sla_policy) { create(:sla_policy, account: account) } | ||
let(:mail) { described_class.with(account: account).sla_missed_first_response(conversation, agent, sla_policy).deliver_now } | ||
|
||
it 'renders the subject' do | ||
expect(mail.subject).to eq("Conversation [ID - #{conversation.display_id}] missed SLA for first response") | ||
end | ||
|
||
it 'renders the receiver email' do | ||
expect(mail.to).to eq([agent.email]) | ||
end | ||
end | ||
|
||
describe 'sla_missed_next_response' do | ||
let(:sla_policy) { create(:sla_policy, account: account) } | ||
let(:mail) { described_class.with(account: account).sla_missed_next_response(conversation, agent, sla_policy).deliver_now } | ||
|
||
it 'renders the subject' do | ||
expect(mail.subject).to eq("Conversation [ID - #{conversation.display_id}] missed SLA for next response") | ||
end | ||
|
||
it 'renders the receiver email' do | ||
expect(mail.to).to eq([agent.email]) | ||
end | ||
end | ||
|
||
describe 'sla_missed_resolution' do | ||
let(:sla_policy) { create(:sla_policy, account: account) } | ||
let(:mail) { described_class.with(account: account).sla_missed_resolution(conversation, agent, sla_policy).deliver_now } | ||
|
||
it 'renders the subject' do | ||
expect(mail.subject).to eq("Conversation [ID - #{conversation.display_id}] missed SLA for resolution time") | ||
end | ||
|
||
it 'renders the receiver email' do | ||
expect(mail.to).to eq([agent.email]) | ||
end | ||
end | ||
end |