EmailBuilder.coffee 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. _ = require('underscore')
  2. settings = require("settings-sharelatex")
  3. marked = require('marked')
  4. PersonalEmailLayout = require("./Layouts/PersonalEmailLayout")
  5. NotificationEmailLayout = require("./Layouts/NotificationEmailLayout")
  6. BaseWithHeaderEmailLayout = require("./Layouts/" + settings.brandPrefix + "BaseWithHeaderEmailLayout")
  7. SingleCTAEmailBody = require("./Bodies/" + settings.brandPrefix + "SingleCTAEmailBody")
  8. CTAEmailTemplate = (content) ->
  9. content.greeting ?= () -> 'Hi,'
  10. content.secondaryMessage ?= () -> ""
  11. return {
  12. subject: (opts) -> content.subject(opts),
  13. layout: BaseWithHeaderEmailLayout,
  14. plainTextTemplate: (opts) -> """
  15. #{content.greeting(opts)}
  16. #{content.message(opts).trim()}
  17. #{content.ctaText(opts)}: #{content.ctaURL(opts)}
  18. #{content.secondaryMessage?(opts).trim() or ""}
  19. Regards,
  20. The #{settings.appName} Team - #{settings.siteUrl}
  21. """
  22. compiledTemplate: (opts) ->
  23. SingleCTAEmailBody({
  24. title: content.title?(opts)
  25. greeting: content.greeting(opts)
  26. message: marked(content.message(opts).trim())
  27. secondaryMessage: marked(content.secondaryMessage(opts).trim())
  28. ctaText: content.ctaText(opts)
  29. ctaURL: content.ctaURL(opts)
  30. gmailGoToAction: content.gmailGoToAction?(opts)
  31. })
  32. }
  33. templates = {}
  34. templates.accountMergeToOverleafAddress = CTAEmailTemplate({
  35. subject: () -> "Confirm Account Merge - #{settings.appName}"
  36. title: () -> "Confirm Account Merge"
  37. message: () ->
  38. """
  39. To merge your ShareLaTeX and Overleaf accounts, click the button below.
  40. If you think you have received this message in error,
  41. please contact us at https://www.overleaf.com/contact
  42. """
  43. ctaText: () -> "Confirm Account Merge"
  44. ctaURL: (opts) -> opts.tokenLinkUrl
  45. })
  46. templates.accountMergeToSharelatexAddress = templates.accountMergeToOverleafAddress
  47. templates.registered = CTAEmailTemplate({
  48. subject: () -> "Activate your #{settings.appName} Account"
  49. message: (opts) -> """
  50. Congratulations, you've just had an account created for you on #{settings.appName} with the email address '#{opts.to}'.
  51. Click here to set your password and log in:
  52. """
  53. secondaryMessage: () -> "If you have any questions or problems, please contact #{settings.adminEmail}"
  54. ctaText: () -> "Set password"
  55. ctaURL: (opts) -> opts.setNewPasswordUrl
  56. })
  57. templates.canceledSubscription = CTAEmailTemplate({
  58. subject: () -> "#{settings.appName} thoughts"
  59. message: () -> """
  60. I'm sorry to see you cancelled your #{settings.appName} premium account. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?
  61. """
  62. secondaryMessage: () -> "Thank you in advance!"
  63. ctaText: () -> "Leave Feedback"
  64. ctaURL: (opts) -> "https://docs.google.com/forms/d/e/1FAIpQLScqU6Je1r4Afz6ul6oY0RAfN7RabdWv_oL1u7Rj1YBmXS4fiQ/viewform?usp=sf_link"
  65. })
  66. templates.passwordResetRequested = CTAEmailTemplate({
  67. subject: () -> "Password Reset - #{settings.appName}"
  68. title: () -> "Password Reset"
  69. message: () -> "We got a request to reset your #{settings.appName} password."
  70. secondaryMessage: () -> """
  71. If you ignore this message, your password won't be changed.
  72. If you didn't request a password reset, let us know.
  73. """
  74. ctaText: () -> "Reset password"
  75. ctaURL: (opts) -> opts.setNewPasswordUrl
  76. })
  77. templates.confirmEmail = CTAEmailTemplate({
  78. subject: () -> "Confirm Email - #{settings.appName}"
  79. title: () -> "Confirm Email"
  80. message: () -> "Please confirm your email on #{settings.appName}."
  81. ctaText: () -> "Confirm Email"
  82. ctaURL: (opts) -> opts.confirmEmailUrl
  83. })
  84. templates.projectInvite = CTAEmailTemplate({
  85. subject: (opts) -> "#{opts.project.name} - shared by #{opts.owner.email}"
  86. title: (opts) -> "#{ opts.project.name } - shared by #{ opts.owner.email }"
  87. message: (opts) -> "#{ opts.owner.email } wants to share '#{ opts.project.name }' with you."
  88. ctaText: () -> "View project"
  89. ctaURL: (opts) -> opts.inviteUrl
  90. gmailGoToAction: (opts) ->
  91. target: opts.inviteUrl
  92. name: "View project"
  93. description: "Join #{ opts.project.name } at #{ settings.appName }"
  94. })
  95. templates.verifyEmailToJoinTeam = CTAEmailTemplate({
  96. subject: (opts) -> "#{ opts.inviterName } has invited you to join a team on #{settings.appName}"
  97. title: (opts) -> "#{opts.inviterName} has invited you to join a team on #{settings.appName}"
  98. message: (opts) -> "Please click the button below to join the team and enjoy the benefits of an upgraded #{ settings.appName } account."
  99. ctaText: (opts) -> "Join now"
  100. ctaURL: (opts) -> opts.acceptInviteUrl
  101. })
  102. templates.testEmail = CTAEmailTemplate({
  103. subject: () -> "A Test Email from #{settings.appName}"
  104. title: () -> "A Test Email from #{settings.appName}"
  105. greeting: () -> "Hi,"
  106. message: () -> "This is a test Email from #{settings.appName}"
  107. ctaText: () -> "Open #{settings.appName}"
  108. ctaURL: () -> settings.siteUrl
  109. })
  110. module.exports =
  111. templates: templates
  112. CTAEmailTemplate: CTAEmailTemplate
  113. buildEmail: (templateName, opts)->
  114. template = templates[templateName]
  115. opts.siteUrl = settings.siteUrl
  116. opts.body = template.compiledTemplate(opts)
  117. if settings.email?.templates?.customFooter?
  118. opts.body += settings.email?.templates?.customFooter
  119. return {
  120. subject : template.subject(opts)
  121. html: template.layout(opts)
  122. text: template?.plainTextTemplate?(opts)
  123. }