2
0

♻️ Introduce typebot v6 with events (#1013)

Closes #885
This commit is contained in:
Baptiste Arnaud
2023-11-08 15:34:16 +01:00
committed by GitHub
parent 68e4fc71fb
commit 35300eaf34
634 changed files with 58971 additions and 31449 deletions

View File

@@ -3,7 +3,6 @@ import {
AnswerInSessionState,
ReplyLog,
SendEmailBlock,
SendEmailOptions,
SessionState,
SmtpCredentials,
TypebotInSession,
@@ -20,6 +19,7 @@ import { env } from '@typebot.io/env'
import { ExecuteIntegrationResponse } from '../../../types'
import prisma from '@typebot.io/lib/prisma'
import { parseVariables } from '../../../variables/parseVariables'
import { defaultSendEmailOptions } from '@typebot.io/schemas/features/blocks/integrations/sendEmail/constants'
export const executeSendEmailBlock = async (
state: SessionState,
@@ -41,24 +41,34 @@ export const executeSendEmailBlock = async (
}
const bodyUniqueVariable = findUniqueVariableValue(typebot.variables)(
options.body
options?.body
)
const body = bodyUniqueVariable
? stringifyUniqueVariableValueAsHtml(bodyUniqueVariable)
: parseVariables(typebot.variables, { isInsideHtml: true })(
options.body ?? ''
options?.body ?? ''
)
if (!options?.recipients)
return { outgoingEdgeId: block.outgoingEdgeId, logs }
try {
const sendEmailLogs = await sendEmail({
typebot,
answers,
credentialsId: options.credentialsId,
credentialsId:
options.credentialsId ?? defaultSendEmailOptions.credentialsId,
recipients: options.recipients.map(parseVariables(typebot.variables)),
subject: parseVariables(typebot.variables)(options.subject ?? ''),
subject: options.subject
? parseVariables(typebot.variables)(options?.subject)
: undefined,
body,
cc: (options.cc ?? []).map(parseVariables(typebot.variables)),
bcc: (options.bcc ?? []).map(parseVariables(typebot.variables)),
cc: options.cc
? options.cc.map(parseVariables(typebot.variables))
: undefined,
bcc: options.bcc
? options.bcc.map(parseVariables(typebot.variables))
: undefined,
replyTo: options.replyTo
? parseVariables(typebot.variables)(options.replyTo)
: undefined,
@@ -91,7 +101,16 @@ const sendEmail = async ({
isBodyCode,
isCustomBody,
fileUrls,
}: SendEmailOptions & {
}: {
credentialsId: string
recipients: string[]
body: string | undefined
subject: string | undefined
cc: string[] | undefined
bcc: string[] | undefined
replyTo: string | undefined
isBodyCode: boolean | undefined
isCustomBody: boolean | undefined
typebot: TypebotInSession
answers: AnswerInSessionState[]
fileUrls?: string | string[]
@@ -216,9 +235,10 @@ const getEmailBody = async ({
}: {
typebot: TypebotInSession
answersInSession: AnswerInSessionState[]
} & Pick<SendEmailOptions, 'isCustomBody' | 'isBodyCode' | 'body'>): Promise<
{ html?: string; text?: string } | undefined
> => {
} & Pick<
NonNullable<SendEmailBlock['options']>,
'isCustomBody' | 'isBodyCode' | 'body'
>): Promise<{ html?: string; text?: string } | undefined> => {
if (isCustomBody || (isNotDefined(isCustomBody) && !isEmpty(body)))
return {
html: isBodyCode ? body : undefined,