[MM-35039] - Send trial ended email (#17478)
* [MM-35039] - Send trial ended email * Generations * Use First name with fallback to username * Use First name with fallback to username for trial ending email
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
246e4f9508
Коммит
fd546cdff2
@@ -952,6 +952,7 @@ type AppIface interface {
|
||||
SendAutoResponse(channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendAutoResponseIfNecessary(channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model.AppError
|
||||
SendCloudTrialEndedEmail() *model.AppError
|
||||
SendEmailVerification(user *model.User, newEmail, redirect string) *model.AppError
|
||||
SendEphemeralPost(userID string, post *model.Post) *model.Post
|
||||
SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error)
|
||||
|
||||
36
app/cloud.go
36
app/cloud.go
@@ -186,7 +186,11 @@ func (a *App) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model
|
||||
countNotOks := 0
|
||||
|
||||
for admin := range sysAdmins {
|
||||
err := a.Srv().EmailService.SendCloudTrialEndWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Username, trialEndDate, sysAdmins[admin].Locale, siteURL)
|
||||
name := sysAdmins[admin].FirstName
|
||||
if name == "" {
|
||||
name = sysAdmins[admin].Username
|
||||
}
|
||||
err := a.Srv().EmailService.SendCloudTrialEndWarningEmail(sysAdmins[admin].Email, name, trialEndDate, sysAdmins[admin].Locale, siteURL)
|
||||
if err != nil {
|
||||
a.Log().Error("Error sending trial ending warning to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err))
|
||||
countNotOks++
|
||||
@@ -200,3 +204,33 @@ func (a *App) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SendCloudTrialEndedEmail() *model.AppError {
|
||||
sysAdmins, e := a.getSysAdminsEmailRecipients()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
// we want to at least have one email sent out to an admin
|
||||
countNotOks := 0
|
||||
|
||||
for admin := range sysAdmins {
|
||||
name := sysAdmins[admin].FirstName
|
||||
if name == "" {
|
||||
name = sysAdmins[admin].Username
|
||||
}
|
||||
|
||||
err := a.Srv().EmailService.SendCloudTrialEndedEmail(sysAdmins[admin].Email, name, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
|
||||
if err != nil {
|
||||
a.Log().Error("Error sending trial ended email to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err))
|
||||
countNotOks++
|
||||
}
|
||||
}
|
||||
|
||||
// if not even one admin got an email, we consider that this operation errored
|
||||
if countNotOks == len(sysAdmins) {
|
||||
return model.NewAppError("app.SendCloudTrialEndedEmail", "app.user.send_emails.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
31
app/email.go
31
app/email.go
@@ -290,13 +290,13 @@ func (es *EmailService) sendWelcomeEmail(userID string, email string, verified b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, userName, trialEndDate, locale, siteURL string) *model.AppError {
|
||||
func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, name, trialEndDate, locale, siteURL string) *model.AppError {
|
||||
T := i18n.GetUserTranslations(locale)
|
||||
subject := T("api.templates.cloud_trial_ending_email.subject")
|
||||
|
||||
data := es.newEmailTemplateData(locale)
|
||||
data.Props["Title"] = T("api.templates.cloud_trial_ending_email.title")
|
||||
data.Props["SubTitle"] = T("api.templates.cloud_trial_ending_email.subtitle", map[string]interface{}{"Username": userName, "TrialEnd": trialEndDate})
|
||||
data.Props["SubTitle"] = T("api.templates.cloud_trial_ending_email.subtitle", map[string]interface{}{"Name": name, "TrialEnd": trialEndDate})
|
||||
data.Props["SiteURL"] = siteURL
|
||||
data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription", siteURL)
|
||||
data.Props["Button"] = T("api.templates.cloud_trial_ending_email.add_payment_method")
|
||||
@@ -314,6 +314,33 @@ func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, userName, trial
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *EmailService) SendCloudTrialEndedEmail(userEmail, name, locale, siteURL string) *model.AppError {
|
||||
T := i18n.GetUserTranslations(locale)
|
||||
subject := T("api.templates.cloud_trial_ended_email.subject")
|
||||
|
||||
t := time.Now()
|
||||
todayDate := fmt.Sprintf("%s %d, %d", t.Month(), t.Day(), t.Year())
|
||||
|
||||
data := es.newEmailTemplateData(locale)
|
||||
data.Props["Title"] = T("api.templates.cloud_trial_ended_email.title")
|
||||
data.Props["SubTitle"] = T("api.templates.cloud_trial_ended_email.subtitle", map[string]interface{}{"Name": name, "TodayDate": todayDate})
|
||||
data.Props["SiteURL"] = siteURL
|
||||
data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription", siteURL)
|
||||
data.Props["Button"] = T("api.templates.cloud_trial_ended_email.start_subscription")
|
||||
data.Props["QuestionTitle"] = T("api.templates.questions_footer.title")
|
||||
data.Props["QuestionInfo"] = T("api.templates.questions_footer.info")
|
||||
|
||||
body, err := es.srv.TemplatesContainer().RenderToString("cloud_trial_ended_email", data)
|
||||
if err != nil {
|
||||
return model.NewAppError("SendCloudTrialEndedEmail", "api.user.cloud_trial_ended_email.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := es.sendMail(userEmail, subject, body); err != nil {
|
||||
return model.NewAppError("SendCloudTrialEndedEmail", "api.user.cloud_trial_ended_email.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendCloudWelcomeEmail sends the cloud version of the welcome email
|
||||
func (es *EmailService) SendCloudWelcomeEmail(userEmail, locale, teamInviteID, workSpaceName, dns, siteURL string) *model.AppError {
|
||||
T := i18n.GetUserTranslations(locale)
|
||||
|
||||
@@ -14125,6 +14125,28 @@ func (a *OpenTracingAppLayer) SendCloudTrialEndWarningEmail(trialEndDate string,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SendCloudTrialEndedEmail() *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendCloudTrialEndedEmail")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SendCloudTrialEndedEmail()
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SendEmailVerification(user *model.User, newEmail string, redirect string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendEmailVerification")
|
||||
|
||||
Ссылка в новой задаче
Block a user