Voice calling is now a capability on the existing TwilioSms rather than a separate Voice model. A single Twilio phone number handles both SMS and voice calls through one inbox. Fixes https://linear.app/chatwoot/issue/CW-6683/add-voice-calling-as-a-capability-on-twilio-sms-channel and https://linear.app/chatwoot/issue/PLA-120/add-the-support-for-sms **What changed** - Replaced Channel::Voice with voice_enabled flag on Channel::TwilioSms - Added voice_enabled, twiml_app_sid, api_key_secret columns to channel_twilio_sms table - Dropped channel_voice table (no production data) - All voice logic lives in Enterprise layer via prepend_mod_with('Channel::TwilioSms') - Added Voice settings tab on Twilio SMS inbox settings to enable/disable voice - Validates Twilio number voice capability before provisioning - Teardown service cleans up TwiML app and credentials when voice is disabled - Frontend voice detection uses isVoiceCallEnabled() / getVoiceCallProvider() helpers — extensible to future providers - Gated by channel_voice feature flag **How to test** 1. Enable feature flag: Account.find(<id>).enable_features('channel_voice') 2. Create voice inbox: Inboxes → Voice tile → enter Twilio credentials → verify incoming/outgoing calls and SMS work 3. Enable voice on existing SMS inbox: Inboxes → select Twilio SMS inbox → Voice tab → toggle on → provide API key credentials → verify calls work 4. Disable voice: Voice tab → toggle off → verify TwiML app is deleted, credentials cleared, SMS still works 5. Re-enable voice: Toggle on again → must provide api_key_secret again → new TwiML app provisioned --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
81 lines
2.4 KiB
Ruby
81 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Voice::StatusUpdateService do
|
|
let(:account) { create(:account) }
|
|
let!(:contact) { create(:contact, account: account, phone_number: from_number) }
|
|
let(:contact_inbox) { ContactInbox.create!(contact: contact, inbox: inbox, source_id: from_number) }
|
|
let(:conversation) do
|
|
Conversation.create!(
|
|
account_id: account.id,
|
|
inbox_id: inbox.id,
|
|
contact_id: contact.id,
|
|
contact_inbox_id: contact_inbox.id,
|
|
identifier: call_sid,
|
|
additional_attributes: { 'call_direction' => 'inbound', 'call_status' => 'ringing' }
|
|
)
|
|
end
|
|
let(:message) do
|
|
conversation.messages.create!(
|
|
account_id: account.id,
|
|
inbox_id: inbox.id,
|
|
message_type: :incoming,
|
|
sender: contact,
|
|
content: 'Voice Call',
|
|
content_type: 'voice_call',
|
|
content_attributes: { data: { call_sid: call_sid, status: 'ringing' } }
|
|
)
|
|
end
|
|
let(:channel) { create(:channel_twilio_sms, :with_voice, account: account, phone_number: '+15551230002') }
|
|
let(:inbox) { channel.inbox }
|
|
let(:from_number) { '+15550002222' }
|
|
let(:call_sid) { 'CATESTSTATUS123' }
|
|
|
|
before do
|
|
allow(Twilio::VoiceWebhookSetupService).to receive(:new)
|
|
.and_return(instance_double(Twilio::VoiceWebhookSetupService, perform: "AP#{SecureRandom.hex(16)}"))
|
|
end
|
|
|
|
it 'updates conversation and last voice message with call status' do
|
|
# Ensure records are created after stub setup
|
|
conversation
|
|
message
|
|
|
|
described_class.new(
|
|
account: account,
|
|
call_sid: call_sid,
|
|
call_status: 'completed'
|
|
).perform
|
|
|
|
conversation.reload
|
|
message.reload
|
|
|
|
expect(conversation.additional_attributes['call_status']).to eq('completed')
|
|
expect(message.content_attributes.dig('data', 'status')).to eq('completed')
|
|
end
|
|
|
|
it 'normalizes busy to no-answer' do
|
|
conversation
|
|
message
|
|
|
|
described_class.new(
|
|
account: account,
|
|
call_sid: call_sid,
|
|
call_status: 'busy'
|
|
).perform
|
|
|
|
conversation.reload
|
|
message.reload
|
|
|
|
expect(conversation.additional_attributes['call_status']).to eq('no-answer')
|
|
expect(message.content_attributes.dig('data', 'status')).to eq('no-answer')
|
|
end
|
|
|
|
it 'no-ops when conversation not found' do
|
|
expect do
|
|
described_class.new(account: account, call_sid: 'UNKNOWN', call_status: 'busy').perform
|
|
end.not_to raise_error
|
|
end
|
|
end
|