@ -11,15 +11,17 @@ import {
|
||||
getVariablesToParseInfoInText,
|
||||
parseVariables,
|
||||
} from '@typebot.io/variables/parseVariables'
|
||||
import { TDescendant } from '@udecode/plate-common'
|
||||
import { TDescendant, TElement } from '@udecode/plate-common'
|
||||
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
|
||||
import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
|
||||
import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
|
||||
|
||||
type Params = {
|
||||
version: 1 | 2
|
||||
typebotVersion: Typebot['version']
|
||||
variables: Variable[]
|
||||
textBubbleContentFormat: 'richText' | 'markdown'
|
||||
}
|
||||
|
||||
export type BubbleBlockWithDefinedContent = BubbleBlock & {
|
||||
@ -28,7 +30,7 @@ export type BubbleBlockWithDefinedContent = BubbleBlock & {
|
||||
|
||||
export const parseBubbleBlock = (
|
||||
block: BubbleBlockWithDefinedContent,
|
||||
{ version, variables, typebotVersion }: Params
|
||||
{ version, variables, typebotVersion, textBubbleContentFormat }: Params
|
||||
): ContinueChatResponse['messages'][0] => {
|
||||
switch (block.type) {
|
||||
case BubbleBlockType.TEXT: {
|
||||
@ -36,21 +38,29 @@ export const parseBubbleBlock = (
|
||||
return {
|
||||
...block,
|
||||
content: {
|
||||
...block.content,
|
||||
type: 'richText',
|
||||
richText: (block.content?.richText ?? []).map(
|
||||
deepParseVariables(variables)
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
const richText = parseVariablesInRichText(block.content?.richText ?? [], {
|
||||
variables,
|
||||
takeLatestIfList: typebotVersion !== '6',
|
||||
}).parsedElements
|
||||
return {
|
||||
...block,
|
||||
content: {
|
||||
...block.content,
|
||||
richText: parseVariablesInRichText(block.content?.richText ?? [], {
|
||||
variables,
|
||||
takeLatestIfList: typebotVersion !== '6',
|
||||
}).parsedElements,
|
||||
},
|
||||
content:
|
||||
textBubbleContentFormat === 'richText'
|
||||
? {
|
||||
type: 'richText',
|
||||
richText,
|
||||
}
|
||||
: {
|
||||
type: 'markdown',
|
||||
markdown: convertRichTextToMarkdown(richText as TElement[]),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user