2
0

🐛 Fix remember user streaming messages

This commit is contained in:
Baptiste Arnaud
2024-07-15 15:06:38 +02:00
parent 043f0054b0
commit f4cd1d5ba3
7 changed files with 21 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.3.4", "version": "0.3.5",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -171,7 +171,10 @@ export const ChatChunk = (props: Props) => {
: '100%', : '100%',
}} }}
> >
<StreamingBubble streamingMessageId={streamingMessageId} /> <StreamingBubble
streamingMessageId={streamingMessageId}
context={props.context}
/>
</div> </div>
</div> </div>
)} )}

View File

@ -73,7 +73,7 @@ type Props = {
export const ConversationContainer = (props: Props) => { export const ConversationContainer = (props: Props) => {
let chatContainer: HTMLDivElement | undefined let chatContainer: HTMLDivElement | undefined
const [chatChunks, setChatChunks, isRecovered] = persist( const [chatChunks, setChatChunks, isRecovered, setIsRecovered] = persist(
createSignal<ChatChunkType[]>([ createSignal<ChatChunkType[]>([
{ {
input: props.initialChatReply.input, input: props.initialChatReply.input,
@ -146,6 +146,7 @@ export const ConversationContainer = (props: Props) => {
message?: string, message?: string,
attachments?: Answer['attachments'] attachments?: Answer['attachments']
) => { ) => {
setIsRecovered(false)
setHasError(false) setHasError(false)
const currentInputBlock = [...chatChunks()].pop()?.input const currentInputBlock = [...chatChunks()].pop()?.input
if (currentInputBlock?.id && props.onAnswer && message) if (currentInputBlock?.id && props.onAnswer && message)
@ -274,6 +275,7 @@ export const ConversationContainer = (props: Props) => {
const processClientSideActions = async ( const processClientSideActions = async (
actions: NonNullable<ContinueChatResponse['clientSideActions']> actions: NonNullable<ContinueChatResponse['clientSideActions']>
) => { ) => {
console.log('YES')
if (isRecovered()) return if (isRecovered()) return
for (const action of actions) { for (const action of actions) {
if ( if (

View File

@ -3,13 +3,19 @@ import { For, createEffect, createSignal } from 'solid-js'
import { marked } from 'marked' import { marked } from 'marked'
import domPurify from 'dompurify' import domPurify from 'dompurify'
import { isNotEmpty } from '@typebot.io/lib' import { isNotEmpty } from '@typebot.io/lib'
import { persist } from '@/utils/persist'
import { BotContext } from '@/types'
type Props = { type Props = {
streamingMessageId: string streamingMessageId: string
context: BotContext
} }
export const StreamingBubble = (props: Props) => { export const StreamingBubble = (props: Props) => {
const [content, setContent] = createSignal<string[]>([]) const [content, setContent] = persist(createSignal<string[]>([]), {
key: `typebot-streaming-message-${props.streamingMessageId}`,
storage: props.context.storage,
})
marked.use({ marked.use({
renderer: { renderer: {

View File

@ -16,9 +16,9 @@ type Params = {
export function persist<T>( export function persist<T>(
signal: Signal<T>, signal: Signal<T>,
params: Params params: Params
): [...Signal<T>, () => boolean] { ): [...Signal<T>, () => boolean, Setter<boolean>] {
const [isRecovered, setIsRecovered] = createSignal(false) const [isRecovered, setIsRecovered] = createSignal(false)
if (!params.storage) return [...signal, () => false] if (!params.storage) return [...signal, isRecovered, setIsRecovered]
const storage = parseRememberUserStorage( const storage = parseRememberUserStorage(
params.storage || defaultSettings.general.rememberUser.storage params.storage || defaultSettings.general.rememberUser.storage
@ -55,7 +55,8 @@ export function persist<T>(
storage.setItem(params.key, value) storage.setItem(params.key, value)
}, },
isRecovered, isRecovered,
] as [...typeof signal, () => boolean] setIsRecovered,
] as [...typeof signal, typeof isRecovered, typeof setIsRecovered]
} }
const parseRememberUserStorage = ( const parseRememberUserStorage = (

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/nextjs", "name": "@typebot.io/nextjs",
"version": "0.3.4", "version": "0.3.5",
"description": "Convenient library to display typebots on your Next.js website", "description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.3.4", "version": "0.3.5",
"description": "Convenient library to display typebots on your React app", "description": "Convenient library to display typebots on your React app",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",