added api route
This commit is contained in:
27
examples/storytelling-chatbot/frontend/app/api/route.ts
Normal file
27
examples/storytelling-chatbot/frontend/app/api/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// [POST] /api
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const params = await request.json();
|
||||
console.log("in POST, params is ", params)
|
||||
const url = process.env.BOT_START_URL || "http://localhost:7860"
|
||||
const req = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.PCC_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
|
||||
const res = await req.json();
|
||||
|
||||
if (req.status !== 200) {
|
||||
return Response.json(res, { status: req.status });
|
||||
}
|
||||
console.log({res});
|
||||
return Response.json(res);
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
return Response.json({message: "Hello World"});
|
||||
}
|
||||
@@ -27,22 +27,26 @@ export default function Call() {
|
||||
|
||||
// Create a new room for the story session
|
||||
try {
|
||||
const response = await fetch("/", {
|
||||
console.log("POSTing to /api")
|
||||
const response = await fetch("/api", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"createDailyRoom": true
|
||||
})
|
||||
});
|
||||
|
||||
const { room_url, token } = await response.json();
|
||||
|
||||
const {dailyRoom, dailyToken} = await response.json();
|
||||
console.log({dailyRoom, dailyToken})
|
||||
// Keep a reference to the room url for later
|
||||
setRoom(room_url);
|
||||
setRoom(dailyRoom);
|
||||
|
||||
// Join the WebRTC session
|
||||
await daily.join({
|
||||
url: room_url,
|
||||
token,
|
||||
url: dailyRoom,
|
||||
token: dailyToken,
|
||||
videoSource: false,
|
||||
startAudioOff: true,
|
||||
});
|
||||
|
||||
3
examples/storytelling-chatbot/frontend/example.env.local
Normal file
3
examples/storytelling-chatbot/frontend/example.env.local
Normal file
@@ -0,0 +1,3 @@
|
||||
SITE_URL=
|
||||
PCC_API_KEY=
|
||||
BOT_START_URL=
|
||||
2090
examples/storytelling-chatbot/frontend/package-lock.json
generated
2090
examples/storytelling-chatbot/frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,7 @@
|
||||
"eslint-config-next": "14.1.4",
|
||||
"postcss": "^8.4.47",
|
||||
"tailwindcss": "^3.4.13",
|
||||
"typescript": "^5.6.2"
|
||||
"typescript": "^5.6.2",
|
||||
"vercel": "^41.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user