Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru89 committed Apr 15, 2024
1 parent 93b55f9 commit fcdc782
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/botonic-plugin-flow-builder/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 14 additions & 3 deletions packages/botonic-plugin-flow-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,6 +28,7 @@ import {
import { DEFAULT_FUNCTIONS } from './functions'
import {
BotonicPluginFlowBuilderOptions,
FlowBuilderJSONVersion,
KnowledgeBaseResponse,
PayloadParamsBase,
} from './types'
Expand All @@ -48,7 +53,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
) => Promise<KnowledgeBaseResponse>

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)
Expand Down Expand Up @@ -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'
8 changes: 7 additions & 1 deletion packages/botonic-plugin-flow-builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>
getLocale: (session: Session) => string
Expand All @@ -31,6 +32,11 @@ export enum ProcessEnvNodeEnvs {
DEVELOPMENT = 'development',
}

export enum FlowBuilderJSONVersion {
DRAFT = 'draft',
LATEST = 'latest',
}

export interface KnowledgeBaseResponse {
answer: string
hasKnowledge: boolean
Expand Down
8 changes: 5 additions & 3 deletions packages/botonic-plugin-flow-builder/src/webview/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FlowBuilderJSONVersion } from '../types'

export enum WebviewContentType {
TEXT = 'webview-text',
IMAGE = 'webview-image',
Expand Down Expand Up @@ -25,7 +27,7 @@ export interface WebviewImageContent {

export interface UseWebviewContentsProps {
flowBuilderApiUrl: string
version: 'draft' | 'latest'
version: FlowBuilderJSONVersion
orgId: string
botId: string
webviewId: string
Expand All @@ -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
}

0 comments on commit fcdc782

Please sign in to comment.