forked from daily-demos/daily-bots-web-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.ts
39 lines (32 loc) · 959 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// [POST] /api
import { defaultBotProfile, defaultMaxDuration } from "./../../rtvi.config";
export async function POST(request: Request) {
const { services, config } = await request.json();
if (!services || !config || !process.env.DAILY_BOTS_URL) {
return new Response(`Services or config not found on request body`, {
status: 400,
});
}
const payload = {
bot_profile: defaultBotProfile,
max_duration: defaultMaxDuration,
services,
api_keys: {
openai: process.env.OPENAI_API_KEY,
},
config: [...config],
};
const req = await fetch(process.env.DAILY_BOTS_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.DAILY_API_KEY}`,
},
body: JSON.stringify(payload),
});
const res = await req.json();
if (req.status !== 200) {
return Response.json(res, { status: req.status });
}
return Response.json(res);
}