Add liquid support

This commit is contained in:
Muhsin 2022-12-15 21:10:44 +05:30
parent 72fcaa739c
commit 7892b039a7
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,9 @@
class ContactDrop < BaseDrop
def email
@obj.try(:email)
end
def phone_number
@obj.try(:phone_number)
end
end

View file

@ -35,6 +35,7 @@ class Message < ApplicationRecord
NUMBER_OF_PERMITTED_ATTACHMENTS = 15
before_validation :ensure_content_type
before_create :process_liquid_in_content
validates :account_id, presence: true
validates :inbox_id, presence: true
@ -147,6 +148,19 @@ class Message < ApplicationRecord
data
end
def process_liquid_in_content
return if content.blank?
template = Liquid::Template.parse(content)
self.content = template.render({
'contact' => ContactDrop.new(conversation.contact),
'agent' => UserDrop.new(Current.user),
'conversation' => ConversationDrop.new(conversation),
'inbox' => InboxDrop.new(inbox)
})
end
def content
# move this to a presenter
return self[:content] if !input_csat? || inbox.web_widget?