From 117742a7791cbf41901a7dca7f02e74dfb86e6ee Mon Sep 17 00:00:00 2001 From: Muhsin <12408980+muhsin-k@users.noreply.github.com> Date: Sat, 18 Apr 2026 10:37:47 +0400 Subject: [PATCH] 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). --- enterprise/app/controllers/twilio/voice_controller.rb | 11 ++++++++++- spec/factories/calls.rb | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/enterprise/app/controllers/twilio/voice_controller.rb b/enterprise/app/controllers/twilio/voice_controller.rb index 0bc4c67d8..7befb1a11 100644 --- a/enterprise/app/controllers/twilio/voice_controller.rb +++ b/enterprise/app/controllers/twilio/voice_controller.rb @@ -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:') diff --git a/spec/factories/calls.rb b/spec/factories/calls.rb index d050449d9..40b8df24a 100644 --- a/spec/factories/calls.rb +++ b/spec/factories/calls.rb @@ -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' }