chore: Disable message hooks for conversations without incoming message (#7620)

When using client APIs to create conversations and auto-assignment is turned on, welcome messages were getting triggered. This PR disable the behaviour and ensure template hooks are triggered only if there are incoming messages present. 

Fixes: https://linear.app/chatwoot/issue/CW-2187
This commit is contained in:
Sojan Jose
2023-07-26 20:38:49 +03:00
committed by GitHub
parent 6c1ee4d965
commit 6cbe1ed911
4 changed files with 26 additions and 11 deletions

View File

@@ -60,11 +60,7 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
def sent_first_outgoing_message_after_24_hours?
# we can send max 1 message after 24 hour window
conversation.messages.outgoing.where('id > ?', last_incoming_message.id).count == 1
end
def last_incoming_message
conversation.messages.incoming.last
conversation.messages.outgoing.where('id > ?', conversation.last_incoming_message.id).count == 1
end
def handle_facebook_error(exception)

View File

@@ -90,11 +90,7 @@ class Instagram::SendOnInstagramService < Base::SendOnChannelService
def sent_first_outgoing_message_after_24_hours?
# we can send max 1 message after 24 hour window
conversation.messages.outgoing.where('id > ?', last_incoming_message.id).count == 1
end
def last_incoming_message
conversation.messages.incoming.last
conversation.messages.outgoing.where('id > ?', conversation.last_incoming_message.id).count == 1
end
def config

View File

@@ -3,6 +3,7 @@ class MessageTemplates::HookExecutionService
def perform
return if conversation.campaign.present?
return if conversation.last_incoming_message.blank?
trigger_templates
end