-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathroute.ts
57 lines (47 loc) · 1.3 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
51
52
53
54
55
56
57
// localhost/api/dialin [POST]
import {
defaultBotProfile,
defaultConfig,
defaultMaxDuration,
defaultServices,
} from "./../../../rtvi.config";
export async function POST(request: Request) {
const { test, callId, callDomain } = await request.json();
//@TODO: HMAC header verification
if (test) {
// Webhook creation test response
return new Response(JSON.stringify({ test: true }), { status: 200 });
}
if (!callId || !callDomain || !process.env.DAILY_BOTS_URL) {
return new Response(`callId or callDomain 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,
dialin_settings: {
callId,
callDomain,
},
};
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);
}