feat: Support multiple emails in email transcript automation (#6924)

This commit is contained in:
Tejaswini Chile
2023-04-19 16:55:25 +05:30
committed by GitHub
parent 821d49943a
commit 5cdc7d654a
3 changed files with 18 additions and 71 deletions

View File

@@ -52,6 +52,8 @@ class ActionService
end
def send_email_transcript(emails)
emails = emails[0].gsub(/\s+/, '').split(',')
emails.each do |email|
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later
end

View File

@@ -121,18 +121,6 @@ describe AutomationRuleListener do
expect(conversation.assignee).to eq(user_1)
end
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
listener.conversation_updated(event)
conversation.reload
allow(mailer).to receive(:conversation_transcript)
end
it 'triggers automation rule send message to the contacts' do
expect(conversation.messages).to be_empty
@@ -253,15 +241,6 @@ describe AutomationRuleListener do
expect(conversation.assignee).to eq(user_1)
end
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
listener.conversation_updated(event)
conversation.reload
allow(mailer).to receive(:conversation_transcript)
end
it 'triggers automation rule send email to the team' do
message_delivery = instance_double(ActionMailer::MessageDelivery)
@@ -457,15 +436,6 @@ describe AutomationRuleListener do
expect(conversation.assignee).to eq(user_1)
end
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
listener.conversation_opened(event)
conversation.reload
allow(mailer).to receive(:conversation_transcript)
end
it 'triggers automation rule send email to the team' do
message_delivery = instance_double(ActionMailer::MessageDelivery)
@@ -577,15 +547,6 @@ describe AutomationRuleListener do
expect(conversation.assignee).to eq(user_1)
end
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
listener.message_created(event)
conversation.reload
allow(mailer).to receive(:conversation_transcript)
end
end
end
@@ -616,17 +577,6 @@ describe AutomationRuleListener do
end
context 'when rule matches' do
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
allow(mailer).to receive(:conversation_transcript)
listener.message_created(event)
conversation.reload
expect(mailer).to have_received(:conversation_transcript).with(conversation, 'new_agent@example.com')
end
it 'triggers automation rule send message to the contacts' do
expect(conversation.messages.count).to eq(1)
listener.message_created(event)
@@ -710,18 +660,6 @@ describe AutomationRuleListener do
end
context 'when rule matches' do
it 'triggers automation rule send email transcript to the mentioned email' do
mailer = double
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
allow(mailer).to receive(:conversation_transcript)
listener.conversation_created(event)
conversation.reload
expect(mailer).to have_received(:conversation_transcript).with(conversation, 'new_agent@example.com')
end
it 'triggers automation rule send message to the contacts' do
expect(conversation.messages.count).to eq(1)
@@ -781,15 +719,6 @@ describe AutomationRuleListener do
let(:event) { Events::Base.new('message_created', Time.zone.now, { conversation: tweet, message: message }) }
let!(:message) { create(:message, account: account, conversation: tweet, message_type: 'incoming') }
it 'triggers automation rule except send_message and send_attachment' do
mailer = double
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
allow(mailer).to receive(:conversation_transcript)
listener.message_created(event)
expect(mailer).to have_received(:conversation_transcript).with(tweet, 'new_agent@example.com')
end
it 'does not triggers automation rule send message or send attachment' do
expect(tweet.messages.count).to eq(1)

View File

@@ -87,5 +87,21 @@ RSpec.describe AutomationRules::ActionService do
described_class.new(rule, account, conversation).perform
end
end
describe '#perform with send_email_transcript action' do
before do
rule.actions << { action_name: 'send_email_transcript', action_params: ['contact@example.com, agent@example.com,agent1@example.com'] }
end
it 'will send email to transcript to action params emails' do
mailer = double
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
allow(mailer).to receive(:conversation_transcript).with(conversation, 'contact@example.com')
allow(mailer).to receive(:conversation_transcript).with(conversation, 'agent@example.com')
allow(mailer).to receive(:conversation_transcript).with(conversation, 'agent1@example.com')
described_class.new(rule, account, conversation).perform
end
end
end
end