2
0

🔧 (scripts) Add typebot fix script

Closes #192
This commit is contained in:
Baptiste Arnaud
2022-12-27 10:05:50 +01:00
parent 8382fd7b71
commit ad72557310
7 changed files with 217 additions and 6 deletions

View File

@ -111,7 +111,8 @@
"groupId": "o4SH1UtKANnW5N5D67oZUz",
"options": {
"labels": { "button": "Send", "placeholder": "Type your email..." },
"variableId": "v3VFChNVSCXQ2rXv4DrJ8Ah"
"variableId": "v3VFChNVSCXQ2rXv4DrJ8Ah",
"retryMessageContent": "This email doesn't seem to be valid. Can you type it again?"
},
"outgoingEdgeId": "w3MiN1Ct38jT5NykVsgmb5"
}

View File

@ -5,6 +5,8 @@ import { canReadTypebots, canWriteTypebots } from '@/utils/api/dbRules'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
import { getAuthenticatedUser } from '@/features/auth/api'
import { archiveResults } from '@/features/results/api'
import { typebotSchema } from 'models'
import { captureEvent } from '@sentry/nextjs'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
@ -55,6 +57,16 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
if (req.method === 'PUT') {
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
const parser = typebotSchema.safeParse(data)
if ('error' in parser) {
captureEvent({
message: 'Typebot schema validation failed',
extra: {
typebotId: data.id,
error: parser.error,
},
})
}
const existingTypebot = await prisma.typebot.findFirst({
where: canReadTypebots(typebotId, user),
select: { updatedAt: true },