fix(whatsapp): restrict voice_enabled? to embedded-signup whatsapp_cloud channels

This commit is contained in:
Tanmay Deep Sharma
2026-04-30 19:10:06 +07:00
parent 2c025755e2
commit 1c945899c7
2 changed files with 33 additions and 1 deletions
+5 -1
View File
@@ -41,8 +41,12 @@ class Channel::Whatsapp < ApplicationRecord
end
# Mirrors Channel::TwilioSms#voice_enabled? so the call subsystem can duck-type across providers.
# Meta's Calling API is only available via the embedded-signup whatsapp_cloud flow —
# 360dialog (default provider) and manual whatsapp_cloud setups can't reach the call APIs.
def voice_enabled?
provider_config['calling_enabled'].present?
provider == 'whatsapp_cloud' &&
provider_config['source'] == 'embedded_signup' &&
provider_config['calling_enabled'].present?
end
def provider_service
+28
View File
@@ -209,4 +209,32 @@ RSpec.describe Channel::Whatsapp do
end
end
end
describe '#voice_enabled?' do
let(:account) { create(:account) }
it 'returns true for embedded-signup whatsapp_cloud channels with calling_enabled' do
channel = create(:channel_whatsapp, account: account, provider: 'whatsapp_cloud',
validate_provider_config: false, sync_templates: false)
channel.update!(provider_config: channel.provider_config.merge('calling_enabled' => true))
expect(channel.voice_enabled?).to be true
end
it 'returns false for whatsapp_cloud channels without embedded_signup source' do
channel = create(:channel_whatsapp, account: account, provider: 'whatsapp_cloud',
validate_provider_config: false, sync_templates: false)
channel.update!(provider_config: channel.provider_config.merge('source' => 'manual', 'calling_enabled' => true))
expect(channel.voice_enabled?).to be false
end
it 'returns false for default-provider channels (360dialog) even with calling_enabled' do
channel = create(:channel_whatsapp, account: account, provider: 'default',
validate_provider_config: false, sync_templates: false)
channel.update!(provider_config: channel.provider_config.merge('calling_enabled' => true))
expect(channel.voice_enabled?).to be false
end
end
end