Skip to content

Commit

Permalink
feat(bot): ⚡️ Add attachment in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 24, 2022
1 parent 2441abe commit 7c3345a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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}
Expand Down
15 changes: 10 additions & 5 deletions apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)) ?? {}
Expand Down Expand Up @@ -106,6 +110,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
to: recipients,
replyTo,
subject,
attachments: fileUrls?.split(', ').map((url) => ({ path: url })),
...emailBody,
}
try {
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const FileUploadForm = ({
files: [
{
file,
path: `public/results/${resultId}/${id}`,
path: `public/results/${resultId}/${id}/${file.name}`,
},
],
})
Expand Down
1 change: 1 addition & 0 deletions packages/bot-engine/src/services/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ const sendEmail = async (
cc: (options.cc ?? []).map(parseVariables(variables)),
bcc: (options.bcc ?? []).map(parseVariables(variables)),
replyTo: replyTo !== '' ? replyTo : undefined,
fileUrls: variables.find(byId(options.attachmentsVariableId))?.value,
isCustomBody: options.isCustomBody,
isBodyCode: options.isBodyCode,
resultValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const sendEmailOptionsSchema = z.object({
replyTo: z.string().optional(),
cc: z.array(z.string()).optional(),
bcc: z.array(z.string()).optional(),
attachmentsVariableId: z.string().optional(),
})

export const sendEmailBlockSchema = blockBaseSchema.and(
Expand Down

5 comments on commit 7c3345a

@vercel
Copy link

@vercel vercel bot commented on 7c3345a Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

sat.cr8.ai
vhpage.cr8.ai
bt.id8rs.com
bot.aws.bj
ar.nigerias.io
aso.nigerias.io
apo.nigerias.io
apr.nigerias.io
am.nigerias.io
an.nigerias.io
sakuranembro.it
eventhub.com.au
chat.sureb4.com
games.klujo.com
bot.upfunnel.art
bot.piccinato.co
clo.closeer.work
faqs.nigerias.io
feedback.ofx.one
stan.vselise.com
app.chatforms.net
voicehelp.cr8.ai
goalsettingbot.com
gentleman-shop.fr
this-is-a-test.com
zap.techadviser.in
bot.eventhub.com.au
forms.webisharp.com
typebot.stillio.com
bot.ansuraniphone.my
chat.hayurihijab.com
bot.cotemeuplano.com
get.freebotoffer.xyz
bot.incusservices.com
abutton.wpwakanda.com
cdd.searchcube.com.sg
bot.meuesocial.com.br
sbutton.wpwakanda.com
chat.missarkansas.org
apply.ansuraniphone.my
c23111azqw.nigerias.io
felipewelington.com.br
form.searchcube.com.sg
gcase.barrettamario.it
kodawariab736.skeep.it
info.clickasuransi.com
view.onlinebotdemo.xyz
mainmenu.diddancing.com
83242573.actualizar.xyz
serviziaziendali.online
91181264.your-access.one
form.sergiolimajr.com.br
type.opaulovieira.com.br
boyfriend-breakup.riku.ai
aibot.angrybranding.co.uk
designguide.techyscouts.com
piazzatorre.barrettamario.it
type.dericsoncalari.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
hunterbot.saleshunter.ai
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
personal-trainer.barrettamario.it
viewer-v2-alpha-typebot-io.vercel.app
viewer-v2-alpha-git-main-typebot-io.vercel.app
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it

@vercel
Copy link

@vercel vercel bot commented on 7c3345a Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7c3345a Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7c3345a Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7c3345a Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.