mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 04:27:53 +00:00
fix: Send push notification on bot_handoff (#7636)
Send a 'Conversation Created' push notification when the bot does a hand_off. fixes: #7587 Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -1,4 +1,18 @@
|
|||||||
class NotificationListener < BaseListener
|
class NotificationListener < BaseListener
|
||||||
|
def conversation_bot_handoff(event)
|
||||||
|
conversation, account = extract_conversation_and_account(event)
|
||||||
|
return if conversation.pending?
|
||||||
|
|
||||||
|
conversation.inbox.members.each do |agent|
|
||||||
|
NotificationBuilder.new(
|
||||||
|
notification_type: 'conversation_creation',
|
||||||
|
user: agent,
|
||||||
|
account: account,
|
||||||
|
primary_actor: conversation
|
||||||
|
).perform
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def conversation_created(event)
|
def conversation_created(event)
|
||||||
conversation, account = extract_conversation_and_account(event)
|
conversation, account = extract_conversation_and_account(event)
|
||||||
return if conversation.pending?
|
return if conversation.pending?
|
||||||
|
|||||||
@@ -119,4 +119,40 @@ describe NotificationListener do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'conversation_bot_handoff' do
|
||||||
|
let(:event_name) { :'conversation.bot_handoff' }
|
||||||
|
|
||||||
|
context 'when conversation is bot handoff' do
|
||||||
|
it 'creates notifications for inbox members who have notifications turned on' do
|
||||||
|
notification_setting = first_agent.notification_settings.first
|
||||||
|
notification_setting.selected_email_flags = [:email_conversation_creation]
|
||||||
|
notification_setting.selected_push_flags = []
|
||||||
|
notification_setting.save!
|
||||||
|
|
||||||
|
create(:inbox_member, user: first_agent, inbox: inbox)
|
||||||
|
conversation.reload
|
||||||
|
|
||||||
|
event = Events::Base.new(event_name, Time.zone.now, conversation: conversation)
|
||||||
|
|
||||||
|
listener.conversation_bot_handoff(event)
|
||||||
|
expect(notification_setting.user.notifications.count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create notification for inbox members who have notifications turned off' do
|
||||||
|
notification_setting = agent_with_out_notification.notification_settings.first
|
||||||
|
notification_setting.unselect_all_email_flags
|
||||||
|
notification_setting.unselect_all_push_flags
|
||||||
|
notification_setting.save!
|
||||||
|
|
||||||
|
create(:inbox_member, user: agent_with_out_notification, inbox: inbox)
|
||||||
|
conversation.reload
|
||||||
|
|
||||||
|
event = Events::Base.new(event_name, Time.zone.now, conversation: conversation)
|
||||||
|
|
||||||
|
listener.conversation_bot_handoff(event)
|
||||||
|
expect(notification_setting.user.notifications.count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user