diff --git a/packages/botonic-plugin-flow-builder/src/constants.ts b/packages/botonic-plugin-flow-builder/src/constants.ts index af94804695..40ee626699 100644 --- a/packages/botonic-plugin-flow-builder/src/constants.ts +++ b/packages/botonic-plugin-flow-builder/src/constants.ts @@ -1,3 +1,5 @@ +export const FLOW_BUILDER_API_URL_PROD = + 'https://api.ent0.flowbuilder.prod.hubtype.com' export const SEPARATOR = '|' export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_` export const VARIABLE_PATTERN = /{([^}]+)}/g diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 83886a9d2c..7ff3c474af 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -2,7 +2,11 @@ import { Plugin, PluginPreRequest, Session } from '@botonic/core' import { ActionRequest } from '@botonic/react' import { FlowBuilderApi } from './api' -import { SEPARATOR, SOURCE_INFO_SEPARATOR } from './constants' +import { + FLOW_BUILDER_API_URL_PROD, + SEPARATOR, + SOURCE_INFO_SEPARATOR, +} from './constants' import { FlowCarousel, FlowContent, @@ -24,6 +28,7 @@ import { import { DEFAULT_FUNCTIONS } from './functions' import { BotonicPluginFlowBuilderOptions, + FlowBuilderJSONVersion, KnowledgeBaseResponse, PayloadParamsBase, } from './types' @@ -48,7 +53,9 @@ export default class BotonicPluginFlowBuilder implements Plugin { ) => Promise constructor(readonly options: BotonicPluginFlowBuilderOptions) { - this.flowUrl = options.flowUrl + const apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD + const jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST + this.flowUrl = `${apiUrl}/flow/${jsonVersion}` this.flow = options.flow this.getLocale = options.getLocale this.getAccessToken = resolveGetAccessToken(options) @@ -229,5 +236,9 @@ export default class BotonicPluginFlowBuilder implements Plugin { export * from './action' export * from './content-fields' -export { BotonicPluginFlowBuilderOptions, PayloadParamsBase } from './types' +export { + BotonicPluginFlowBuilderOptions, + FlowBuilderJSONVersion, + PayloadParamsBase, +} from './types' export * from './webview' diff --git a/packages/botonic-plugin-flow-builder/src/types.ts b/packages/botonic-plugin-flow-builder/src/types.ts index 47e1a5d950..9c552a504b 100644 --- a/packages/botonic-plugin-flow-builder/src/types.ts +++ b/packages/botonic-plugin-flow-builder/src/types.ts @@ -4,7 +4,8 @@ import { ActionRequest } from '@botonic/react' import { HtFlowBuilderData } from './content-fields/hubtype-fields' export interface BotonicPluginFlowBuilderOptions { - flowUrl: string + apiUrl?: string + jsonVersion?: FlowBuilderJSONVersion flow?: HtFlowBuilderData customFunctions?: Record getLocale: (session: Session) => string @@ -31,6 +32,11 @@ export enum ProcessEnvNodeEnvs { DEVELOPMENT = 'development', } +export enum FlowBuilderJSONVersion { + DRAFT = 'draft', + LATEST = 'latest', +} + export interface KnowledgeBaseResponse { answer: string hasKnowledge: boolean diff --git a/packages/botonic-plugin-flow-builder/src/webview/types.ts b/packages/botonic-plugin-flow-builder/src/webview/types.ts index 1709926642..0c40220c08 100644 --- a/packages/botonic-plugin-flow-builder/src/webview/types.ts +++ b/packages/botonic-plugin-flow-builder/src/webview/types.ts @@ -1,3 +1,5 @@ +import { FlowBuilderJSONVersion } from '../types' + export enum WebviewContentType { TEXT = 'webview-text', IMAGE = 'webview-image', @@ -25,7 +27,7 @@ export interface WebviewImageContent { export interface UseWebviewContentsProps { flowBuilderApiUrl: string - version: 'draft' | 'latest' + version: FlowBuilderJSONVersion orgId: string botId: string webviewId: string @@ -39,7 +41,7 @@ export interface UseWebviewContents { } export interface WebviewContentsContextType { - getTextContent: (code: string, locale: string) => string | undefined - getImageSrc: (code: string, locale: string) => string | undefined + getTextContent: (code: string) => string | undefined + getImageSrc: (code: string) => string | undefined setCurrentLocale: (locale: string) => void }