feat: Ability to toggle conversation continuity via email (#3817)

Fixes: #3368
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2022-01-26 15:59:48 -08:00
committed by GitHub
parent 34e8ad9dc5
commit 59deffc7e3
9 changed files with 113 additions and 50 deletions

View File

@@ -3,6 +3,7 @@
# Table name: channel_web_widgets
#
# id :integer not null, primary key
# continuity_via_email :boolean default(TRUE), not null
# feature_flags :integer default(3), not null
# hmac_mandatory :boolean default(FALSE)
# hmac_token :string
@@ -29,7 +30,8 @@ class Channel::WebWidget < ApplicationRecord
include FlagShihTzu
self.table_name = 'channel_web_widgets'
EDITABLE_ATTRS = [:website_url, :widget_color, :welcome_title, :welcome_tagline, :reply_time, :pre_chat_form_enabled, :hmac_mandatory,
EDITABLE_ATTRS = [:website_url, :widget_color, :welcome_title, :welcome_tagline, :reply_time, :pre_chat_form_enabled,
:continuity_via_email, :hmac_mandatory,
{ pre_chat_form_options: [:pre_chat_message, :require_email] },
{ selected_feature_flags: [] }].freeze

View File

@@ -185,6 +185,14 @@ class Message < ApplicationRecord
::MessageTemplates::HookExecutionService.new(message: self).perform
end
def email_notifiable_webwidget?
inbox.web_widget? && inbox.channel.continuity_via_email
end
def email_notifiable_channel?
email_notifiable_webwidget? || %w[Email].include?(inbox.inbox_type)
end
def email_notifiable_message?
return false unless outgoing? || input_csat?
return false if private?
@@ -194,7 +202,8 @@ class Message < ApplicationRecord
def can_notify_via_mail?
return unless email_notifiable_message?
return false if conversation.contact.email.blank? || !(%w[Website Email].include? inbox.inbox_type)
return unless email_notifiable_channel?
return if conversation.contact.email.blank?
true
end