Rocky_Mountain_Vending/app/api/internal/phone-calls/turn/route.ts

36 lines
1.2 KiB
TypeScript

import { NextResponse } from "next/server"
import { fetchMutation } from "convex/nextjs"
import { api } from "@/convex/_generated/api"
import { requirePhoneAgentInternalAuth } from "@/app/api/internal/phone-calls/shared"
export async function POST(request: Request) {
const authError = await requirePhoneAgentInternalAuth(request)
if (authError) {
return authError
}
try {
const body = await request.json()
await fetchMutation(api.voiceSessions.addTranscriptTurn, {
sessionId: body.sessionId,
roomName: String(body.roomName || ""),
participantIdentity: String(body.participantIdentity || ""),
role: body.role,
text: String(body.text || ""),
kind: body.kind ? String(body.kind) : undefined,
isFinal: typeof body.isFinal === "boolean" ? body.isFinal : undefined,
language: body.language ? String(body.language) : undefined,
source: "phone-agent",
createdAt:
typeof body.createdAt === "number" ? body.createdAt : undefined,
})
return NextResponse.json({ success: true })
} catch (error) {
console.error("Failed to append phone call turn:", error)
return NextResponse.json(
{ error: "Failed to append phone call turn" },
{ status: 500 }
)
}
}