2
0
Files
bot/packages/bot-engine/queries/getSession.ts

20 lines
597 B
TypeScript
Raw Normal View History

import prisma from '@typebot.io/lib/prisma'
import { sessionStateSchema } from '@typebot.io/schemas'
import { deleteSession } from './deleteSession'
2022-11-29 10:02:40 +01:00
export const getSession = async (sessionId: string) => {
const session = await prisma.chatSession.findUnique({
2022-11-29 10:02:40 +01:00
where: { id: sessionId },
select: { id: true, state: true, updatedAt: true, isReplying: true },
})
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),
}
2022-11-29 10:02:40 +01:00
}