-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c22f8
commit b14da04
Showing
21 changed files
with
1,295 additions
and
194 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
examples/conversational-ai/talk-to-santa/app/api/get-conversation/[conversationId]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextResponse } from "next/server"; | ||
import { ElevenLabsClient } from "elevenlabs"; | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { conversationId: string } } | ||
) { | ||
console.log(params); | ||
console.log("Getting conversation", params.conversationId); | ||
if (!process.env.XI_API_KEY) { | ||
throw Error("XI_API_KEY is not set"); | ||
} | ||
const elevenlabs = new ElevenLabsClient({ | ||
apiKey: process.env.XI_API_KEY, | ||
}); | ||
|
||
try { | ||
const conversation = await elevenlabs.conversationalAi.getConversation( | ||
params.conversationId | ||
); | ||
console.log(conversation); | ||
|
||
return NextResponse.json({ conversation }); | ||
} catch (error) { | ||
console.error("Error getting conversation", error); | ||
return NextResponse.json( | ||
{ error: "Failed to get Conversation" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/conversational-ai/talk-to-santa/app/api/signed-url/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET() { | ||
const agentId = process.env.AGENT_ID; | ||
const apiKey = process.env.XI_API_KEY; | ||
if (!agentId) { | ||
throw Error("AGENT_ID is not set"); | ||
} | ||
if (!apiKey) { | ||
throw Error("XI_API_KEY is not set"); | ||
} | ||
try { | ||
const response = await fetch( | ||
`https://api.elevenlabs.io/v1/convai/conversation/get_signed_url?agent_id=${agentId}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"xi-api-key": apiKey, | ||
}, | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to get signed URL"); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json({ signedUrl: data.signed_url }); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to get signed URL" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
Oops, something went wrong.