feat: Add CSAT Message Template Hooks (#2494)
This commit is contained in:
@@ -67,11 +67,11 @@ class Inbox < ApplicationRecord
|
||||
end
|
||||
|
||||
def facebook?
|
||||
channel.class.name.to_s == 'Channel::FacebookPage'
|
||||
channel_type == 'Channel::FacebookPage'
|
||||
end
|
||||
|
||||
def web_widget?
|
||||
channel.class.name.to_s == 'Channel::WebWidget'
|
||||
channel_type == 'Channel::WebWidget'
|
||||
end
|
||||
|
||||
def inbox_type
|
||||
|
||||
@@ -5,11 +5,7 @@ class MessageTemplates::HookExecutionService
|
||||
return if inbox.agent_bot_inbox&.active?
|
||||
return if conversation.campaign.present?
|
||||
|
||||
# TODO: let's see whether this is needed and remove this and related logic if not
|
||||
# ::MessageTemplates::Template::OutOfOffice.new(conversation: conversation).perform if should_send_out_of_office_message?
|
||||
|
||||
::MessageTemplates::Template::Greeting.new(conversation: conversation).perform if should_send_greeting?
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if inbox.enable_email_collect && should_send_email_collect?
|
||||
trigger_templates
|
||||
end
|
||||
|
||||
private
|
||||
@@ -17,6 +13,14 @@ class MessageTemplates::HookExecutionService
|
||||
delegate :inbox, :conversation, to: :message
|
||||
delegate :contact, to: :conversation
|
||||
|
||||
def trigger_templates
|
||||
# TODO: let's see whether this is needed and remove this and related logic if not
|
||||
# ::MessageTemplates::Template::OutOfOffice.new(conversation: conversation).perform if should_send_out_of_office_message?
|
||||
::MessageTemplates::Template::Greeting.new(conversation: conversation).perform if should_send_greeting?
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if inbox.enable_email_collect && should_send_email_collect?
|
||||
::MessageTemplates::Template::CsatSurvey.new(conversation: conversation).perform if should_send_csat_survey?
|
||||
end
|
||||
|
||||
def should_send_out_of_office_message?
|
||||
inbox.out_of_office? && conversation.messages.today.template.empty? && inbox.out_of_office_message.present?
|
||||
end
|
||||
@@ -41,4 +45,21 @@ class MessageTemplates::HookExecutionService
|
||||
def contact_has_email?
|
||||
contact.email
|
||||
end
|
||||
|
||||
def csat_enabled_inbox?
|
||||
# for now csat only available in web widget channel
|
||||
return unless inbox.web_widget?
|
||||
return unless inbox.csat_survey_enabled?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def should_send_csat_survey?
|
||||
return unless conversation.resolved?
|
||||
return unless csat_enabled_inbox?
|
||||
# only send CSAT once in a conversation
|
||||
return if conversation.messages.where(content_type: :input_csat).present?
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
24
app/services/message_templates/template/csat_survey.rb
Normal file
24
app/services/message_templates/template/csat_survey.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class MessageTemplates::Template::CsatSurvey
|
||||
pattr_initialize [:conversation!]
|
||||
|
||||
def perform
|
||||
ActiveRecord::Base.transaction do
|
||||
conversation.messages.create!(csat_survey_message_params)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
delegate :contact, :account, to: :conversation
|
||||
delegate :inbox, to: :message
|
||||
|
||||
def csat_survey_message_params
|
||||
{
|
||||
account_id: @conversation.account_id,
|
||||
inbox_id: @conversation.inbox_id,
|
||||
message_type: :template,
|
||||
content_type: :input_csat,
|
||||
content: I18n.t('conversations.templates.csat_input_message_body')
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user