0

Webhooks update

by
Published Apr 8, 2025
Script ultravox Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Ultravox = {
3
  apiKey: string;
4
};
5
/**
6
 * Webhooks update
7
 *
8
 */
9
export async function main(
10
  auth: Ultravox,
11
  webhook_id: string,
12
  body: {
13
    webhookId: string;
14
    created: string;
15
    url: string;
16
    secrets?: string[];
17
    events: "call.started" | "call.ended"[];
18
  },
19
) {
20
  const url = new URL(`https://api.ultravox.ai/api/webhooks/${webhook_id}`);
21

22
  const response = await fetch(url, {
23
    method: "PUT",
24
    headers: {
25
      "Content-Type": "application/json",
26
      "X-API-Key": auth.apiKey,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36