2
0

🔊 Add more error logs for sendEmail block

This commit is contained in:
Baptiste Arnaud
2023-03-16 12:28:24 +01:00
parent cd09f1075f
commit 3d8cb40f06
6 changed files with 45 additions and 24 deletions

View File

@ -17,6 +17,7 @@ import { decrypt } from '@typebot.io/lib/api/encryption'
import { saveErrorLog } from '@/features/logs/saveErrorLog'
import { updateVariables } from '@/features/variables/updateVariables'
import { parseVariables } from '@/features/variables/parseVariables'
import { saveSuccessLog } from '@/features/logs/saveSuccessLog'
export const createChatCompletionOpenAI = async (
state: SessionState,
@ -89,6 +90,11 @@ export const createChatCompletionOpenAI = async (
}, [])
if (newVariables.length > 0)
newSessionState = await updateVariables(newSessionState)(newVariables)
state.result &&
(await saveSuccessLog({
resultId: state.result.id,
message: 'OpenAI block successfully executed',
}))
return {
outgoingEdgeId,
newSessionState,

View File

@ -37,23 +37,35 @@ export const executeSendEmailBlock = async (
},
],
}
await sendEmail({
typebotId: typebot.id,
result,
credentialsId: options.credentialsId,
recipients: options.recipients.map(parseVariables(variables)),
subject: parseVariables(variables)(options.subject ?? ''),
body: parseVariables(variables)(options.body ?? ''),
cc: (options.cc ?? []).map(parseVariables(variables)),
bcc: (options.bcc ?? []).map(parseVariables(variables)),
replyTo: options.replyTo
? parseVariables(variables)(options.replyTo)
: undefined,
fileUrls:
variables.find(byId(options.attachmentsVariableId))?.value ?? undefined,
isCustomBody: options.isCustomBody,
isBodyCode: options.isBodyCode,
})
try {
await sendEmail({
typebotId: typebot.id,
result,
credentialsId: options.credentialsId,
recipients: options.recipients.map(parseVariables(variables)),
subject: parseVariables(variables)(options.subject ?? ''),
body: parseVariables(variables)(options.body ?? ''),
cc: (options.cc ?? []).map(parseVariables(variables)),
bcc: (options.bcc ?? []).map(parseVariables(variables)),
replyTo: options.replyTo
? parseVariables(variables)(options.replyTo)
: undefined,
fileUrls:
variables.find(byId(options.attachmentsVariableId))?.value ?? undefined,
isCustomBody: options.isCustomBody,
isBodyCode: options.isBodyCode,
})
} catch (err) {
await saveErrorLog({
resultId: result.id,
message: 'Email not sent',
details: {
error: err,
},
})
}
return { outgoingEdgeId: block.outgoingEdgeId }
}