Skip to content

georgeherby/hmrc-email-renderer

 
 

Repository files navigation

hmrc-email-renderer


Build Status Download

Manages the rendering of parameterised email using templates.

Note: Before sending a pull request with template changes, please look at our guidelines.

API

Path Supported Methods Description
/templates/:templateId POST Renders the email template for the given template Id More...

POST /templates/:templateId

Renders the email template for the given template Id and returns the rendered template details.

Example request body - parameters with String type key and values.

{
  "parameters": {
    "param1" : "Parameter to be used in the email template"
    "param2" : "Parameter to be used in the email template"
  }
}

Responds with status:

  • 200 When the template is rendered successfully
{
   "plain": "Rendered template in text format",
   "html": "Rendered template in HTML format",
   "fromAddress": "From address to be used for this email when sending",
   "subject": "Email subject to use", 
   "service": "The regime (i.e. - sa/paye/etc) that this template belongs to"
}
  • 404 When the template with the provided template Id cannot be resolved.

  • 400 When an insufficient set of parameters for rendering the template is specified in the request. Only the first missing value is reported.

{
   "status": "Rendering of template failed",
   "reason": "key not found: param10"
}

Preview Mode

Templates can be fiddly to get right as they can ordinarily only be viewed by actually generating an email and sending it. To work around this you can preview templates during development by running the micro-service from sbt:

cd $WORKSPACE/hmrc-email-renderer
sbt -Dhttp.port=8950 -Dapplication.router=testOnlyDoNotUseInAppConf.Routes run

You should be able to list all the templates available for preview from http://localhost:8950/hmrc-email-renderer/test-only/preview.

Note that to render logos correctly the assets frontend also needs to be started using

sm --start ASSETS_FRONTEND -f

Quick Preview

Alternatively, you can do a preview of emails by starting the service using sm to preview the source, snapshot or release versions of the micro-service.

sm --start ASSETS_FRONTEND -f
sm --start HMRC_EMAIL_RENDERER [-f|-r]

Again, list the templates can then be previewed from

http://localhost:8950/hmrc-email-renderer/test-only/preview

Handling Templates based on Language preference

If we want to make a template to work based on preference.

We have to add this to configuration in following place

https://github.com/hmrc/app-config-base/blob/master/hmrc-email-renderer.conf

key should be an english tempalteId and value should be welsh templateId

We make a call to preferences service to see weather language is set to English or Welsh, if Welsh we return welsh template otherwise english.

License

This code is open source software licensed under the Apache 2.0 License Test test

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 61.0%
  • Scala 39.0%