Skip to content

Commit

Permalink
Separate out welcome templates
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Nov 19, 2024
1 parent ba9b335 commit e283827
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 68 deletions.
7 changes: 4 additions & 3 deletions admin/jobs/river/subscription_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ func (w *SubscriptionCancellationCheckWorker) subscriptionCancellationCheck(ctx
}

err = w.admin.Email.SendSubscriptionEnded(&email.SubscriptionEnded{
ToEmail: org.BillingEmail,
ToName: org.Name,
OrgName: org.Name,
ToEmail: org.BillingEmail,
ToName: org.Name,
OrgName: org.Name,
BillingURL: w.admin.URLs.Billing(org.Name, false),
})
if err != nil {
w.logger.Error("failed to send subscription ended email", zap.String("org_id", org.ID), zap.String("org_name", org.Name), zap.String("billing_email", org.BillingEmail), zap.Error(err))
Expand Down
11 changes: 6 additions & 5 deletions admin/server/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,12 @@ func (s *Server) CancelBillingSubscription(ctx context.Context, req *adminv1.Can
s.logger.Named("billing").Warn("subscription cancelled", zap.String("org_id", org.ID), zap.String("org_name", org.Name))

err = s.admin.Email.SendSubscriptionCancelled(&email.SubscriptionCancelled{
ToEmail: org.BillingEmail,
ToName: org.Name,
OrgName: org.Name,
PlanName: sub.Plan.DisplayName,
EndDate: endDate,
ToEmail: org.BillingEmail,
ToName: org.Name,
OrgName: org.Name,
PlanName: sub.Plan.DisplayName,
EndDate: endDate,
BillingURL: s.admin.URLs.Billing(org.Name, false),
})
if err != nil {
s.logger.Named("billing").Error("failed to send subscription cancelled email", zap.String("org_name", org.Name), zap.String("org_id", org.ID), zap.String("billing_email", org.BillingEmail), zap.Error(err))
Expand Down
104 changes: 67 additions & 37 deletions runtime/pkg/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,26 @@ func (c *Client) SendInformational(opts *Informational) error {
}

type Welcome struct {
ToEmail string
ToName string
Subject string
FrontendURL string
WelcomeText template.HTML
IsNew bool
IsFromDeploy bool
ToEmail string
ToName string
Subject string
FrontendURL string
WelcomeText template.HTML
}

func (c *Client) SendWelcomeToTrial(opts *Welcome) error {
buf := new(bytes.Buffer)
err := c.templates.Lookup("welcome_to_trial.html").Execute(buf, opts)
if err != nil {
return fmt.Errorf("email template error: %w", err)
}
html := buf.String()
return c.Sender.Send(opts.ToEmail, opts.ToName, opts.Subject, html)
}

func (c *Client) SendWelcome(opts *Welcome) error {
func (c *Client) SendWelcomeToTeam(opts *Welcome) error {
buf := new(bytes.Buffer)
err := c.templates.Lookup("welcome.html").Execute(buf, opts)
err := c.templates.Lookup("welcome_to_team.html").Execute(buf, opts)
if err != nil {
return fmt.Errorf("email template error: %w", err)
}
Expand Down Expand Up @@ -390,10 +398,10 @@ func (c *Client) SendInvoicePaymentFailed(opts *InvoicePaymentFailed) error {
return c.SendCallToAction(&CallToAction{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("Payment failed. Please update your payment method"),
Subject: fmt.Sprintf("Payment failed for %s. Please update your payment method", opts.OrgName),
PreButton: template.HTML(fmt.Sprintf(`
We couldn’t process your payment for %s. You have until %s to update your payment details before your account is <a href="https://docs.rilldata.com/home/FAQ#what-is-project-hibernation">hibernating</a>.
`, opts.ToName, opts.GracePeriodEndDate.Format(dateFormat))),
We couldn’t process your payment for %s. You have until %s to update your payment details before your org is <a href="https://docs.rilldata.com/home/FAQ#what-is-project-hibernation">hibernating</a>.
`, opts.OrgName, opts.GracePeriodEndDate.Format(dateFormat))),
ButtonText: "Update Payment Info",
ButtonLink: opts.PaymentURL,
})
Expand All @@ -413,7 +421,7 @@ func (c *Client) SendInvoicePaymentSuccess(opts *InvoicePaymentSuccess) error {
return c.SendInformational(&Informational{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("Successful payment %s", opts.PaymentDate.Format("January 2, 2006 15:04:05 MST")),
Subject: fmt.Sprintf("Successful payment %s", opts.PaymentDate.Format(dateFormat)),
Body: template.HTML(fmt.Sprintf(`
Thank you for your payment!
<br /><br />
Expand All @@ -438,7 +446,7 @@ func (c *Client) SendInvoiceUnpaid(opts *InvoiceUnpaid) error {
return c.SendCallToAction(&CallToAction{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("%s is now hibernated", opts.OrgName),
Subject: fmt.Sprintf("Invoice for %s is now past due. Org is now hibernated", opts.OrgName),
PreButton: template.HTML(fmt.Sprintf(`
%s and its projects have been hibernated due to an overdue payment.
<br /><br />
Expand All @@ -450,40 +458,58 @@ Restore access by updating your payment information today!
}

type SubscriptionCancelled struct {
ToEmail string
ToName string
OrgName string
PlanName string
EndDate time.Time
ToEmail string
ToName string
OrgName string
PlanName string
BillingURL string
EndDate time.Time
}

func (c *Client) SendSubscriptionCancelled(opts *SubscriptionCancelled) error {
return c.SendInformational(&Informational{
return c.SendCallToAction(&CallToAction{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("%s for %s is canceled", opts.PlanName, opts.OrgName),
Body: template.HTML(fmt.Sprintf(`
You’ve successfully canceled the %s for %s. Your access will continue until %s. If you change your mind, you can always reactivate your subscription!
Subject: fmt.Sprintf("%s for %s is canceled. Access available until %s", opts.PlanName, opts.OrgName, opts.EndDate.Format(dateFormat)),
PreButton: template.HTML(fmt.Sprintf(`
We’re sorry to see you go!
<br /><br />
You’ve successfully canceled the %s for %s. You’ll still have access to Rill Cloud until %s. After this date, your subscription will expire, and you will no longer have access.
<br /><br />
If you change your mind, you can always reactivate your subscription!
<br /><br />
If you found that our service did not meet your needs, please reply to this email and we’ll do our best to address your feedback and concerns.
`, opts.PlanName, opts.ToName, opts.EndDate.Format(dateFormat))),
ButtonText: "Billing Settings",
ButtonLink: opts.BillingURL,
PostButton: template.HTML(fmt.Sprintf("If you found that our service did not meet your needs, please reply to this email and we’ll do our best to address your feedback and concerns.")),

Check failure on line 485 in runtime/pkg/email/email.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
})
}

type SubscriptionEnded struct {
ToEmail string
ToName string
OrgName string
ToEmail string
ToName string
OrgName string
BillingURL string
}

func (c *Client) SendSubscriptionEnded(opts *SubscriptionEnded) error {
return c.SendInformational(&Informational{
return c.SendCallToAction(&CallToAction{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("%s is now hibernated", opts.OrgName),
Body: template.HTML(fmt.Sprintf(`
%s and its projects are now <a href="https://docs.rilldata.com/home/FAQ#what-is-project-hibernation">hibernating</a>.
Subject: fmt.Sprintf("Subscription for %s has now ended. Org is hibernated", opts.OrgName),
PreButton: template.HTML(fmt.Sprintf(`
Your cancelled subscription for %s has and its projects are now <a href="https://docs.rilldata.com/home/FAQ#what-is-project-hibernation">hibernating</a>. We hope you enjoyed using Rill Cloud during your time with us.
<br /><br />
If you’d like to reactive your subscription and regain access, you can easily do so at any time by renewing your subscription from here:
`, opts.OrgName)),
ButtonText: "Billing Settings",
ButtonLink: opts.BillingURL,
PostButton: template.HTML(fmt.Sprintf(`

Check failure on line 508 in runtime/pkg/email/email.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
We’d also love to hear from you! If you have any feedback about your experience or how we can improve, please share it with us by replying to this email.
<br /><br />
Thank you for trying Rill Cloud. We hope to see you again in the future!
`)),
})
}

Expand All @@ -496,17 +522,16 @@ type TrialStarted struct {
}

func (c *Client) SendTrialStarted(opts *TrialStarted) error {
return c.SendWelcome(&Welcome{
return c.SendWelcomeToTrial(&Welcome{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("A 30-day free trial for for %s has started", opts.OrgName),
Subject: fmt.Sprintf("A 30-day free trial for %s has started", opts.OrgName),
FrontendURL: opts.FrontendURL,
WelcomeText: template.HTML(fmt.Sprintf(`
Hi %s,
<br /><br />
You now have access to Rill Cloud until %s to explore all features. Let us know if you need any help along the way!
`, opts.ToName, opts.TrialEndDate.Format(dateFormat))),
IsNew: true,
})
}

Expand Down Expand Up @@ -574,14 +599,19 @@ func (c *Client) SendTrialGracePeriodEnded(opts *TrialGracePeriodEnded) error {
return c.SendCallToAction(&CallToAction{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("%s is now hibernated", opts.OrgName),
Subject: fmt.Sprintf("Trial plan grace period for %s has ended. Org is now hibernated", opts.OrgName),
PreButton: template.HTML(fmt.Sprintf(`
%s and its projects are now <a href="https://docs.rilldata.com/home/FAQ#what-is-project-hibernation">hibernating</a>.
<br /><br />
Reactivate your account by upgrading to the Team Plan today!
Reactivate your org by upgrading to the Team Plan today!
`, opts.OrgName)),
ButtonText: "Upgrade to Team Plan",
ButtonLink: opts.UpgradeURL,
PostButton: template.HTML(fmt.Sprintf(`
We’d also love to hear from you! If you have any feedback about your experience or how we can improve, please share it with us by replying to this email.
<br /><br />
Thank you for trying Rill Cloud. We hope to see you again in the future!
`)),
})
}

Expand Down Expand Up @@ -644,7 +674,7 @@ type TeamPlan struct {

// SendTeamPlanStarted sends customised plan started email for Team Plan
func (c *Client) SendTeamPlanStarted(opts *TeamPlan) error {
return c.SendWelcome(&Welcome{
return c.SendWelcomeToTeam(&Welcome{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("Welcome to the %s", opts.PlanName),
Expand All @@ -659,7 +689,7 @@ Your next billing cycle starts on %s.

// SendTeamPlanRenewal sends customised plan renewed email for Team Plan
func (c *Client) SendTeamPlanRenewal(opts *TeamPlan) error {
return c.SendWelcome(&Welcome{
return c.SendWelcomeToTeam(&Welcome{
ToEmail: opts.ToEmail,
ToName: opts.ToName,
Subject: fmt.Sprintf("Your %s subscription for %s has been renewed", opts.PlanName, opts.OrgName),
Expand Down
Loading

0 comments on commit e283827

Please sign in to comment.