import {z} from 'zod' export type Table = 0 | 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72; export type ChatbotLink = {id?: number | undefined, chatbotId?: number | undefined, linkedTableType?: Table | undefined, linkedId?: number | undefined, linkedSubId?: number | undefined, createdDate?: string | undefined}; export type ChatbotStatus = 0 | 1 | 2; export type ChatbotMode = 0 | 1; export type AutoCloseConfigModel = {chatbotWarningEnabled?: boolean | undefined, chatbotWarningTimeMinutes?: (number | null) | undefined, chatbotWarningMessage?: (string | null) | undefined, chatbotCloseEnabled?: boolean | undefined, chatbotCloseTimeMinutes?: (number | null) | undefined, chatbotCloseWithoutMessage?: boolean | undefined, chatbotCloseMessage?: (string | null) | undefined, noBotWarningEnabled?: boolean | undefined, noBotWarningTimeMinutes?: (number | null) | undefined, noBotWarningMessage?: (string | null) | undefined, noBotCloseEnabled?: boolean | undefined, noBotCloseTimeMinutes?: (number | null) | undefined, noBotCloseWithoutMessage?: boolean | undefined, noBotCloseMessage?: (string | null) | undefined}; export type Chatbot = {id?: number | undefined, departmentId?: number | undefined, name: string, avatar?: (string | null) | undefined, firstMessage?: (string | null) | undefined, links?: (Array | null) | undefined, topics?: (string | null) | undefined, objectIds?: (string | null) | undefined, seen?: number | undefined, status?: ChatbotStatus | undefined, mode?: ChatbotMode | undefined, aiConfig?: (string | null) | undefined, publishedVersionId?: number | undefined, channelCount?: number | undefined, workingHourType?: number | undefined, createdDate?: (string | null) | undefined, updatedDate?: (string | null) | undefined, autoCloseConfig?: (string | null) | undefined, parsedConfig?: AutoCloseConfigModel | undefined}; export type CreateApiV1ChatbotsPreviewArgs = {body: Chatbot}; export type CreateApiV1ChatbotsPreviewOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const table = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(5), z.literal(6), z.literal(7), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(25), z.literal(26), z.literal(27), z.literal(31), z.literal(32), z.literal(34), z.literal(35), z.literal(36), z.literal(37), z.literal(38), z.literal(39), z.literal(40), z.literal(41), z.literal(42), z.literal(43), z.literal(44), z.literal(45), z.literal(46), z.literal(47), z.literal(48), z.literal(50), z.literal(51), z.literal(52), z.literal(53), z.literal(55), z.literal(60), z.literal(61), z.literal(62), z.literal(63), z.literal(64), z.literal(65), z.literal(66), z.literal(67), z.literal(68), z.literal(69), z.literal(72)]); export const chatbotLink = z.object({id: z.number().int().optional(), chatbotId: z.number().int().optional(), linkedTableType: table.optional(), linkedId: z.number().int().optional(), linkedSubId: z.number().int().optional(), createdDate: z.string().optional()}); export const chatbotStatus = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const chatbotMode = z.union([z.literal(0), z.literal(1)]); export const autoCloseConfigModel = z.object({chatbotWarningEnabled: z.boolean().optional(), chatbotWarningTimeMinutes: z.number().int().nullable().optional(), chatbotWarningMessage: z.string().nullable().optional(), chatbotCloseEnabled: z.boolean().optional(), chatbotCloseTimeMinutes: z.number().int().nullable().optional(), chatbotCloseWithoutMessage: z.boolean().optional(), chatbotCloseMessage: z.string().nullable().optional(), noBotWarningEnabled: z.boolean().optional(), noBotWarningTimeMinutes: z.number().int().nullable().optional(), noBotWarningMessage: z.string().nullable().optional(), noBotCloseEnabled: z.boolean().optional(), noBotCloseTimeMinutes: z.number().int().nullable().optional(), noBotCloseWithoutMessage: z.boolean().optional(), noBotCloseMessage: z.string().nullable().optional()}); export const chatbot = z.object({id: z.number().int().optional(), departmentId: z.number().int().optional(), name: z.string().min(1).max(100), avatar: z.string().nullable().optional(), firstMessage: z.string().nullable().optional(), links: z.array(chatbotLink).nullable().optional(), topics: z.string().nullable().optional(), objectIds: z.string().nullable().optional(), seen: z.number().int().optional(), status: chatbotStatus.optional(), mode: chatbotMode.optional(), aiConfig: z.string().nullable().optional(), publishedVersionId: z.number().int().optional(), channelCount: z.number().int().optional(), workingHourType: z.number().int().optional(), createdDate: z.string().nullable().optional(), updatedDate: z.string().nullable().optional(), autoCloseConfig: z.string().nullable().optional(), parsedConfig: autoCloseConfigModel.optional()}); export const chatbotObject = z.object({id: z.number().int().optional(), departmentId: z.number().int().optional(), name: z.string().min(1).max(100), language: z.string().nullable().optional(), code: z.string().nullable().optional()}); export const chatbotPreviewModel = z.object({bot: chatbot.optional(), objects: z.array(chatbotObject).nullable().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 }; /** * Preview a (possibly unsaved) chatbot configuration without persisting anything * * POST /v1/chatbots/preview * * Also accepts auth: API Key */ export const createApiV1ChatbotsPreview = async (args: CreateApiV1ChatbotsPreviewArgs, options: CreateApiV1ChatbotsPreviewOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/chatbots/preview${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(chatbotPreviewModel, await res.json()) };