feat(bot): ⚡️ Add attachment in emails
This commit is contained in:
@@ -5,12 +5,14 @@ import {
|
||||
Flex,
|
||||
HStack,
|
||||
Switch,
|
||||
FormLabel,
|
||||
} from '@chakra-ui/react'
|
||||
import { CodeEditor } from 'components/shared/CodeEditor'
|
||||
import { CredentialsDropdown } from 'components/shared/CredentialsDropdown'
|
||||
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'
|
||||
import { Input, Textarea } from 'components/shared/Textbox'
|
||||
import { CredentialsType, SendEmailOptions } from 'models'
|
||||
import { VariableSearchInput } from 'components/shared/VariableSearchInput'
|
||||
import { CredentialsType, SendEmailOptions, Variable } from 'models'
|
||||
import React, { useState } from 'react'
|
||||
import { env } from 'utils'
|
||||
import { SmtpConfigModal } from './SmtpConfigModal'
|
||||
@@ -88,6 +90,14 @@ export const SendEmailSettings = ({ options, onOptionsChange }: Props) => {
|
||||
isBodyCode: options.isBodyCode ? !options.isBodyCode : true,
|
||||
})
|
||||
|
||||
const handleChangeAttachmentVariable = (
|
||||
variable: Pick<Variable, 'id' | 'name'> | undefined
|
||||
) =>
|
||||
onOptionsChange({
|
||||
...options,
|
||||
attachmentsVariableId: variable?.id,
|
||||
})
|
||||
|
||||
return (
|
||||
<Stack spacing={4}>
|
||||
<Stack>
|
||||
@@ -179,6 +189,15 @@ export const SendEmailSettings = ({ options, onOptionsChange }: Props) => {
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
<Stack>
|
||||
<FormLabel mb="0" htmlFor="variable">
|
||||
Attachments:
|
||||
</FormLabel>
|
||||
<VariableSearchInput
|
||||
initialVariableId={options.attachmentsVariableId}
|
||||
onSelectVariable={handleChangeAttachmentVariable}
|
||||
/>
|
||||
</Stack>
|
||||
<SmtpConfigModal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import prisma from 'libs/prisma'
|
||||
import {
|
||||
PublicTypebot,
|
||||
ResultValues,
|
||||
SendEmailOptions,
|
||||
SmtpCredentialsData,
|
||||
Typebot,
|
||||
} from 'models'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { createTransport, getTestMessageUrl } from 'nodemailer'
|
||||
@@ -60,9 +60,13 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
isBodyCode,
|
||||
isCustomBody,
|
||||
resultValues,
|
||||
fileUrls,
|
||||
} = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as SendEmailOptions & { resultValues: ResultValues }
|
||||
) as SendEmailOptions & {
|
||||
resultValues: ResultValues
|
||||
fileUrls?: string
|
||||
}
|
||||
|
||||
const { host, port, isTlsEnabled, username, password, from } =
|
||||
(await getEmailInfo(credentialsId)) ?? {}
|
||||
@@ -106,6 +110,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
to: recipients,
|
||||
replyTo,
|
||||
subject,
|
||||
attachments: fileUrls?.split(', ').map((url) => ({ path: url })),
|
||||
...emailBody,
|
||||
}
|
||||
try {
|
||||
@@ -163,9 +168,9 @@ const getEmailBody = async ({
|
||||
html: isBodyCode ? body : undefined,
|
||||
text: !isBodyCode ? body : undefined,
|
||||
}
|
||||
const typebot = (await prisma.typebot.findUnique({
|
||||
where: { id: typebotId },
|
||||
})) as unknown as Typebot
|
||||
const typebot = (await prisma.publicTypebot.findUnique({
|
||||
where: { typebotId },
|
||||
})) as unknown as PublicTypebot
|
||||
if (!typebot) return
|
||||
const linkedTypebots = await getLinkedTypebots(typebot)
|
||||
const answers = parseAnswers({
|
||||
|
||||
Reference in New Issue
Block a user