fix: Send CSAT survey only when agent can reply in conversation (#11584)
Fixes https://github.com/chatwoot/chatwoot/issues/11569 ## Problem On platforms like WhatsApp and Facebook Messenger, customers cannot reply to messages after 24 hours (or other channel-specific messaging windows). Despite this limitation, the system continued sending CSAT surveys to customers outside their messaging window, making it impossible for them to respond. ## Solution Added a check for `conversation.can_reply?` in the `should_send_csat_survey?` method. This leverages the existing `MessageWindowService` which already handles all channel-specific messaging window logic.
This commit is contained in:
@@ -17,7 +17,7 @@ class MessageTemplates::HookExecutionService
|
||||
::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?
|
||||
handle_csat_survey
|
||||
end
|
||||
|
||||
def should_send_out_of_office_message?
|
||||
@@ -65,13 +65,26 @@ class MessageTemplates::HookExecutionService
|
||||
true
|
||||
end
|
||||
|
||||
def should_send_csat_survey?
|
||||
def handle_csat_survey
|
||||
return unless csat_enabled_conversation?
|
||||
|
||||
# only send CSAT once in a conversation
|
||||
return if conversation.messages.where(content_type: :input_csat).present?
|
||||
return if csat_already_sent?
|
||||
|
||||
true
|
||||
# Only send CSAT if agent can still reply by checking the messaging window restriction
|
||||
# https://www.chatwoot.com/docs/self-hosted/supported-features#outgoing-message-restriction
|
||||
if within_messaging_window?
|
||||
::MessageTemplates::Template::CsatSurvey.new(conversation: conversation).perform
|
||||
else
|
||||
conversation.create_csat_not_sent_activity_message
|
||||
end
|
||||
end
|
||||
|
||||
def csat_already_sent?
|
||||
conversation.messages.where(content_type: :input_csat).present?
|
||||
end
|
||||
|
||||
def within_messaging_window?
|
||||
conversation.can_reply?
|
||||
end
|
||||
end
|
||||
MessageTemplates::HookExecutionService.prepend_mod_with('MessageTemplates::HookExecutionService')
|
||||
|
||||
Reference in New Issue
Block a user