-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathroute.ts
50 lines (42 loc) · 1.12 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
// localhost/api/dialout [POST]
import {
defaultBotProfile,
defaultConfig,
defaultMaxDuration,
defaultServices,
} from "./../../../rtvi.config";
export async function POST(request: Request) {
const dialout_data = await request.json();
if (!dialout_data || !process.env.DAILY_BOTS_URL) {
return new Response(
`dialout_data or phoneNumber not found on request body`,
{
status: 400,
}
);
}
const payload = {
bot_profile: defaultBotProfile,
services: defaultServices,
max_duration: defaultMaxDuration,
api_keys: {
together: process.env.TOGETHER_API_KEY,
cartesia: process.env.CARTESIA_API_KEY,
},
config: defaultConfig,
dialout_settings: dialout_data,
};
const req = await fetch(process.env.DAILY_BOTS_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.DAILY_BOTS_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);
}