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:
Muhsin
2026-04-18 10:37:47 +04:00
parent 081e578a57
commit 117742a779
2 changed files with 13 additions and 4 deletions
@@ -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:')
+3 -3
View File
@@ -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' }