export type HandoverPush = {client_id: string, message: string, rich_message?: string | undefined, lang: string, platform: 'messenger' | 'webchat'}; export type CreateApiHandoverPushBotIdArgs = {bot_id: string, body: HandoverPush}; export type CreateApiHandoverPushBotIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Push * * POST /handover/push/{bot_id} */ export const createApiHandoverPushBotId = async (args: CreateApiHandoverPushBotIdArgs, options?: CreateApiHandoverPushBotIdOptions) => { const {baseUrl = "https://apis.smartly.ai", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/handover/push/${encodeURIComponent(String(args.bot_id))}${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 };