export type Parameter = {parameter_name: string, value: string}; export type Attachment = {upload_method: 'url' | 'base64', file_data: string, cache_for?: number | undefined}; export type Message = {message_id?: string | undefined, status?: (0 | 1 | -1 | -2 | 2 | 4 | 5) | undefined, message_template_id: string, customer_id: string, contact?: string | undefined, title?: string | undefined, send_time?: string | undefined, opened_time?: string | undefined, mail_client_user_agent?: string | undefined, mail_client_language?: string | undefined, communication_channel_id: 1 | 2 | 4 | 5, message_data?: Array | undefined, attachments?: Array | undefined, last_change?: string | undefined}; export type CreateApiMessagesActionsSendMessageArgs = {'Accept-Language'?: string | undefined, body: {message: Message}}; export type CreateApiMessagesActionsSendMessageOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send message * * POST /messages/actions/send-message * * Also accepts auth: basicAuth */ export const createApiMessagesActionsSendMessage = async (args: CreateApiMessagesActionsSendMessageArgs, options?: CreateApiMessagesActionsSendMessageOptions) => { const {baseUrl = "https://sandbox.crmcarecloud.com/webservice/rest-api/enterprise-interface/v1.0", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/messages/actions/send-message${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 };