2
0

🐛 (wa) Fix WhatsApp session stuck if state object is empty

Closes #1513
This commit is contained in:
Baptiste Arnaud
2024-05-15 17:47:38 +02:00
parent 91603aa6ce
commit 8351e20fd3
4 changed files with 22 additions and 5 deletions

View File

@ -1,11 +1,19 @@
import prisma from '@typebot.io/lib/prisma'
import { sessionStateSchema } from '@typebot.io/schemas'
import { deleteSession } from './deleteSession'
export const getSession = async (sessionId: string) => {
const session = await prisma.chatSession.findUnique({
where: { id: sessionId },
select: { id: true, state: true, updatedAt: true, isReplying: true },
})
if (!session) return null
return { ...session, state: sessionStateSchema.parse(session.state) }
if (!session?.state) return null
if (Object.keys(session.state).length === 0) {
await deleteSession(session.id)
return null
}
return {
...session,
state: sessionStateSchema.parse(session.state),
}
}

View File

@ -0,0 +1,7 @@
import prisma from '@typebot.io/lib/prisma'
export const removeIsReplyingInChatSession = async (id: string) =>
prisma.chatSession.updateMany({
where: { id },
data: { isReplying: false },
})

View File

@ -4,7 +4,7 @@ type Props = {
existingSessionId: string | undefined
newSessionId: string
}
export const setChatSessionHasReplying = async ({
export const setIsReplyingInChatSession = async ({
existingSessionId,
newSessionId,
}: Props) => {