chore: Add open conversation option (#11828)
Added conversation_status, assignee_id, team_id, and priority to the message_created event to allow users to build automations based on conversation details. Also introduced a new open_conversation action. --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -171,6 +171,16 @@ describe AutomationRuleListener do
|
||||
listener.message_created(event)
|
||||
expect(AutomationRules::ActionService).not_to have_received(:new).with(automation_rule, account, conversation)
|
||||
end
|
||||
|
||||
it 'passes conversation attributes to conditions filter service' do
|
||||
conversation.update!(status: :open, priority: :high)
|
||||
listener.message_created(event)
|
||||
expect(AutomationRules::ConditionsFilterService).to have_received(:new).with(
|
||||
automation_rule,
|
||||
conversation,
|
||||
{ message: message, changed_attributes: { content: %w[nil Hi] } }
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,17 @@ describe ActionService do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#open_conversation' do
|
||||
let(:conversation) { create(:conversation, status: :resolved) }
|
||||
let(:action_service) { described_class.new(conversation) }
|
||||
|
||||
it 'opens the conversation' do
|
||||
expect(conversation.status).to eq('resolved')
|
||||
action_service.open_conversation(nil)
|
||||
expect(conversation.reload.status).to eq('open')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#change_priority' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
let(:action_service) { described_class.new(conversation) }
|
||||
|
||||
@@ -110,6 +110,29 @@ RSpec.describe AutomationRules::ConditionsFilterService do
|
||||
expect(described_class.new(rule, conversation, { message: message, changed_attributes: {} }).perform).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when filtering messages based on conversation attributes' do
|
||||
let(:conversation) { create(:conversation, account: account, status: :open, priority: :high) }
|
||||
let(:message) do
|
||||
create(:message, account: account, conversation: conversation, content: 'Test message',
|
||||
inbox: conversation.inbox, message_type: :incoming)
|
||||
end
|
||||
|
||||
it 'will return true when conversation status matches' do
|
||||
rule.update(conditions: [{ 'values': ['open'], 'attribute_key': 'status', 'query_operator': nil, 'filter_operator': 'equal_to' }])
|
||||
expect(described_class.new(rule, conversation, { message: message, changed_attributes: {} }).perform).to be(true)
|
||||
end
|
||||
|
||||
it 'will return false when conversation status does not match' do
|
||||
rule.update(conditions: [{ 'values': ['resolved'], 'attribute_key': 'status', 'query_operator': nil, 'filter_operator': 'equal_to' }])
|
||||
expect(described_class.new(rule, conversation, { message: message, changed_attributes: {} }).perform).to be(false)
|
||||
end
|
||||
|
||||
it 'will return true when conversation priority matches' do
|
||||
rule.update(conditions: [{ 'values': ['high'], 'attribute_key': 'priority', 'query_operator': nil, 'filter_operator': 'equal_to' }])
|
||||
expect(described_class.new(rule, conversation, { message: message, changed_attributes: {} }).perform).to be(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user