From 53e778e0bbde74a236036d8bc6d9738cbd23cf84 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 25 Jan 2024 08:43:55 +0100 Subject: [PATCH] :monocle_face: Add inspectChatSession script --- packages/scripts/inspectChatSession.ts | 35 ++++++++++++++++++++++++++ packages/scripts/package.json | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packages/scripts/inspectChatSession.ts diff --git a/packages/scripts/inspectChatSession.ts b/packages/scripts/inspectChatSession.ts new file mode 100644 index 000000000..7c8327894 --- /dev/null +++ b/packages/scripts/inspectChatSession.ts @@ -0,0 +1,35 @@ +import { PrismaClient } from '@typebot.io/prisma' +import { promptAndSetEnvironment } from './utils' +import * as p from '@clack/prompts' + +const inspectChatSession = async () => { + await promptAndSetEnvironment('production') + + const id = await p.text({ + message: 'Session ID?', + }) + + if (!id || typeof id !== 'string') { + console.log('No ID provided') + return + } + + const prisma = new PrismaClient({ + log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'], + }) + + const chatSession = await prisma.chatSession.findFirst({ + where: { + id, + }, + }) + + if (!chatSession) { + console.log('Session not found') + return + } + + console.log(JSON.stringify(chatSession, null, 2)) +} + +inspectChatSession() diff --git a/packages/scripts/package.json b/packages/scripts/package.json index ea1be2f58..d0a58b99c 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -27,7 +27,8 @@ "inspectWorkspace": "tsx inspectWorkspace.ts", "getCoupon": "tsx getCoupon.ts", "exportResults": "tsx exportResults.ts", - "updateUserEmail": "tsx updateUserEmail.ts" + "updateUserEmail": "tsx updateUserEmail.ts", + "inspectChatSession": "tsx inspectChatSession.ts" }, "devDependencies": { "@typebot.io/emails": "workspace:*",