Skip to content

[DF-500] Implement a mailchimp provider #1130

@maxgurewitz

Description

@maxgurewitz

Implement support for Mailchimp and mandrill as an email service provider.

Add a new PersistedEmailProvider type:

export const PersistedEmailProvider = Type.Union([
SendgridEmailProvider,
AmazonSesEmailProvider,
PostMarkEmailProvider,
ResendEmailProvider,
SmtpEmailProvider,
TestEmailProvider,
]);

Add new EmailServiceProviderSuccess type:

export const EmailServiceProviderSuccess = Type.Union([
EmailSendgridSuccess,
EmailAmazonSesSuccess,
EmailPostMarkSuccess,
EmailResendSuccess,
EmailSmtpSuccess,
EmailTestSuccess,
]);

Add new EmailServiceProviderFailure type:

export const EmailServiceProviderFailure = Type.Union([
MessageSendgridServiceFailure,
MessageAmazonSesServiceFailure,
MessageResendFailure,
MessagePostMarkFailure,
MessageSmtpFailure,
]);

Add new EmailProviderSecret type:

export const EmailProviderSecret = Type.Union([
SendgridSecret,
PostMarkSecret,
AmazonSesSecret,
SmtpSecret,
ResendSecret,
TestEmailSecret,
]);

Error handling for the /templates/test api endpoint:

switch (type) {
case EmailProviderType.Sendgrid: {
const { body, status } = result.error.variant.provider;
const suggestions: string[] = [];
if (status) {
suggestions.push(`Sendgrid responded with status: ${status}`);
if (status === 403) {
suggestions.push(
"Is the configured email domain authorized in sengrid?",
);
}
}
return reply.status(200).send({
type: JsonResultType.Err,
err: {
suggestions,
responseData: body,
},
});
}

A webhook for updating the status of sent emails:

fastify.withTypeProvider<TypeBoxTypeProvider>().post(
"/sendgrid",
{
schema: {
description: "Used to consume sendgrid webhook payloads.",
tags: ["Webhooks"],
headers: Type.Object({
"x-twilio-email-event-webhook-signature": Type.String(),
"x-twilio-email-event-webhook-timestamp": Type.String(),
}),
body: Type.Array(SendgridEvent),
},
},

Handle the email provider type when sending messages:

case EmailProviderType.Sendgrid: {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (secretConfig.type !== EmailProviderType.Sendgrid) {
return err({
type: InternalEventType.BadWorkspaceConfiguration,
variant: {
type: BadWorkspaceConfigurationType.MessageServiceProviderMisconfigured,
message: `expected sendgrid secret config but got ${secretConfig.type}`,
},
});
}

Create the email provider:

const val = emailProviders.flatMap((ep) => {
let type: EmailProviderType;
switch (ep.type) {
case EmailProviderType.Test:
type = EmailProviderType.Test;
break;
case EmailProviderType.Sendgrid:
type = EmailProviderType.Sendgrid;
break;
case EmailProviderType.AmazonSes:

Add Place in Settings to configure email provider:

function EmailChannelConfig() {
return (
<>
<SectionSubHeader id={settingsSectionIds.emailChannel} title="Email" />
<DefaultEmailConfig />
<SendGridConfig />
<AmazonSesConfig />
<ResendConfig />
<PostMarkConfig />
<SmtpConfig />
</>
);
}

See this previous issue as a reference: #641

From SyncLinear.com | DF-500

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions