⚡️ Reset remembered state if the typebot is updated (#1675)
Wipe stored chat state if a typebot is updated. Resolves #1508 Resolves #1427 https://github.com/user-attachments/assets/7668d6a7-2916-4158-b715-1cccaeaf6ddf --------- Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
This commit is contained in:
@ -96,6 +96,7 @@ export const startChat = async ({
|
||||
id: typebot.id,
|
||||
theme: typebot.theme,
|
||||
settings: typebot.settings,
|
||||
publishedAt: typebot.publishedAt,
|
||||
},
|
||||
messages,
|
||||
input,
|
||||
|
@ -31,5 +31,6 @@ export const findPublicTypebot = ({ publicId }: Props) =>
|
||||
},
|
||||
},
|
||||
},
|
||||
updatedAt: true,
|
||||
},
|
||||
})
|
||||
|
@ -18,5 +18,6 @@ export const findTypebot = ({ id, userId }: Props) =>
|
||||
theme: true,
|
||||
variables: true,
|
||||
isArchived: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
})
|
||||
|
@ -278,6 +278,7 @@ export const startSession = async ({
|
||||
theme: sanitizeAndParseTheme(typebot.theme, {
|
||||
variables: initialState.typebotsQueue[0].typebot.variables,
|
||||
}),
|
||||
publishedAt: typebot.updatedAt,
|
||||
},
|
||||
dynamicTheme: parseDynamicTheme(newSessionState),
|
||||
logs: startLogs.length > 0 ? startLogs : undefined,
|
||||
@ -296,6 +297,7 @@ export const startSession = async ({
|
||||
theme: sanitizeAndParseTheme(typebot.theme, {
|
||||
variables: initialState.typebotsQueue[0].typebot.variables,
|
||||
}),
|
||||
publishedAt: typebot.updatedAt,
|
||||
},
|
||||
messages,
|
||||
input,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/js",
|
||||
"version": "0.3.7",
|
||||
"version": "0.3.8",
|
||||
"description": "Javascript library to display typebots on your website",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
@ -150,8 +150,25 @@ export const Bot = (props: BotProps & { class?: string }) => {
|
||||
const initialChatInStorage = getInitialChatReplyFromStorage(
|
||||
data.typebot.id
|
||||
)
|
||||
if (initialChatInStorage) {
|
||||
setInitialChatReply(initialChatInStorage)
|
||||
if (
|
||||
initialChatInStorage &&
|
||||
initialChatInStorage.typebot.publishedAt &&
|
||||
data.typebot.publishedAt
|
||||
) {
|
||||
if (
|
||||
new Date(initialChatInStorage.typebot.publishedAt).getTime() ===
|
||||
new Date(data.typebot.publishedAt).getTime()
|
||||
) {
|
||||
setInitialChatReply(initialChatInStorage)
|
||||
} else {
|
||||
// Restart chat by resetting remembered state
|
||||
wipeExistingChatStateInStorage(data.typebot.id)
|
||||
setInitialChatReply(data)
|
||||
setInitialChatReplyInStorage(data, {
|
||||
typebotId: data.typebot.id,
|
||||
storage,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
setInitialChatReply(data)
|
||||
setInitialChatReplyInStorage(data, {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/nextjs",
|
||||
"version": "0.3.7",
|
||||
"version": "0.3.8",
|
||||
"description": "Convenient library to display typebots on your Next.js website",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/react",
|
||||
"version": "0.3.7",
|
||||
"version": "0.3.8",
|
||||
"description": "Convenient library to display typebots on your React app",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -12,6 +12,7 @@ export const leadGenerationTypebot: StartTypebot = {
|
||||
version: '3',
|
||||
id: 'clckrl4q5000t3b6sabwokaar',
|
||||
events: null,
|
||||
publishedAt: new Date(),
|
||||
groups: [
|
||||
{
|
||||
id: 'clckrl4q5000g3b6skizhd262',
|
||||
|
@ -170,6 +170,7 @@ const startTypebotPick = {
|
||||
variables: true,
|
||||
settings: true,
|
||||
theme: true,
|
||||
updatedAt: true,
|
||||
} as const
|
||||
export const startTypebotSchema = z.preprocess(
|
||||
preprocessTypebot,
|
||||
@ -381,6 +382,7 @@ export const startChatResponseSchema = z
|
||||
id: z.string(),
|
||||
theme: themeSchema,
|
||||
settings: settingsSchema,
|
||||
publishedAt: z.coerce.date().optional(),
|
||||
}),
|
||||
})
|
||||
.merge(chatResponseBaseSchema)
|
||||
|
Reference in New Issue
Block a user