2
0

♻️ Introduce typebot v6 with events (#1013)

Closes #885
This commit is contained in:
Baptiste Arnaud
2023-11-08 15:34:16 +01:00
committed by GitHub
parent 68e4fc71fb
commit 35300eaf34
634 changed files with 58971 additions and 31449 deletions

View File

@@ -1,25 +1,25 @@
import {
TypingEmulation,
defaultSettings,
} from '@typebot.io/schemas/features/typebot/settings'
import { Settings } from '@typebot.io/schemas/features/typebot/settings'
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
type Props = {
bubbleContent: string
typingSettings?: TypingEmulation
typingSettings?: Settings['typingEmulation']
}
export const computeTypingDuration = ({
bubbleContent,
typingSettings = defaultSettings({ isBrandingEnabled: false })
.typingEmulation,
typingSettings,
}: Props) => {
let wordCount = bubbleContent.match(/(\w+)/g)?.length ?? 0
if (wordCount === 0) wordCount = bubbleContent.length
const typedWordsPerMinute = typingSettings.speed
let typingTimeout = typingSettings.enabled
? (wordCount / typedWordsPerMinute) * 60000
: 0
if (typingTimeout > typingSettings.maxDelay * 1000)
typingTimeout = typingSettings.maxDelay * 1000
const { enabled, speed, maxDelay } = {
enabled: typingSettings?.enabled ?? defaultSettings.typingEmulation.enabled,
speed: typingSettings?.speed ?? defaultSettings.typingEmulation.speed,
maxDelay:
typingSettings?.maxDelay ?? defaultSettings.typingEmulation.maxDelay,
}
const typedWordsPerMinute = speed
let typingTimeout = enabled ? (wordCount / typedWordsPerMinute) * 60000 : 0
if (typingTimeout > maxDelay * 1000) typingTimeout = maxDelay * 1000
return typingTimeout
}