EmailBuilder.coffee 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. secondaryMessage: (opts) ->
  46. "If the button does not appear, open this link in your browser: #{opts.tokenLinkUrl}"
  47. })
  48. templates.accountMergeToSharelatexAddress = templates.accountMergeToOverleafAddress
  49. templates.registered = CTAEmailTemplate({
  50. subject: () -> "Activate your #{settings.appName} Account"
  51. message: (opts) -> """
  52. Congratulations, you've just had an account created for you on #{settings.appName} with the email address '#{opts.to}'.
  53. Click here to set your password and log in:
  54. """
  55. secondaryMessage: () -> "If you have any questions or problems, please contact #{settings.adminEmail}"
  56. ctaText: () -> "Set password"
  57. ctaURL: (opts) -> opts.setNewPasswordUrl
  58. })
  59. templates.canceledSubscription = CTAEmailTemplate({
  60. subject: () -> "#{settings.appName} thoughts"
  61. message: () -> """
  62. 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?
  63. """
  64. secondaryMessage: () -> "Thank you in advance!"
  65. ctaText: () -> "Leave Feedback"
  66. ctaURL: (opts) -> "https://docs.google.com/forms/d/e/1FAIpQLScqU6Je1r4Afz6ul6oY0RAfN7RabdWv_oL1u7Rj1YBmXS4fiQ/viewform?usp=sf_link"
  67. })
  68. templates.passwordResetRequested = CTAEmailTemplate({
  69. subject: () -> "Password Reset - #{settings.appName}"
  70. title: () -> "Password Reset"
  71. message: () -> "We got a request to reset your #{settings.appName} password."
  72. secondaryMessage: () -> """
  73. If you ignore this message, your password won't be changed.
  74. If you didn't request a password reset, let us know.
  75. """
  76. ctaText: () -> "Reset password"
  77. ctaURL: (opts) -> opts.setNewPasswordUrl
  78. })
  79. templates.confirmEmail = CTAEmailTemplate({
  80. subject: () -> "Confirm Email - #{settings.appName}"
  81. title: () -> "Confirm Email"
  82. message: () -> "Please confirm your email on #{settings.appName}."
  83. ctaText: () -> "Confirm Email"
  84. secondaryMessage: (opts) ->
  85. "If the button does not appear, open this link in your browser: #{opts.confirmEmailUrl}"
  86. ctaURL: (opts) -> opts.confirmEmailUrl
  87. })
  88. templates.projectInvite = CTAEmailTemplate({
  89. subject: (opts) -> "#{opts.project.name} - shared by #{opts.owner.email}"
  90. title: (opts) -> "#{ opts.project.name } - shared by #{ opts.owner.email }"
  91. message: (opts) -> "#{ opts.owner.email } wants to share '#{ opts.project.name }' with you."
  92. ctaText: () -> "View project"
  93. ctaURL: (opts) -> opts.inviteUrl
  94. gmailGoToAction: (opts) ->
  95. target: opts.inviteUrl
  96. name: "View project"
  97. description: "Join #{ opts.project.name } at #{ settings.appName }"
  98. })
  99. templates.verifyEmailToJoinTeam = CTAEmailTemplate({
  100. subject: (opts) -> "#{ opts.inviterName } has invited you to join a team on #{settings.appName}"
  101. title: (opts) -> "#{opts.inviterName} has invited you to join a team on #{settings.appName}"
  102. message: (opts) -> "Please click the button below to join the team and enjoy the benefits of an upgraded #{ settings.appName } account."
  103. ctaText: (opts) -> "Join now"
  104. ctaURL: (opts) -> opts.acceptInviteUrl
  105. })
  106. templates.testEmail = CTAEmailTemplate({
  107. subject: () -> "A Test Email from #{settings.appName}"
  108. title: () -> "A Test Email from #{settings.appName}"
  109. greeting: () -> "Hi,"
  110. message: () -> "This is a test Email from #{settings.appName}"
  111. ctaText: () -> "Open #{settings.appName}"
  112. ctaURL: () -> settings.siteUrl
  113. })
  114. module.exports =
  115. templates: templates
  116. CTAEmailTemplate: CTAEmailTemplate
  117. buildEmail: (templateName, opts)->
  118. template = templates[templateName]
  119. opts.siteUrl = settings.siteUrl
  120. opts.body = template.compiledTemplate(opts)
  121. if settings.email?.templates?.customFooter?
  122. opts.body += settings.email?.templates?.customFooter
  123. return {
  124. subject : template.subject(opts)
  125. html: template.layout(opts)
  126. text: template?.plainTextTemplate?(opts)
  127. }