⚡ (whatsapp) Improve / fix markdown serializer
Forked remark-slate code to create Typebot's own serializer Closes #1056
This commit is contained in:
@@ -30,14 +30,13 @@
|
||||
"nodemailer": "6.9.3",
|
||||
"openai": "4.19.0",
|
||||
"qs": "6.11.2",
|
||||
"remark-slate": "1.8.6",
|
||||
"stripe": "12.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/nodemailer": "6.4.8",
|
||||
"@types/qs": "6.9.7",
|
||||
"@typebot.io/forge-schemas": "workspace:*",
|
||||
"@typebot.io/forge": "workspace:*",
|
||||
"@typebot.io/forge-repository": "workspace:*"
|
||||
"@typebot.io/forge-repository": "workspace:*",
|
||||
"@typebot.io/forge-schemas": "workspace:*",
|
||||
"@types/nodemailer": "6.4.8",
|
||||
"@types/qs": "6.9.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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