2
0

(api) Add textBubbleContentFormat option

Closes #1111
This commit is contained in:
Baptiste Arnaud
2024-05-23 16:30:56 +02:00
parent 3031d26f03
commit c53ce349af
22 changed files with 155 additions and 37 deletions

View File

@ -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[]),
},
}
}