import {z} from 'zod' export type CreateApiV20EndpointsArgs = {Accept?: ('application/json' | 'application/hal+json' | 'application/xml' | 'text/xml' | 'text/csv') | undefined, resourceId?: string | undefined, body: {foreignId?: string | undefined, channel?: ('facebook' | 'alexa' | 'slack' | 'generic' | 'inject' | 'rest' | 'realtime' | 'socket' | 'adminconsole' | 'webchat2' | 'dialogflow' | 'twilio' | 'twilio-sms' | 'line' | 'intercom' | 'microsoftBotFramework' | 'microsoftTeams' | 'sunshineConversations' | 'admin-webchat' | 'avaya' | 'nonConversational' | 'voiceGateway2' | 'amazonLex' | 'workplace' | 'webhook' | 'abstractRest' | 'userlike' | 'ringCentralEngage' | 'audioCodes' | 'bandwidth' | 'whatsapp' | 'eightByEight' | 'genesysBotConnector' | 'niceCXOne' | 'agentAssistVoice' | 'webchat3' | 'niceCXOneAAH' | 'zoomContactCenter' | 'mcpServer') | undefined, flowId?: string | undefined, localeId?: string | undefined, URLToken?: string | undefined, name?: string | undefined, entrypoint?: string | undefined, active?: boolean | undefined, nluConnectorId?: ('alexa' | 'dialogflow' | 'dialogflowBuiltIn' | 'amazonLexBuiltIn' | 'luis' | 'watson' | 'noNlu' | 'cognigy' | 'code' | 'generativeAI' | 'lex' | string) | undefined, useConversations?: boolean | undefined, maskIPAddress?: boolean | undefined, maskAnalytics?: boolean | undefined, maskLogging?: boolean | undefined, useContactProfiles?: boolean | undefined, useAnalytics?: boolean | undefined, useDashbotAnalytics?: boolean | undefined, dashbotApikey?: string | undefined, dashbotPlatform?: string | undefined, disableInputSanitization?: string | undefined, disableSkipUriTags?: string | undefined, overrideSnapshotConnections?: boolean | undefined, settings?: ({accessScope?: string | undefined, accessToken?: string | undefined, appId?: string | undefined, appSecret?: string | undefined, backgroundImageUrl?: string | undefined, basicAuthPassword?: string | undefined, basicAuthUser?: string | undefined, botUserId?: string | undefined, businessHours?: ({businessHours?: (Array<{startTime?: string | undefined, endTime?: string | undefined, weekDay?: string | undefined}>) | undefined, enabled?: boolean | undefined, text?: string | undefined, mode?: string | undefined, timeZone?: string | undefined, title?: string | undefined}) | undefined, colorScheme?: string | undefined, connectionName?: string | undefined, customJSON?: string | undefined, designTemplate?: number | undefined, disableHtmlContentSanitization?: boolean | undefined, disableInputAutocomplete?: boolean | undefined, disableInputAutogrow?: boolean | undefined, disableUrlButtonSanitization?: boolean | undefined, enableGenericHTMLStyling?: boolean | undefined, enableAsyncCommunication?: boolean | undefined, engagementMessageText?: string | undefined, displayGetStartedButton?: boolean | undefined, dynamicImageAspectRatio?: boolean | undefined, enableCollectMetadata?: boolean | undefined, enableConnectionStatusIndicator?: boolean | undefined, enableDemoWebchat?: boolean | undefined, enableFileUpload?: boolean | undefined, enablePersistentMenu?: boolean | undefined, enableRating?: ('onRequest' | 'always' | 'once') | undefined, enableSTT?: boolean | undefined, enableTTS?: boolean | undefined, enableUnreadMessageBadge?: boolean | undefined, enableUnreadMessagePreview?: boolean | undefined, enableUnreadMessageSound?: boolean | undefined, enableUnreadMessageTitleIndicator?: boolean | undefined, enableTypingIndicator?: boolean | undefined, facebookPageToken?: string | undefined, focusInputAfterPostback?: boolean | undefined, getStartedButtonText?: string | undefined, getStartedPayload?: string | undefined, getStartedText?: string | undefined, getStartedData?: string | undefined, headerLogoUrl?: string | undefined, hubSecret?: string | undefined, inputAutogrowMaxRows?: number | undefined, inputPlaceholder?: string | undefined, language?: string | undefined, lineChannelAccessToken?: string | undefined, lineChannelSecret?: string | undefined, maintenance?: ({enabled?: boolean | undefined, mode?: string | undefined, text?: string | undefined, title?: string | undefined}) | undefined, mergeContactProfiles?: boolean | undefined, messageDelay?: number | undefined, messageLogoUrl?: string | undefined, overwriteWebchatBundleUrl?: string | undefined, ratingTitleText?: string | undefined, ratingCommentText?: string | undefined, ratingMessageHistoryRatingText?: string | undefined, ratingMessageHistoryCommentText?: string | undefined, reparseAlexaSlots?: boolean | undefined, requestFacebookProfileData?: boolean | undefined, restEndpointAuthentication?: ({authenticationType?: ('no-auth' | 'apiKey') | undefined}) | undefined, sessionExpiration?: number | undefined, shouldOverwriteWebchatBundleUrl?: boolean | undefined, showEngagementMessagesInChat?: boolean | undefined, slackOAuthAccessToken?: string | undefined, slackVerifyToken?: string | undefined, sunshineConversationsChannelKeyId?: string | undefined, sunshineConversationsChannelSecret?: string | undefined, sunshineConversationsChannelUri?: string | undefined, tenantId?: string | undefined, updateContactProfileWithFacebookProfile?: boolean | undefined, voice?: string | undefined, webhookEndpointAuthentication?: ({authenticationType?: ('no-auth' | 'apiKey') | undefined}) | undefined, webhookUrl?: string | undefined, skill?: Record | undefined, persistentMenu?: Record | undefined}) | undefined, transformer?: ({abortOnError?: boolean | undefined, transformer?: string | undefined, transpiledTransformer?: string | undefined, inputTransformerEnabled?: boolean | undefined, outputTransformerEnabled?: boolean | undefined, finalPingTransformerEnabled?: boolean | undefined, notifyTransformerEnabled?: boolean | undefined, injectTransformerEnabled?: boolean | undefined}) | undefined, handoverSettings?: ({provider?: ('cognigy' | 'none' | 'rce') | undefined, providerSettings?: ({forwardOnlyHandoverConversations?: boolean | undefined, getQueueUpdates?: boolean | undefined, apiVersion?: string | undefined, baseUrl?: string | undefined, apiAccessToken?: string | undefined, baseApiUrl?: string | undefined, realtimeAccessToken?: string | undefined, realtimeEndpointUrl?: string | undefined, webhookSecret?: string | undefined, botCategoryId?: string | undefined, agentCategoryId?: string | undefined, organizationId?: string | undefined, deploymentId?: string | undefined, buttonId?: string | undefined}) | undefined, agentAssistSettings?: ({copilotType?: ('none' | 'workspace' | 'whisper') | undefined, agentAssistFlowId?: string | undefined, agentAssistConfigId?: string | undefined, enableTranscriptTile?: boolean | undefined, enableTranscriptTileChatInput?: boolean | undefined, redactTranscriptTileMessages?: boolean | undefined, enableAgentCopilotAuthentication?: boolean | undefined, blockNonJWTRequests?: boolean | undefined, agentCopilotAuthentication?: string | undefined, copilotAuthenticationMethod?: ('default' | 'tokenSecret' | 'publicKey' | 'keyStore') | undefined, copilotAuthenticationPublicKeys?: Array | undefined, copilotAuthenticationKeyStoreUrl?: string | undefined, oAuth2Connection?: string | undefined}) | undefined}) | undefined, orgDataPrivacySettings?: ({enabled?: boolean | undefined, useAnalytics?: boolean | undefined, storeDataPayload?: boolean | undefined, useContactProfiles?: boolean | undefined, useConversations?: boolean | undefined, maskIPAddress?: boolean | undefined, maskAnalytics?: boolean | undefined, maskLogging?: boolean | undefined}) | undefined, projectId?: string | undefined}}; export type CreateApiV20EndpointsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV20EndpointsResponse = z.object({foreignId: z.string().optional(), channel: z.enum(["facebook", "alexa", "slack", "generic", "inject", "rest", "realtime", "socket", "adminconsole", "webchat2", "dialogflow", "twilio", "twilio-sms", "line", "intercom", "microsoftBotFramework", "microsoftTeams", "sunshineConversations", "admin-webchat", "avaya", "nonConversational", "voiceGateway2", "amazonLex", "workplace", "webhook", "abstractRest", "userlike", "ringCentralEngage", "audioCodes", "bandwidth", "whatsapp", "eightByEight", "genesysBotConnector", "niceCXOne", "agentAssistVoice", "webchat3", "niceCXOneAAH", "zoomContactCenter", "mcpServer"]).optional(), flowId: z.string().optional(), localeId: z.string().optional(), URLToken: z.string().optional(), name: z.string().optional(), entrypoint: z.string().optional(), active: z.boolean().optional(), nluConnectorId: z.union([z.enum(["alexa", "dialogflow", "dialogflowBuiltIn", "amazonLexBuiltIn", "luis", "watson", "noNlu", "cognigy", "code", "generativeAI", "lex"]), z.string()]).optional(), useConversations: z.boolean().optional(), maskIPAddress: z.boolean().optional(), maskAnalytics: z.boolean().optional(), maskLogging: z.boolean().optional(), useContactProfiles: z.boolean().optional(), useAnalytics: z.boolean().optional(), useDashbotAnalytics: z.boolean().optional(), dashbotApikey: z.string().optional(), dashbotPlatform: z.string().optional(), disableInputSanitization: z.string().optional(), disableSkipUriTags: z.string().optional(), overrideSnapshotConnections: z.boolean().optional(), settings: z.object({accessScope: z.string().optional(), accessToken: z.string().optional(), appId: z.string().optional(), appSecret: z.string().optional(), backgroundImageUrl: z.string().optional(), basicAuthPassword: z.string().optional(), basicAuthUser: z.string().optional(), botUserId: z.string().optional(), businessHours: z.object({businessHours: z.array(z.object({startTime: z.string().optional(), endTime: z.string().optional(), weekDay: z.string().optional()})).optional(), enabled: z.boolean().optional(), text: z.string().optional(), mode: z.string().optional(), timeZone: z.string().optional(), title: z.string().optional()}).optional(), colorScheme: z.string().optional(), connectionName: z.string().optional(), customJSON: z.string().optional(), designTemplate: z.number().int().optional(), disableHtmlContentSanitization: z.boolean().optional(), disableInputAutocomplete: z.boolean().optional(), disableInputAutogrow: z.boolean().optional(), disableUrlButtonSanitization: z.boolean().optional(), enableGenericHTMLStyling: z.boolean().optional(), enableAsyncCommunication: z.boolean().optional(), engagementMessageText: z.string().optional(), displayGetStartedButton: z.boolean().optional(), dynamicImageAspectRatio: z.boolean().optional(), enableCollectMetadata: z.boolean().optional(), enableConnectionStatusIndicator: z.boolean().optional(), enableDemoWebchat: z.boolean().optional(), enableFileUpload: z.boolean().optional(), enablePersistentMenu: z.boolean().optional(), enableRating: z.enum(["onRequest", "always", "once"]).optional(), enableSTT: z.boolean().optional(), enableTTS: z.boolean().optional(), enableUnreadMessageBadge: z.boolean().optional(), enableUnreadMessagePreview: z.boolean().optional(), enableUnreadMessageSound: z.boolean().optional(), enableUnreadMessageTitleIndicator: z.boolean().optional(), enableTypingIndicator: z.boolean().optional(), facebookPageToken: z.string().optional(), focusInputAfterPostback: z.boolean().optional(), getStartedButtonText: z.string().optional(), getStartedPayload: z.string().optional(), getStartedText: z.string().optional(), getStartedData: z.string().optional(), headerLogoUrl: z.string().optional(), hubSecret: z.string().optional(), inputAutogrowMaxRows: z.number().optional(), inputPlaceholder: z.string().optional(), language: z.string().optional(), lineChannelAccessToken: z.string().optional(), lineChannelSecret: z.string().optional(), maintenance: z.object({enabled: z.boolean().optional(), mode: z.string().optional(), text: z.string().optional(), title: z.string().optional()}).optional(), mergeContactProfiles: z.boolean().optional(), messageDelay: z.number().int().optional(), messageLogoUrl: z.string().optional(), overwriteWebchatBundleUrl: z.string().optional(), ratingTitleText: z.string().optional(), ratingCommentText: z.string().optional(), ratingMessageHistoryRatingText: z.string().optional(), ratingMessageHistoryCommentText: z.string().optional(), reparseAlexaSlots: z.boolean().optional(), requestFacebookProfileData: z.boolean().optional(), restEndpointAuthentication: z.object({authenticationType: z.enum(["no-auth", "apiKey"]).optional()}).optional(), sessionExpiration: z.number().int().optional(), shouldOverwriteWebchatBundleUrl: z.boolean().optional(), showEngagementMessagesInChat: z.boolean().optional(), slackOAuthAccessToken: z.string().optional(), slackVerifyToken: z.string().optional(), sunshineConversationsChannelKeyId: z.string().optional(), sunshineConversationsChannelSecret: z.string().optional(), sunshineConversationsChannelUri: z.string().optional(), tenantId: z.string().optional(), updateContactProfileWithFacebookProfile: z.boolean().optional(), voice: z.string().optional(), webhookEndpointAuthentication: z.object({authenticationType: z.enum(["no-auth", "apiKey"]).optional()}).optional(), webhookUrl: z.string().optional(), skill: z.object({}).optional(), persistentMenu: z.object({}).optional()}).optional(), transformer: z.object({abortOnError: z.boolean().optional(), transformer: z.string().optional(), transpiledTransformer: z.string().optional(), inputTransformerEnabled: z.boolean().optional(), outputTransformerEnabled: z.boolean().optional(), finalPingTransformerEnabled: z.boolean().optional(), notifyTransformerEnabled: z.boolean().optional(), injectTransformerEnabled: z.boolean().optional()}).optional(), handoverSettings: z.object({provider: z.enum(["cognigy", "none", "rce"]).optional(), providerSettings: z.object({forwardOnlyHandoverConversations: z.boolean().optional(), getQueueUpdates: z.boolean().optional(), apiVersion: z.string().optional(), baseUrl: z.string().optional(), apiAccessToken: z.string().optional(), baseApiUrl: z.string().optional(), realtimeAccessToken: z.string().optional(), realtimeEndpointUrl: z.string().optional(), webhookSecret: z.string().optional(), botCategoryId: z.string().optional(), agentCategoryId: z.string().optional(), organizationId: z.string().optional(), deploymentId: z.string().optional(), buttonId: z.string().optional()}).optional(), agentAssistSettings: z.object({copilotType: z.enum(["none", "workspace", "whisper"]).optional(), agentAssistFlowId: z.string().optional(), agentAssistConfigId: z.string().optional(), enableTranscriptTile: z.boolean().optional(), enableTranscriptTileChatInput: z.boolean().optional(), redactTranscriptTileMessages: z.boolean().optional(), enableAgentCopilotAuthentication: z.boolean().optional(), blockNonJWTRequests: z.boolean().optional(), agentCopilotAuthentication: z.string().optional(), copilotAuthenticationMethod: z.enum(["default", "tokenSecret", "publicKey", "keyStore"]).optional(), copilotAuthenticationPublicKeys: z.array(z.string()).optional(), copilotAuthenticationKeyStoreUrl: z.string().optional(), oAuth2Connection: z.string().optional()}).optional()}).optional(), orgDataPrivacySettings: z.object({enabled: z.boolean().optional(), useAnalytics: z.boolean().optional(), storeDataPayload: z.boolean().optional(), useContactProfiles: z.boolean().optional(), useConversations: z.boolean().optional(), maskIPAddress: z.boolean().optional(), maskAnalytics: z.boolean().optional(), maskLogging: z.boolean().optional()}).optional(), _id: z.string().min(24).max(24).optional(), createdAt: z.number().int().gte(0).lte(2147483647).optional(), lastChanged: z.number().int().gte(0).lte(2147483647).optional(), createdBy: z.string().min(24).max(24).optional(), lastChangedBy: z.string().min(24).max(24).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 an Endpoint * * POST /v2.0/endpoints * * Also accepts auth: APIKeyQueryParam, CXoneTokenHeader, OAuth2 */ export const createApiV20Endpoints = async (args: CreateApiV20EndpointsArgs, options?: CreateApiV20EndpointsOptions) => { const {baseUrl = "https://api-trial.cognigy.ai/testing", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.resourceId != null) query.append("resourceId", String(args.resourceId)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2.0/endpoints${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(createApiV20EndpointsResponse, await res.json()) };