import { serve } from 'https://deno.land/std@0.168.0/http/server.ts' import { processAudio } from './index.ts' interface WebhookPayload { type: 'INSERT' | 'UPDATE' | 'DELETE' table: string schema: string record: { id: string story_id: string student_id: string audio_url: string status: string [key: string]: any } old_record: null | Record } serve(async (req) => { try { const payload: WebhookPayload = await req.json() // Verifica se é uma inserção em story_recordings if ( payload.type === 'INSERT' && payload.table === 'story_recordings' && payload.schema === 'public' && payload.record.status === 'pending_analysis' ) { await processAudio(payload.record) } return new Response(JSON.stringify({ success: true }), { headers: { 'Content-Type': 'application/json' } }) } catch (error) { console.error('Hook error:', error) return new Response( JSON.stringify({ error: error.message }), { status: 500, headers: { 'Content-Type': 'application/json' } } ) } })