refactor(voice): expose voice_enabled? on Channel::Whatsapp for duck-typed checks
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user