feat: support reply to for incoming messages on facebook (#8076)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -60,6 +60,7 @@ class Message < ApplicationRecord
|
||||
|
||||
before_validation :ensure_content_type
|
||||
before_save :ensure_processed_message_content
|
||||
before_save :ensure_in_reply_to
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :inbox_id, presence: true
|
||||
@@ -233,6 +234,20 @@ class Message < ApplicationRecord
|
||||
self.processed_message_content = message_content&.truncate(150_000)
|
||||
end
|
||||
|
||||
# fetch the in_reply_to message and set the external id
|
||||
def ensure_in_reply_to
|
||||
in_reply_to = content_attributes[:in_reply_to]
|
||||
in_reply_to_external_id = content_attributes[:in_reply_to_external_id]
|
||||
|
||||
if in_reply_to.present? && in_reply_to_external_id.blank?
|
||||
message = conversation.messages.find_by(id: in_reply_to)
|
||||
content_attributes[:in_reply_to_external_id] = message.try(:source_id)
|
||||
elsif in_reply_to_external_id.present? && in_reply_to.blank?
|
||||
message = conversation.messages.find_by(source_id: in_reply_to_external_id)
|
||||
content_attributes[:in_reply_to] = message.try(:id)
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_content_type
|
||||
self.content_type ||= Message.content_types[:text]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user