feat: support reply to for incoming messages on facebook (#8076)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Shivam Mishra
2023-10-13 16:33:50 +05:30
committed by GitHub
parent 7b09fa4a03
commit 62d8ec7edb
7 changed files with 83 additions and 3 deletions

View File

@@ -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