export type CreateApiWorkspaceKeyTriggerArgs = {workspace_key: string, body: {name: string, template: string, notification_category: string, users: Array<{distinct_id: string, $channels?: Array | undefined, $email?: Array | undefined, $sms?: Array | undefined, $whatsapp?: Array | undefined, $androidpush?: Array | undefined, $iospush?: Array | undefined, $slack?: (Array<{email: string, access_token: string} | {user_id: string, access_token: string} | {channel: string, access_token: string} | {incoming_webhook: {url: string}}>) | undefined, $ms_teams?: (Array<{tenant_id: string, service_url: string, conversation_id: string} | {tenant_id: string, service_url: string, user_id: string} | {incoming_webhook: {url: string}}>) | undefined}>, data?: ({$attachments?: (Array<{url: string, filename?: string | undefined, ignore_if_error?: boolean | undefined} | {data: string, filename?: string | undefined, contentType?: string | undefined}>) | undefined} | {[key: string]: string}) | undefined, delivery?: ({smart?: boolean | undefined, success?: string | undefined, time_to_live?: string | undefined, mandatory_channels?: Array | undefined}) | undefined, delay?: string | undefined, trigger_at?: string | undefined, tenant_id?: string | undefined, $idempotency_key?: string | undefined}}; export type CreateApiWorkspaceKeyTriggerOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Dynamic Workflow Trigger * * POST /{workspace_key}/trigger/ */ export const createApiWorkspaceKeyTrigger = async (args: CreateApiWorkspaceKeyTriggerArgs, options?: CreateApiWorkspaceKeyTriggerOptions) => { const {baseUrl = "https://hub.suprsend.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.workspace_key))}/trigger/${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 res.text() };