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.
This commit is contained in:
Tanmay Deep Sharma
2026-05-05 17:30:03 +07:00
parent 61a8511f7a
commit cb420d83f6
2 changed files with 7 additions and 2 deletions
@@ -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?
@@ -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