-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
}, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 ?? '', | ||
}); | ||
|
||
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters