⚡ (whatsapp) Improve / fix markdown serializer
Forked remark-slate code to create Typebot's own serializer Closes #1056
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import { ButtonItem, ContinueChatResponse } from '@typebot.io/schemas'
|
||||
import { WhatsAppSendingMessage } from '@typebot.io/schemas/features/whatsapp'
|
||||
import { convertRichTextToWhatsAppText } from './convertRichTextToWhatsAppText'
|
||||
import { isDefined, isEmpty } from '@typebot.io/lib/utils'
|
||||
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
|
||||
import { InputBlockType } from '@typebot.io/schemas/features/blocks/inputs/constants'
|
||||
import { defaultPictureChoiceOptions } from '@typebot.io/schemas/features/blocks/inputs/pictureChoice/constants'
|
||||
import { defaultChoiceInputOptions } from '@typebot.io/schemas/features/blocks/inputs/choice/constants'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/serializer/convertRichTextToMarkdown'
|
||||
|
||||
export const convertInputToWhatsAppMessages = (
|
||||
input: NonNullable<ContinueChatResponse['input']>,
|
||||
@ -13,7 +13,9 @@ export const convertInputToWhatsAppMessages = (
|
||||
): WhatsAppSendingMessage[] => {
|
||||
const lastMessageText =
|
||||
lastMessage?.type === BubbleBlockType.TEXT
|
||||
? convertRichTextToWhatsAppText(lastMessage.content.richText ?? [])
|
||||
? convertRichTextToMarkdown(lastMessage.content.richText ?? [], {
|
||||
flavour: 'whatsapp',
|
||||
})
|
||||
: undefined
|
||||
switch (input.type) {
|
||||
case InputBlockType.DATE:
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { ContinueChatResponse } from '@typebot.io/schemas'
|
||||
import { WhatsAppSendingMessage } from '@typebot.io/schemas/features/whatsapp'
|
||||
import { convertRichTextToWhatsAppText } from './convertRichTextToWhatsAppText'
|
||||
import { isSvgSrc } from '@typebot.io/lib/utils'
|
||||
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
|
||||
import { VideoBubbleContentType } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/serializer/convertRichTextToMarkdown'
|
||||
|
||||
const mp4HttpsUrlRegex = /^https:\/\/.*\.mp4$/
|
||||
|
||||
@ -17,7 +17,9 @@ export const convertMessageToWhatsAppMessage = (
|
||||
return {
|
||||
type: 'text',
|
||||
text: {
|
||||
body: convertRichTextToWhatsAppText(message.content.richText),
|
||||
body: convertRichTextToMarkdown(message.content.richText, {
|
||||
flavour: 'whatsapp',
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
import { TElement } from '@udecode/plate-common'
|
||||
import { serialize } from 'remark-slate'
|
||||
|
||||
export const convertRichTextToWhatsAppText = (richText: TElement[]): string =>
|
||||
richText
|
||||
.map((chunk) =>
|
||||
serialize(chunk)?.replaceAll('**', '*').replaceAll('&#39;', "'")
|
||||
)
|
||||
.join('\n')
|
Reference in New Issue
Block a user