2
0

🚸 (whatsapp) Avoid multiple replies to be sent concurently

Closes #972, closes #1453
This commit is contained in:
Baptiste Arnaud
2024-04-18 09:38:22 +02:00
parent 94539e8ed3
commit 7bec58e745
12 changed files with 84 additions and 21 deletions

View File

@ -5,15 +5,18 @@ import { SessionState } from '@typebot.io/schemas'
type Props = {
id?: string
state: SessionState
isReplying?: boolean
}
export const createSession = ({
id,
state,
isReplying,
}: Props): Prisma.PrismaPromise<any> =>
prisma.chatSession.create({
data: {
id,
state,
isReplying,
},
})

View File

@ -4,7 +4,7 @@ import { sessionStateSchema } from '@typebot.io/schemas'
export const getSession = async (sessionId: string) => {
const session = await prisma.chatSession.findUnique({
where: { id: sessionId },
select: { id: true, state: true, updatedAt: true },
select: { id: true, state: true, updatedAt: true, isReplying: true },
})
if (!session) return null
return { ...session, state: sessionStateSchema.parse(session.state) }

View File

@ -0,0 +1,20 @@
import prisma from '@typebot.io/lib/prisma'
type Props = {
existingSessionId: string | undefined
newSessionId: string
}
export const setChatSessionHasReplying = async ({
existingSessionId,
newSessionId,
}: Props) => {
if (existingSessionId) {
return prisma.chatSession.updateMany({
where: { id: existingSessionId },
data: { isReplying: true },
})
}
return prisma.chatSession.createMany({
data: { id: newSessionId, isReplying: true, state: {} },
})
}

View File

@ -5,15 +5,18 @@ import { SessionState } from '@typebot.io/schemas'
type Props = {
id: string
state: SessionState
isReplying: boolean
}
export const updateSession = ({
id,
state,
isReplying,
}: Props): Prisma.PrismaPromise<any> =>
prisma.chatSession.updateMany({
where: { id },
data: {
state,
isReplying,
},
})