mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
- Implementa Edge Function para processamento de áudio - Adiciona integração com OpenAI Whisper e GPT-4 - Configura Database Trigger para story_recordings - Implementa análise automática de leitura - Atualiza documentação e variáveis de ambiente
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
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<string, any>
|
|
}
|
|
|
|
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' } }
|
|
)
|
|
}
|
|
})
|