From 99dfe1d5afa52eceb41773e05eb5ffaf22e58c76 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Wed, 26 Apr 2023 20:23:46 +0530 Subject: [PATCH] feat: Enable template variables in channel greeting messages (#6971) --- app/drops/account_drop.rb | 3 ++ app/helpers/email_helper.rb | 22 +++++++++++++ .../inbox/components/WeeklyAvailability.vue | 32 +++++++++++++++++-- .../shared/components/GreetingsEditor.vue | 1 + app/models/concerns/liquidable.rb | 5 +-- app/services/action_service.rb | 3 ++ .../automation_rules/action_service_spec.rb | 12 +++++++ .../template/greeting_spec.rb | 21 ++++++++++++ .../template/out_of_office_spec.rb | 17 ++++++++++ 9 files changed, 112 insertions(+), 4 deletions(-) diff --git a/app/drops/account_drop.rb b/app/drops/account_drop.rb index 2e3a2530f..d784475db 100644 --- a/app/drops/account_drop.rb +++ b/app/drops/account_drop.rb @@ -1,2 +1,5 @@ class AccountDrop < BaseDrop + def name + @obj.try(:name) + end end diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index 46689ba00..05b6a53e3 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -10,4 +10,26 @@ module EmailHelper def normalize_email_with_plus_addressing(email) "#{email.split('@').first.split('+').first}@#{email.split('@').last}".downcase end + + def parse_email_variables(conversation, email) + case email + when modified_liquid_content(email) + template = Liquid::Template.parse(modified_liquid_content(email)) + template.render(message_drops(conversation)) + when URI::MailTo::EMAIL_REGEXP + email + end + end + + def modified_liquid_content(email) + # This regex is used to match the code blocks in the content + # We don't want to process liquid in code blocks + email.gsub(/`(.*?)`/m, '{% raw %}`\\1`{% endraw %}') + end + + def message_drops(conversation) + { + 'contact' => ContactDrop.new(conversation.contact) + } + end end diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/WeeklyAvailability.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/WeeklyAvailability.vue index ecad7814b..5eee329b4 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/WeeklyAvailability.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/WeeklyAvailability.vue @@ -17,7 +17,16 @@