Add LICENSE, README, and Docs tab to Mission Control
This commit is contained in:
@@ -3,24 +3,53 @@ import { runSiteMenteVoiceTurn } from "../../../../lib/ai/siteMenteAgent";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
// Vapi webhook payload types
|
||||
interface VapiMessage {
|
||||
type: string;
|
||||
role?: string;
|
||||
transcript?: string;
|
||||
}
|
||||
|
||||
interface VapiCall {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface VapiWebhookPayload {
|
||||
message: VapiMessage;
|
||||
call: VapiCall;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = (await request.json()) as { transcript?: string };
|
||||
|
||||
if (!body.transcript || typeof body.transcript !== "string") {
|
||||
return NextResponse.json(
|
||||
{ error: "transcript is required." },
|
||||
{ status: 400 }
|
||||
);
|
||||
const body = (await request.json()) as VapiWebhookPayload;
|
||||
|
||||
// Extract transcript from Vapi's format
|
||||
const message = body.message;
|
||||
|
||||
// Only process final transcripts
|
||||
if (!message || message.type !== "transcript" || !message.transcript) {
|
||||
// Return empty response for non-transcript messages
|
||||
return NextResponse.json({ results: [] });
|
||||
}
|
||||
|
||||
const transcript = message.transcript;
|
||||
|
||||
// Call MiniMax brain
|
||||
const response = await runSiteMenteVoiceTurn({
|
||||
transcript: body.transcript,
|
||||
transcript: transcript,
|
||||
});
|
||||
|
||||
// Return in Vapi's expected format
|
||||
return NextResponse.json({
|
||||
results: [
|
||||
{
|
||||
result: response.reply,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return NextResponse.json(response);
|
||||
} catch (error) {
|
||||
console.error("[SiteMente][API] Voice route failed", error);
|
||||
console.error("[SiteMente][Vapi] Voice route failed", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to generate voice response." },
|
||||
{ status: 500 }
|
||||
|
||||
Reference in New Issue
Block a user