♻️ (results) Introduce tRPC and use it for the results
This commit is contained in:
@ -34,7 +34,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const { resultValues, variables } = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as {
|
||||
resultValues: ResultValues | undefined
|
||||
resultValues:
|
||||
| (Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
})
|
||||
| undefined
|
||||
variables: Variable[]
|
||||
}
|
||||
const typebot = (await prisma.typebot.findUnique({
|
||||
@ -83,7 +87,9 @@ export const executeWebhook =
|
||||
webhook: Webhook,
|
||||
variables: Variable[],
|
||||
groupId: string,
|
||||
resultValues?: ResultValues,
|
||||
resultValues?: Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
},
|
||||
resultId?: string
|
||||
): Promise<WebhookResponse> => {
|
||||
if (!webhook.url || !webhook.method)
|
||||
@ -193,7 +199,9 @@ const getBodyContent =
|
||||
groupId,
|
||||
}: {
|
||||
body?: string | null
|
||||
resultValues?: ResultValues
|
||||
resultValues?: Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
}
|
||||
groupId: string
|
||||
}): Promise<string | undefined> => {
|
||||
if (!body) return
|
||||
|
@ -26,7 +26,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const { resultValues, variables } = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as {
|
||||
resultValues: ResultValues | undefined
|
||||
resultValues:
|
||||
| (Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
})
|
||||
| undefined
|
||||
variables: Variable[]
|
||||
}
|
||||
const typebot = (await prisma.typebot.findUnique({
|
||||
|
@ -54,7 +54,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
} = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as SendEmailOptions & {
|
||||
resultValues: ResultValues
|
||||
resultValues: Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
}
|
||||
fileUrls?: string
|
||||
}
|
||||
const { name: replyToName } = parseEmailRecipient(replyTo)
|
||||
@ -162,10 +164,14 @@ const getEmailBody = async ({
|
||||
isBodyCode,
|
||||
typebotId,
|
||||
resultValues,
|
||||
}: { typebotId: string; resultValues: ResultValues } & Pick<
|
||||
SendEmailOptions,
|
||||
'isCustomBody' | 'isBodyCode' | 'body'
|
||||
>): Promise<{ html?: string; text?: string } | undefined> => {
|
||||
}: {
|
||||
typebotId: string
|
||||
resultValues: Omit<ResultValues, 'createdAt'> & {
|
||||
createdAt: string
|
||||
}
|
||||
} & Pick<SendEmailOptions, 'isCustomBody' | 'isBodyCode' | 'body'>): Promise<
|
||||
{ html?: string; text?: string } | undefined
|
||||
> => {
|
||||
if (isCustomBody || (isNotDefined(isCustomBody) && !isEmpty(body)))
|
||||
return {
|
||||
html: isBodyCode ? body : undefined,
|
||||
|
Reference in New Issue
Block a user