Adding Emails/Messages #
Wrote this so I can maintain sanity next time I have to do it, but for anyone else who is adding a new email/message type to jfa-go, these notes might help.
For an example, we’re adding a new email to tell the user their dog ran away.
It roughly goes:
- In
lang/email/en-us.json
, add a section for your email (calleddogRanAway
), add variables for each line/section of the email. If you have the means to, feel free to add translations. - In
lang.go
: Add the section to theemailLang
struct (in CamelCase, i.e.DogRanAway
). - In
storage.go
: AddDogRanAway
to thecustomEmails
struct, and to thepatchLang
sections inloadLangEmail
. - In
mail/
, createdog-ran-away.txt
anddog-ran-away.mjml
, and define the structure of the email, using the variables you defined inlang/email/en-us.json
, or some custom variables you’ll pass in the next step. - In
email.go
: Define two functions:dogRanAwayValues, and
constructDogRanAway, following the function of the others in there. Make sure the variables you pass to the templater match what you put in
mail/`. Make sure to reference the paths provided by the settings you’ll add in the next step. - In
config/config-base.json
, define settings for the email subject, html and text email paths. (i.e.[dog_ran_away_section] -> subject/email_html/email_text
) - In
config.go
, find the bit where there’s lots ofemail_html
andemail_text
: Copy one of the pairs ofapp.MustSetValue
calls and change it to conform to the settings from the previous step, setting the default values to"jfa-go:"+"dog-ran-away.html/txt"
. - In
api-messages.go
:- In
GetCustomContent
, add a line to theemailListDTO
forDogRanAway
. - In
GetCustomMessageTemplate
, add a case forDogRanAway
to the big switch statement, calling the two functions you defined inemail.go
. PassdogRanAwayValues
some bogus values to be shown when the user edits the email.
- In
Then use constructDogRanAway
to create the email where needed.