export type GetApiV1WhatsappChannelIdEventsArgs = {channelId: string, type?: ('enqueque' | 'sent' | 'delivered' | 'read' | 'answered' | 'failed' | 'pending' | 'invalid') | undefined, from?: string | undefined, to?: string | undefined}; export type GetApiV1WhatsappChannelIdEventsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Historial de eventos HSM * * GET /v1/whatsapp/{channelId}/events */ export const getApiV1WhatsappChannelIdEvents = async (args: GetApiV1WhatsappChannelIdEventsArgs, options?: GetApiV1WhatsappChannelIdEventsOptions) => { const {baseUrl = "https://connect.cliengo.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.type != null) query.append("type", String(args.type)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/whatsapp/${encodeURIComponent(String(args.channelId))}/events${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };