feat: Notification on new messages in conversation (#1204)
fixes: #895 fixes: #1118 fixes: #1075 Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -47,7 +47,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
context 'with a conversation' do
|
||||
it 'returns the correct conversation params' do
|
||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||
expect(conversation.user_last_seen_at).to eq(nil)
|
||||
expect(conversation.contact_last_seen_at).to eq(nil)
|
||||
|
||||
post '/api/v1/widget/conversations/update_last_seen',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
@@ -56,7 +56,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
expect(conversation.reload.user_last_seen_at).not_to eq(nil)
|
||||
expect(conversation.reload.contact_last_seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,9 +4,10 @@ RSpec.describe ConversationMailbox, type: :mailbox do
|
||||
include ActionMailbox::TestHelper
|
||||
|
||||
describe 'add mail as reply in a conversation' do
|
||||
let(:agent) { create(:user, email: 'agent1@example.com') }
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
|
||||
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
|
||||
let(:conversation) { create(:conversation, assignee: agent, inbox: create(:inbox, greeting_enabled: false)) }
|
||||
let(:conversation) { create(:conversation, assignee: agent, inbox: create(:inbox, account: account, greeting_enabled: false), account: account) }
|
||||
let(:described_subject) { described_class.receive reply_mail }
|
||||
let(:serialized_attributes) { %w[text_content html_content number_of_attachments subject date to from in_reply_to cc bcc message_id] }
|
||||
|
||||
|
||||
@@ -36,4 +36,21 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile
|
||||
expect(mail.to).to eq([agent.email])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'assigned_conversation_new_message' do
|
||||
let(:mail) { described_class.assigned_conversation_new_message(conversation, agent).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq("#{agent.available_name}, New message in your assigned conversation [ID - #{conversation.display_id}].")
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([agent.email])
|
||||
end
|
||||
|
||||
it 'will not send email if agent is online' do
|
||||
::OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id)
|
||||
expect(mail).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,9 +14,9 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
||||
end
|
||||
|
||||
context 'with summary' do
|
||||
let(:conversation) { create(:conversation, assignee: agent) }
|
||||
let(:message) { create(:message, conversation: conversation) }
|
||||
let(:private_message) { create(:message, content: 'This is a private message', conversation: conversation) }
|
||||
let(:conversation) { create(:conversation, account: account, assignee: agent) }
|
||||
let(:message) { create(:message, account: account, conversation: conversation) }
|
||||
let(:private_message) { create(:message, account: account, content: 'This is a private message', conversation: conversation) }
|
||||
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
@@ -31,6 +31,12 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
||||
expect(mail.body.decoded).not_to include(private_message.content)
|
||||
expect(mail.body.decoded).to include(message.content)
|
||||
end
|
||||
|
||||
it 'will not send email if conversation is already viewed by contact' do
|
||||
create(:message, message_type: 'outgoing', account: account, conversation: conversation)
|
||||
conversation.update(contact_last_seen_at: Time.zone.now)
|
||||
expect(mail).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'without assignee' do
|
||||
@@ -75,6 +81,12 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
||||
expect(mail.body.decoded).not_to include(message_1.content)
|
||||
expect(mail.body.decoded).to include(message_2.content)
|
||||
end
|
||||
|
||||
it 'will not send email if conversation is already viewed by contact' do
|
||||
create(:message, message_type: 'outgoing', account: account, conversation: conversation)
|
||||
conversation.update(contact_last_seen_at: Time.zone.now)
|
||||
expect(mail).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when custom domain and email is not enabled' do
|
||||
|
||||
@@ -69,7 +69,7 @@ RSpec.describe Conversation, type: :model do
|
||||
conversation.update(
|
||||
status: :resolved,
|
||||
locked: true,
|
||||
user_last_seen_at: Time.now,
|
||||
contact_last_seen_at: Time.now,
|
||||
assignee: new_assignee
|
||||
)
|
||||
end
|
||||
@@ -317,7 +317,7 @@ RSpec.describe Conversation, type: :model do
|
||||
timestamp: conversation.created_at.to_i,
|
||||
can_reply: true,
|
||||
channel: 'Channel::WebWidget',
|
||||
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
||||
contact_last_seen_at: conversation.contact_last_seen_at.to_i,
|
||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||
unread_count: 0
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ RSpec.describe Message, type: :model do
|
||||
end
|
||||
|
||||
context 'when message is created' do
|
||||
let(:message) { build(:message) }
|
||||
let(:message) { build(:message, account: create(:account)) }
|
||||
|
||||
it 'triggers ::MessageTemplates::HookExecutionService' do
|
||||
hook_execution_service = double
|
||||
@@ -23,10 +23,25 @@ RSpec.describe Message, type: :model do
|
||||
expect(hook_execution_service).to have_received(:perform)
|
||||
end
|
||||
|
||||
it 'calls notify email method on after save' do
|
||||
allow(message).to receive(:notify_via_mail).and_return(true)
|
||||
it 'calls notify email method on after save for outgoing messages' do
|
||||
allow(ConversationReplyEmailWorker).to receive(:perform_in).and_return(true)
|
||||
message.message_type = 'outgoing'
|
||||
message.save!
|
||||
expect(message).to have_received(:notify_via_mail)
|
||||
expect(ConversationReplyEmailWorker).to have_received(:perform_in)
|
||||
end
|
||||
|
||||
it 'wont call notify email method for private notes' do
|
||||
message.private = true
|
||||
allow(ConversationReplyEmailWorker).to receive(:perform_in).and_return(true)
|
||||
message.save!
|
||||
expect(ConversationReplyEmailWorker).not_to have_received(:perform_in)
|
||||
end
|
||||
|
||||
it 'wont call notify email method unless its website or email channel' do
|
||||
message.inbox = create(:inbox, account: message.account, channel: build(:channel_api, account: message.account))
|
||||
allow(ConversationReplyEmailWorker).to receive(:perform_in).and_return(true)
|
||||
message.save!
|
||||
expect(ConversationReplyEmailWorker).not_to have_received(:perform_in)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ RSpec.describe Conversations::EventDataPresenter do
|
||||
can_reply: conversation.can_reply?,
|
||||
channel: conversation.inbox.channel_type,
|
||||
timestamp: conversation.created_at.to_i,
|
||||
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
||||
contact_last_seen_at: conversation.contact_last_seen_at.to_i,
|
||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||
unread_count: 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user