export type CreateApiApiV1WWIdTriggersHooksWebhookSourceIdArgs = {wId: string, webhookSourceId: string, body: Record}; export type CreateApiApiV1WWIdTriggersHooksWebhookSourceIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Receive external webhook to trigger flows * * POST /api/v1/w/{wId}/triggers/hooks/{webhookSourceId} */ export const createApiApiV1WWIdTriggersHooksWebhookSourceId = async (args: CreateApiApiV1WWIdTriggersHooksWebhookSourceIdArgs, options?: CreateApiApiV1WWIdTriggersHooksWebhookSourceIdOptions) => { const {baseUrl = "https://dust.tt", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/w/${encodeURIComponent(String(args.wId))}/triggers/hooks/${encodeURIComponent(String(args.webhookSourceId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };