export type HangupButtonEventDataDto = {id: number}; export type HangupButtonEventDto = {url: string, data: HangupButtonEventDataDto}; export type CallEventDto = {call_type: 'incoming' | 'outgoing', from: string, to: string, call_event_id: number, auth_user_id: number, integration_code: string, time: string, status: string, note?: string | undefined, hangup_button: HangupButtonEventDto}; export type CreateApiMessengerV1TelephonyCallStartArgs = {body: CallEventDto}; export type CreateApiMessengerV1TelephonyCallStartOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Start a phone call * * POST /messenger/v1/telephony/call/start */ export const createApiMessengerV1TelephonyCallStart = async (args: CreateApiMessengerV1TelephonyCallStartArgs, options: CreateApiMessengerV1TelephonyCallStartOptions) => { const {baseUrl, 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 ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/messenger/v1/telephony/call/start${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 };