fix(voice): guarantee conference_sid at TwiML render, consistent Call factory
- conference_twiml now ensures call.conference_sid is present before rendering; backfills via Voice::Conference::Name.for(call) if missing. Prevents invalid TwiML on Call rows created without the sid set. - Call factory derives account/inbox/contact from the associated conversation so create(:call) is always internally consistent (no more mismatched account_id across associations).
This commit is contained in:
@@ -114,10 +114,12 @@ class Twilio::VoiceController < ApplicationController
|
||||
end
|
||||
|
||||
def conference_twiml(call)
|
||||
conference_sid = ensure_conference_sid!(call)
|
||||
|
||||
Twilio::TwiML::VoiceResponse.new.tap do |response|
|
||||
response.dial do |dial|
|
||||
dial.conference(
|
||||
call.conference_sid,
|
||||
conference_sid,
|
||||
start_conference_on_enter: agent_leg?(twilio_from),
|
||||
end_conference_on_exit: false,
|
||||
status_callback: conference_status_callback_url,
|
||||
@@ -129,6 +131,13 @@ class Twilio::VoiceController < ApplicationController
|
||||
end.to_s
|
||||
end
|
||||
|
||||
def ensure_conference_sid!(call)
|
||||
return call.conference_sid if call.conference_sid.present?
|
||||
|
||||
call.update!(conference_sid: Voice::Conference::Name.for(call))
|
||||
call.conference_sid
|
||||
end
|
||||
|
||||
def participant_label_for(from_number)
|
||||
return from_number.delete_prefix('client:') if from_number.start_with?('client:')
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
FactoryBot.define do
|
||||
factory :call do
|
||||
association :account
|
||||
association :inbox
|
||||
association :conversation
|
||||
association :contact
|
||||
account { conversation.account }
|
||||
inbox { conversation.inbox }
|
||||
contact { conversation.contact }
|
||||
provider { :twilio }
|
||||
direction { :incoming }
|
||||
status { 'ringing' }
|
||||
|
||||
Reference in New Issue
Block a user