import {z} from 'zod' export type MmsPayload = {subject?: string | undefined, content?: (Array<{body?: string | undefined, mime_type?: 'text/plain' | undefined}>) | undefined}; export type RcsMedia = {height?: ('HEIGHT_UNSPECIFIED' | 'SHORT' | 'MEDIUM' | 'TALL') | undefined, content_info?: ({file_url?: string | undefined, force_refresh?: boolean | undefined}) | undefined}; export type RcsSuggestedReply = {text?: string | undefined, postback_data?: string | undefined}; export type RcsSuggestedAction = {text?: string | undefined, postback_data?: string | undefined, fallback_url?: string | undefined, open_url_action?: ({application?: ('OPEN_URL_APPLICATION_UNSPECIFIED' | 'BROWSER' | 'WEBVIEW') | undefined, url?: string | undefined, webview_view_mode?: ('WEBVIEW_VIEW_MODE_UNSPECIFIED' | 'FULL' | 'HALF' | 'TALL') | undefined, description?: string | undefined}) | undefined, dial_action?: ({phone_number?: string | undefined}) | undefined, view_location_action?: ({label?: string | undefined, lat_long?: ({latitude?: number | undefined, longitude?: number | undefined}) | undefined}) | undefined, create_calendar_event_action?: ({title?: string | undefined, description?: string | undefined, start_time?: string | undefined, end_time?: string | undefined}) | undefined}; export type RcsSuggestion = {reply?: RcsSuggestedReply | undefined, action?: RcsSuggestedAction | undefined}; export type RcsCardContent = {title?: string | undefined, description?: string | undefined, media?: RcsMedia | undefined, suggestions?: Array | undefined}; export type RcsStandaloneCard = {card_orientation?: ('CARD_ORIENTATION_UNSPECIFIED' | 'HORIZONTAL' | 'VERTICAL') | undefined, thumbnail_image_alignment?: ('THUMBNAIL_IMAGE_ALIGNMENT_UNSPECIFIED' | 'LEFT' | 'RIGHT') | undefined, card_content?: RcsCardContent | undefined}; export type RcsCarouselCard = {card_width?: ('CARD_WIDTH_UNSPECIFIED' | 'SMALL' | 'MEDIUM') | undefined, card_contents?: Array | undefined}; export type RcsRichCard = {standalone_card?: RcsStandaloneCard | undefined, carousel_card?: RcsCarouselCard | undefined}; export type RcsContentMessage = {text?: string | undefined, rich_card?: RcsRichCard | undefined, suggestions?: Array | undefined}; export type RcsPayload = {content_message?: RcsContentMessage | undefined}; export type BroadcastRequest = {name: string, send_scheduled_date: string, send_schedule?: ({method?: string | undefined, send_date?: string | undefined, send_time?: string | undefined, field_name?: string | undefined, default_time_zone?: string | undefined}) | undefined, targeting?: ({message_template?: string | undefined, short_url_base?: string | undefined, shorten_urls?: boolean | undefined, channel?: ('sms' | 'push') | undefined, source_short_code?: ({short_code?: string | undefined, country_code?: string | undefined, source_type?: string | undefined}) | undefined, source_lists: Array, filters?: (Array<{name?: string | undefined, selector?: string | undefined, value?: Array | undefined}>) | undefined, mms?: MmsPayload | undefined, rcs?: RcsPayload | undefined}) | undefined}; export type CreateApiCompaniesCompanyKeyMobiledbBroadcastsArgs = {'X-API-Version'?: string | undefined, 'Content-Type': string, company_key: string, body: BroadcastRequest}; export type CreateApiCompaniesCompanyKeyMobiledbBroadcastsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const mmsPayload = z.object({subject: z.string().optional(), content: z.array(z.object({body: z.string().optional(), mime_type: z.literal("text/plain").optional()})).optional()}); export const rcsMedia = z.object({height: z.enum(["HEIGHT_UNSPECIFIED", "SHORT", "MEDIUM", "TALL"]).optional(), content_info: z.object({file_url: z.string().optional(), force_refresh: z.boolean().optional()}).optional()}); export const rcsSuggestedReply = z.object({text: z.string().max(25).optional(), postback_data: z.string().max(2048).optional()}); export const rcsSuggestedAction = z.object({text: z.string().max(25).optional(), postback_data: z.string().max(2048).optional(), fallback_url: z.string().max(2048).optional(), open_url_action: z.object({application: z.enum(["OPEN_URL_APPLICATION_UNSPECIFIED", "BROWSER", "WEBVIEW"]).optional(), url: z.string().max(2048).optional(), webview_view_mode: z.enum(["WEBVIEW_VIEW_MODE_UNSPECIFIED", "FULL", "HALF", "TALL"]).optional(), description: z.string().optional()}).optional(), dial_action: z.object({phone_number: z.string().optional()}).optional(), view_location_action: z.object({label: z.string().max(200).optional(), lat_long: z.object({latitude: z.number().gte(-90).lte(90).optional(), longitude: z.number().gte(-180).lte(180).optional()}).optional()}).optional(), create_calendar_event_action: z.object({title: z.string().max(100).optional(), description: z.string().max(500).optional(), start_time: z.string().optional(), end_time: z.string().optional()}).optional()}); export const rcsSuggestion = z.object({reply: rcsSuggestedReply.optional(), action: rcsSuggestedAction.optional()}); export const rcsCardContent = z.object({title: z.string().max(200).optional(), description: z.string().max(2000).optional(), media: rcsMedia.optional(), suggestions: z.array(rcsSuggestion).optional()}); export const rcsStandaloneCard = z.object({card_orientation: z.enum(["CARD_ORIENTATION_UNSPECIFIED", "HORIZONTAL", "VERTICAL"]).optional(), thumbnail_image_alignment: z.enum(["THUMBNAIL_IMAGE_ALIGNMENT_UNSPECIFIED", "LEFT", "RIGHT"]).optional(), card_content: rcsCardContent.optional()}); export const rcsCarouselCard = z.object({card_width: z.enum(["CARD_WIDTH_UNSPECIFIED", "SMALL", "MEDIUM"]).optional(), card_contents: z.array(rcsCardContent).optional()}); export const rcsRichCard = z.object({standalone_card: rcsStandaloneCard.optional(), carousel_card: rcsCarouselCard.optional()}); export const rcsContentMessage = z.object({text: z.string().max(3072).optional(), rich_card: rcsRichCard.optional(), suggestions: z.array(rcsSuggestion).optional()}); export const rcsPayload = z.object({content_message: rcsContentMessage.optional()}); export const broadcastResponse = z.object({broadcast_id: z.string().optional(), status: z.enum(["scheduled", "in_progress", "sent", "canceled", "deleted", "paused", "failed"]).optional(), name: z.string().optional(), send_scheduled_date: z.string().optional(), created_by: z.string().optional(), created_by_application: z.string().optional(), targeting: z.object({message_template: z.string().optional(), short_url_base: z.string().optional(), shorten_urls: z.boolean().optional(), channel: z.string().optional(), source_short_code: z.string().optional(), source_lists: z.array(z.string()).optional(), filters: z.array(z.object({})).optional(), mms: mmsPayload.optional(), rcs: rcsPayload.optional(), delivery: z.object({send_start_date: z.string().optional(), enqueue_completed_date: z.string().optional(), recipient_count: z.number().int().optional()}).optional(), url: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a broadcast * * POST /companies/{company_key}/mobiledb/broadcasts/ */ export const createApiCompaniesCompanyKeyMobiledbBroadcasts = async (args: CreateApiCompaniesCompanyKeyMobiledbBroadcastsArgs, options?: CreateApiCompaniesCompanyKeyMobiledbBroadcastsOptions) => { const {baseUrl = "https://public-api.vibescm.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-Version'] != null) headers.set("X-API-Version", String(args['X-API-Version'])) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.company_key))}/mobiledb/broadcasts/${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 validateResponse(broadcastResponse, await res.json()) };