feat: Add the support for custom attributes in message variables (#8511)

This commit is contained in:
Muhsin Keloth
2023-12-09 03:43:35 +05:30
committed by GitHub
parent bf49a17efa
commit b1a68759cf
4 changed files with 36 additions and 3 deletions

View File

@@ -2,8 +2,8 @@ require 'rails_helper'
shared_examples_for 'liqudable' do
context 'when liquid is present in content' do
let(:contact) { create(:contact, name: 'john', phone_number: '+912883') }
let(:conversation) { create(:conversation, id: 1, contact: contact) }
let(:contact) { create(:contact, name: 'john', phone_number: '+912883', custom_attributes: { customer_type: 'platinum' }) }
let(:conversation) { create(:conversation, id: 1, contact: contact, custom_attributes: { priority: 'high' }) }
context 'when message is incoming' do
let(:message) { build(:message, conversation: conversation, message_type: 'incoming') }
@@ -24,6 +24,14 @@ shared_examples_for 'liqudable' do
expect(message.content).to eq 'hey John how are you?'
end
it 'set replaces liquid custom attributes in message' do
message.content = 'Are you a {{contact.custom_attribute.customer_type}} customer,
If yes then the priority is {{conversation.custom_attribute.priority}}'
message.save!
expect(message.content).to eq 'Are you a platinum customer,
If yes then the priority is high'
end
it 'process liquid operators like default value' do
message.content = 'Can we send you an email at {{ contact.email | default: "default" }} ?'
message.save!