Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
2.0 KiB
Ruby
63 lines
2.0 KiB
Ruby
module MailMerge
|
|
TOKEN = /\{\{\s*([a-z0-9_.]+)\s*\}\}/i
|
|
|
|
class << self
|
|
def catalog
|
|
{
|
|
"societa" => "Nome società",
|
|
"regione" => "Regione",
|
|
"provincia" => "Provincia",
|
|
"citta" => "Città",
|
|
"email" => "Email",
|
|
"sito" => "Sito / profilo",
|
|
"sport" => "Sport",
|
|
"mf" => "M/F",
|
|
"streaming" => "Streaming rilevato",
|
|
"fit" => "Fit commerciale",
|
|
"n_lista" => "N. in lista",
|
|
"contatto_nome" => "Nome contatto",
|
|
"contatto_ruolo" => "Ruolo contatto",
|
|
"contatto_email" => "Email contatto",
|
|
"test_ab" => "Test A/B",
|
|
"progetto" => "Nome progetto",
|
|
"piano" => "Piano / prodotto"
|
|
}
|
|
end
|
|
|
|
def variables_for(organization: nil, contact: nil, project: nil, opportunity: nil, ab_variant: nil)
|
|
org = organization
|
|
contact ||= org&.primary_contact || org&.contacts&.first
|
|
opportunity ||= org&.campaign_opportunity(project) if org && project
|
|
|
|
{
|
|
"societa" => org&.name,
|
|
"organizzazione.nome" => org&.name,
|
|
"regione" => org&.region,
|
|
"provincia" => org&.province,
|
|
"citta" => org&.city,
|
|
"email" => (contact&.email.presence || org&.email),
|
|
"sito" => org&.website,
|
|
"sport" => org&.sport,
|
|
"mf" => org&.team_gender_label,
|
|
"streaming" => org&.streaming_status_label,
|
|
"fit" => org&.commercial_fit,
|
|
"n_lista" => org&.list_position,
|
|
"contatto_nome" => contact&.full_name,
|
|
"contatto_ruolo" => contact&.role,
|
|
"contatto_email" => contact&.email,
|
|
"test_ab" => ab_variant.presence || opportunity&.ab_variant,
|
|
"progetto" => project&.name,
|
|
"piano" => opportunity&.product
|
|
}.transform_values { |value| value.to_s }
|
|
end
|
|
|
|
def render(template, **context)
|
|
vars = variables_for(**context)
|
|
template.to_s.gsub(TOKEN) do
|
|
key = Regexp.last_match(1).to_s.downcase
|
|
vars[key].to_s
|
|
end
|
|
end
|
|
end
|
|
end
|