Skip to content

Commit

Permalink
added goodbye email
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Nov 2, 2024
1 parent da776fb commit 70bd8b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/altair-api/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const config = {
resendApiKey: process.env.RESEND_API_KEY,
audienceId: process.env.RESEND_AUDIENCE_ID,
defaultFrom: 'Altair GraphQL <[email protected]>',
replyTo: 'reply@mail.altairgraphql.dev',
replyTo: 'info@altairgraphql.dev',
},
};

Expand Down
41 changes: 39 additions & 2 deletions packages/altair-api/src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Resend } from 'resend';
import { renderWelcomeEmail } from '@altairgraphql/emails';
import { UserService } from 'src/auth/user/user.service';
import { Config } from 'src/common/config';
import { User } from '@altairgraphql/db';

@Injectable()
export class EmailService {
Expand Down Expand Up @@ -32,7 +33,7 @@ export class EmailService {
const { data, error } = await this.resend.contacts.create({
email: user.email,
audienceId,
firstName: user.firstName ?? user.email,
firstName: this.getFirstName(user),
lastName: user.lastName ?? '',
});

Expand All @@ -58,12 +59,48 @@ export class EmailService {
to: user.email,
replyTo: this.configService.get('email.replyTo', { infer: true }),
subject: 'Welcome to Altair GraphQL Cloud',
html: await renderWelcomeEmail({ username: user.firstName ?? user.email }),
html: await renderWelcomeEmail({ username: this.getFirstName(user) }),
});
if (error) {
console.error('Error sending welcome email', error);
}

return { data, error };
}

async sendGoodbyeEmail(userId: string) {
const user = await this.userService.mustGetUser(userId);
const { data, error } = await this.resend.emails.send({
from:
this.configService.get('email.defaultFrom', { infer: true }) ??
'[email protected]',
to: user.email,
replyTo: this.configService.get('email.replyTo', { infer: true }),
subject: 'Sorry to see you go 👋🏾',
html: `Hey ${this.getFirstName(user)},
<br><br>
Samuel here. I noticed you've cancelled your Altair GraphQL pro subscription and wanted to check in.
<br><br>
Would you mind sharing what led to your decision? Your feedback helps us make Altair better for everyone. Just hit reply to let me know.
<br><br>
If you ever want to come back, we'll be here! And of course, you can keep using Altair's free version as long as you like.
<br><br>
Thanks for giving the pro version a try!
<br><br>
Best wishes,
<br>
Samuel
<br><br>
P.S. If you cancelled because of a technical issue or need help with something, just let me know -- I'm happy to help!`,
});
if (error) {
console.error('Error sending goodbye email', error);
}

return { data, error };
}

private getFirstName(user: User) {
return user.firstName ?? user.email;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export class StripeWebhookController {

if (planRole === BASIC_PLAN_ID) {
await this.userService.toBasicPlan(user.id);
if (shouldCancelPlan) {
// Send goodbye email
console.log('Sending goodbye email');
await this.emailService.sendGoodbyeEmail(user.id);
}
} else if (planRole === PRO_PLAN_ID) {
await this.userService.toProPlan(user.id, quantity);
// Send welcome email
Expand Down

0 comments on commit 70bd8b2

Please sign in to comment.