mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-07 21:35:38 +00:00
fix: Twilio channel selection when MessagingServiceSid is empty (#5040)
- Fixes channel selection logic in incoming_message_service for Twilio messages ref: #4242
This commit is contained in:
@@ -2,13 +2,13 @@ require 'rails_helper'
|
||||
|
||||
describe Twilio::IncomingMessageService do
|
||||
let!(:account) { create(:account) }
|
||||
let!(:twilio_sms) do
|
||||
let!(:twilio_channel) do
|
||||
create(:channel_twilio_sms, account: account, account_sid: 'ACxxx',
|
||||
inbox: create(:inbox, account: account, greeting_enabled: false))
|
||||
end
|
||||
let!(:contact) { create(:contact, account: account, phone_number: '+12345') }
|
||||
let(:contact_inbox) { create(:contact_inbox, source_id: '+12345', contact: contact, inbox: twilio_sms.inbox) }
|
||||
let!(:conversation) { create(:conversation, contact: contact, inbox: twilio_sms.inbox, contact_inbox: contact_inbox) }
|
||||
let(:contact_inbox) { create(:contact_inbox, source_id: '+12345', contact: contact, inbox: twilio_channel.inbox) }
|
||||
let!(:conversation) { create(:conversation, contact: contact, inbox: twilio_channel.inbox, contact_inbox: contact_inbox) }
|
||||
|
||||
describe '#perform' do
|
||||
it 'creates a new message in existing conversation' do
|
||||
@@ -16,7 +16,7 @@ describe Twilio::IncomingMessageService do
|
||||
SmsSid: 'SMxx',
|
||||
From: '+12345',
|
||||
AccountSid: 'ACxxx',
|
||||
MessagingServiceSid: twilio_sms.messaging_service_sid,
|
||||
MessagingServiceSid: twilio_channel.messaging_service_sid,
|
||||
Body: 'testing3'
|
||||
}
|
||||
|
||||
@@ -29,16 +29,16 @@ describe Twilio::IncomingMessageService do
|
||||
SmsSid: 'SMxx',
|
||||
From: '+123456',
|
||||
AccountSid: 'ACxxx',
|
||||
MessagingServiceSid: twilio_sms.messaging_service_sid,
|
||||
MessagingServiceSid: twilio_channel.messaging_service_sid,
|
||||
Body: 'new conversation'
|
||||
}
|
||||
|
||||
described_class.new(params: params).perform
|
||||
expect(Conversation.count).to eq(2)
|
||||
expect(twilio_channel.inbox.conversations.count).to eq(2)
|
||||
end
|
||||
|
||||
context 'with a phone number' do
|
||||
let!(:twilio_sms) do
|
||||
let!(:twilio_channel) do
|
||||
create(:channel_twilio_sms, :with_phone_number, account: account, account_sid: 'ACxxx',
|
||||
inbox: create(:inbox, account: account, greeting_enabled: false))
|
||||
end
|
||||
@@ -48,7 +48,7 @@ describe Twilio::IncomingMessageService do
|
||||
SmsSid: 'SMxx',
|
||||
From: '+12345',
|
||||
AccountSid: 'ACxxx',
|
||||
To: twilio_sms.phone_number,
|
||||
To: twilio_channel.phone_number,
|
||||
Body: 'testing3'
|
||||
}
|
||||
|
||||
@@ -61,12 +61,37 @@ describe Twilio::IncomingMessageService do
|
||||
SmsSid: 'SMxx',
|
||||
From: '+123456',
|
||||
AccountSid: 'ACxxx',
|
||||
To: twilio_sms.phone_number,
|
||||
To: twilio_channel.phone_number,
|
||||
Body: 'new conversation'
|
||||
}
|
||||
|
||||
described_class.new(params: params).perform
|
||||
expect(Conversation.count).to eq(2)
|
||||
expect(twilio_channel.inbox.conversations.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with multiple channels configured' do
|
||||
before do
|
||||
2.times.each do
|
||||
create(:channel_twilio_sms, :with_phone_number, account: account, account_sid: 'ACxxx', messaging_service_sid: nil,
|
||||
inbox: create(:inbox, account: account, greeting_enabled: false))
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a new conversation in appropriate channel' do
|
||||
twilio_sms_channel = create(:channel_twilio_sms, :with_phone_number, account: account, account_sid: 'ACxxx',
|
||||
inbox: create(:inbox, account: account, greeting_enabled: false))
|
||||
|
||||
params = {
|
||||
SmsSid: 'SMxx',
|
||||
From: '+123456',
|
||||
AccountSid: 'ACxxx',
|
||||
To: twilio_sms_channel.phone_number,
|
||||
Body: 'new conversation'
|
||||
}
|
||||
|
||||
described_class.new(params: params).perform
|
||||
expect(twilio_sms_channel.inbox.conversations.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user