Edits history of script submission #13702 for ' Webhooks create (ultravox)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Ultravox = {
      apiKey: string;
    };
    /**
     * Webhooks create
     *
     */
    export async function main(
      auth: Ultravox,
      body: {
        webhookId: string;
        created: string;
        url: string;
        secrets?: string[];
        events: "call.started" | "call.ended"[];
      },
    ) {
      const url = new URL(`https://api.ultravox.ai/api/webhooks`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-API-Key": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago