From cb420d83f67e536c3fd38112be0de03bda9a1fe6 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Tue, 5 May 2026 17:30:03 +0700 Subject: [PATCH] fix(voice): address PR #14356 review feedback - Return 422 (not 200) from `WhatsappCallsController#initiate` permission branch so clients can't mistake the opt-in template path for a successful dial. Body shape unchanged (`{ status: ... }`). - Drop the `file.attached?` guard from `enqueue_audio_transcription`. The social-media ingest path (Messages::Messenger::MessageBuilder) saves the Attachment before attaching the blob, and the guard was silently dropping transcription for those audio messages. AudioTranscriptionJob already has retry_on FileNotFoundError to ride out the create-then-attach race. --- .../controllers/api/v1/accounts/whatsapp_calls_controller.rb | 5 ++++- enterprise/app/models/enterprise/concerns/attachment.rb | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/enterprise/app/controllers/api/v1/accounts/whatsapp_calls_controller.rb b/enterprise/app/controllers/api/v1/accounts/whatsapp_calls_controller.rb index 04ba67dd1..b54940586 100644 --- a/enterprise/app/controllers/api/v1/accounts/whatsapp_calls_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/whatsapp_calls_controller.rb @@ -132,7 +132,10 @@ class Api::V1::Accounts::WhatsappCallsController < Api::V1::Accounts::BaseContro return render_could_not_create_error(I18n.t('errors.whatsapp.calls.permission_request_failed')) if status == 'failed' - render json: { status: status } + # 422 (not 200) so any client treating 2xx as "call placed" can't mistake + # the permission-template path for a successful dial. The FE composable + # detects this status and surfaces the banner instead of throwing. + render json: { status: status }, status: :unprocessable_entity end def permission_request_throttled? diff --git a/enterprise/app/models/enterprise/concerns/attachment.rb b/enterprise/app/models/enterprise/concerns/attachment.rb index 06b8b641a..21a13272b 100644 --- a/enterprise/app/models/enterprise/concerns/attachment.rb +++ b/enterprise/app/models/enterprise/concerns/attachment.rb @@ -14,8 +14,10 @@ module Enterprise::Concerns::Attachment def enqueue_audio_transcription return unless file_type.to_sym == :audio - return unless file.attached? + # No file.attached? guard: the social-media ingest path saves the + # Attachment before attaching the blob. AudioTranscriptionJob retries + # on ActiveStorage::FileNotFoundError to ride out that race. Messages::AudioTranscriptionJob.perform_later(id) end