From 67b522c4332abd9fc895627cd2225f517cebb898 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Thu, 30 Apr 2026 15:34:08 +0700 Subject: [PATCH] refactor(voice): expose voice_enabled? on Channel::Whatsapp for duck-typed checks --- app/models/channel/whatsapp.rb | 7 +++++++ .../enterprise/messages/message_builder.rb | 15 ++++----------- .../whatsapp/call_permission_reply_service.rb | 2 +- .../services/whatsapp/incoming_call_service.rb | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/models/channel/whatsapp.rb b/app/models/channel/whatsapp.rb index 5905c54f7..0cdf77e00 100644 --- a/app/models/channel/whatsapp.rb +++ b/app/models/channel/whatsapp.rb @@ -40,6 +40,13 @@ class Channel::Whatsapp < ApplicationRecord 'Whatsapp' end + # Mirrors Channel::TwilioSms#voice_enabled? so the call subsystem can + # duck-type across providers. Backed by the JSON config rather than a column + # because all other WhatsApp Cloud capability flags live in `provider_config`. + def voice_enabled? + provider_config['calling_enabled'].present? + end + def provider_service if provider == 'whatsapp_cloud' Whatsapp::Providers::WhatsappCloudService.new(whatsapp_channel: self) diff --git a/enterprise/app/builders/enterprise/messages/message_builder.rb b/enterprise/app/builders/enterprise/messages/message_builder.rb index 4956ebd80..7de2ed0ee 100644 --- a/enterprise/app/builders/enterprise/messages/message_builder.rb +++ b/enterprise/app/builders/enterprise/messages/message_builder.rb @@ -7,17 +7,10 @@ module Enterprise::Messages::MessageBuilder super end + # Voice-capable channels (Twilio voice, WhatsApp Cloud Calling) all expose + # `voice_enabled?`; treat any of them as eligible for the incoming voice_call + # bubble bypass. def voice_call_inbox? - twilio_voice_inbox? || whatsapp_call_inbox? - end - - def twilio_voice_inbox? - inbox = @conversation.inbox - inbox.channel_type == 'Channel::TwilioSms' && inbox.channel.voice_enabled? - end - - def whatsapp_call_inbox? - inbox = @conversation.inbox - inbox.channel_type == 'Channel::Whatsapp' && inbox.channel.provider_config['calling_enabled'] + @conversation.inbox.channel.try(:voice_enabled?) end end diff --git a/enterprise/app/services/whatsapp/call_permission_reply_service.rb b/enterprise/app/services/whatsapp/call_permission_reply_service.rb index 4634f6e44..7b66475ce 100644 --- a/enterprise/app/services/whatsapp/call_permission_reply_service.rb +++ b/enterprise/app/services/whatsapp/call_permission_reply_service.rb @@ -2,7 +2,7 @@ class Whatsapp::CallPermissionReplyService pattr_initialize [:inbox!, :params!] def perform - return unless inbox.channel.provider_config['calling_enabled'] + return unless inbox.channel.voice_enabled? reply_data = extract_reply_data return unless reply_data&.dig(:accepted) diff --git a/enterprise/app/services/whatsapp/incoming_call_service.rb b/enterprise/app/services/whatsapp/incoming_call_service.rb index af2879eec..682d8a126 100644 --- a/enterprise/app/services/whatsapp/incoming_call_service.rb +++ b/enterprise/app/services/whatsapp/incoming_call_service.rb @@ -2,7 +2,7 @@ class Whatsapp::IncomingCallService pattr_initialize [:inbox!, :params!] def perform - return unless inbox.channel.provider_config['calling_enabled'] + return unless inbox.channel.voice_enabled? Array(params[:calls]).each { |c| handle_event(c.with_indifferent_access) } end