2
0
Files
bot/apps/builder/pages/api/mock/webhook.ts
Baptiste Arnaud 8501d39234 build: 🏗️ Add Sentry to builder
2022-02-14 10:57:57 +01:00

28 lines
841 B
TypeScript

import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
const firstParam = req.query.firstParam.toString()
const secondParam = req.query.secondParam.toString()
const customHeader = req.headers['custom-typebot']
const { body } = req
if (
body.customField === 'secret4' &&
customHeader === 'secret3' &&
secondParam === 'secret2' &&
firstParam === 'secret1'
) {
return res.status(200).send([
{ name: 'John', age: 21 },
{ name: 'Tim', age: 52 },
])
}
return res.status(400).send({ message: 'Bad request' })
}
return methodNotAllowed(res)
}
export default withSentry(handler)