Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
97 lines
2.6 KiB
Ruby
97 lines
2.6 KiB
Ruby
module Liquidable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_create :process_liquid_in_content
|
|
before_create :process_liquid_in_template_params
|
|
end
|
|
|
|
private
|
|
|
|
def message_drops
|
|
{
|
|
'contact' => ContactDrop.new(conversation.contact),
|
|
'agent' => UserDrop.new(sender),
|
|
'conversation' => ConversationDrop.new(conversation),
|
|
'inbox' => InboxDrop.new(inbox),
|
|
'account' => AccountDrop.new(conversation.account)
|
|
}
|
|
end
|
|
|
|
def liquid_processable_message?
|
|
content.present? && (message_type == 'outgoing' || message_type == 'template')
|
|
end
|
|
|
|
def process_liquid_in_content
|
|
return unless liquid_processable_message?
|
|
|
|
template = Liquid::Template.parse(modified_liquid_content)
|
|
self.content = template.render(message_drops)
|
|
rescue Liquid::Error
|
|
# If there is an error in the liquid syntax, we don't want to process it
|
|
end
|
|
|
|
def modified_liquid_content
|
|
# This regex is used to match the code blocks in the content
|
|
# We don't want to process liquid in code blocks
|
|
content.gsub(/`(.*?)`/m, '{% raw %}`\\1`{% endraw %}')
|
|
end
|
|
|
|
def process_liquid_in_template_params
|
|
return unless template_params_present? && liquid_processable_template_params?
|
|
|
|
processed_params = process_liquid_in_hash(template_params_data['processed_params'])
|
|
|
|
# Update the additional_attributes with processed template_params
|
|
self.additional_attributes = additional_attributes.merge(
|
|
'template_params' => template_params_data.merge('processed_params' => processed_params)
|
|
)
|
|
rescue Liquid::Error
|
|
# If there is an error in the liquid syntax, we don't want to process it
|
|
end
|
|
|
|
def template_params_present?
|
|
additional_attributes&.dig('template_params', 'processed_params').present?
|
|
end
|
|
|
|
def liquid_processable_template_params?
|
|
message_type == 'outgoing' || message_type == 'template'
|
|
end
|
|
|
|
def template_params_data
|
|
additional_attributes['template_params']
|
|
end
|
|
|
|
def process_liquid_in_hash(hash)
|
|
return hash unless hash.is_a?(Hash)
|
|
|
|
hash.transform_values { |value| process_liquid_value(value) }
|
|
end
|
|
|
|
def process_liquid_value(value)
|
|
case value
|
|
when String
|
|
process_liquid_string(value)
|
|
when Hash
|
|
process_liquid_in_hash(value)
|
|
when Array
|
|
process_liquid_array(value)
|
|
else
|
|
value
|
|
end
|
|
end
|
|
|
|
def process_liquid_array(array)
|
|
array.map { |item| process_liquid_value(item) }
|
|
end
|
|
|
|
def process_liquid_string(string)
|
|
return string if string.blank?
|
|
|
|
template = Liquid::Template.parse(string)
|
|
template.render(message_drops)
|
|
rescue Liquid::Error
|
|
string
|
|
end
|
|
end
|