Class: Webhooks::V1::AssemblyaiController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/webhooks/v1/assemblyai_controller.rb

Overview

Webhook endpoint for AssemblyAI transcription callbacks.
https://www.assemblyai.com/docs/deployment/webhooks

Flow:

  1. VERIFY: Validate JWT token (security)
  2. INGEST: Create/update WebhookLog entry
  3. ENQUEUE: Queue background worker
  4. RESPOND: Return 200 OK immediately

Test with:
token=$(rails runner "puts AssemblyaiCallbackTokenService.generate_token(resource_type: 'Video', resource_id: 1)")
curl -X POST "https://api.warmlyyours.me:3000/webhooks/v1/assemblyai?token=$token"
-H "Content-Type: application/json"
-d '"transcript_id":"abc123","status":"completed"'

Instance Method Summary collapse

Instance Method Details

#createObject

POST /webhooks/v1/assemblyai



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/webhooks/v1/assemblyai_controller.rb', line 22

def create
  # 1. VERIFY SIGNATURE (JWT token)
  payload = AssemblyaiCallbackTokenService.validate_token(params[:token])

  unless payload
    Rails.logger.warn '[Webhooks::V1::Assemblyai] Invalid or expired token'
    return head :unauthorized
  end

  # Extract resource info from token
  resource_type = payload['resource_type']
  resource_id = payload['resource_id']

  Rails.logger.info "[Webhooks::V1::Assemblyai] Received #{resource_type}:#{resource_id} - status: #{params[:status]}"

  # 2. INGEST (find pending or create ready)
  webhook_log = WebhookLog.ingest!(
    provider: 'assemblyai',
    category: 'transcription_complete',
    resource_type: resource_type,
    resource_id: resource_id,
    data: {
      transcript_id: params[:transcript_id],
      status: params[:status],
      error: params[:error]
    }.compact
  )

  # 3. ENQUEUE background job
  WebhookProcessorWorker.perform_async(webhook_log.id)

  Rails.logger.info "[Webhooks::V1::Assemblyai] Created WebhookLog #{webhook_log.id}, queued for processing"

  # 4. RESPOND immediately
  render json: { status: 'ok', webhook_log_id: webhook_log.id }
end