April 20, 2018
Dyspatch helps you take email templates out of your code base, allowing content creators to build complex email templates free from the deployment process. When it comes time to send an email, how does Dyspatch fit in? This guide outlines how to integrate Dyspatch into your system, and the steps to make Dyspatch a part of your email sending pipeline.
Template Life Cycle
Create, collaborate, and approve email content in Dyspatch. The Dyspatch API exposes approved compiled templates, with their snippets and styling already inlined. A Digital Messaging Service built in your system will store and build emails from the compiled templates taken from the Dyspatch API. How your Digital Messaging Service functions can vary depending on your organization's goals, but there are two main processes we'll outline below to get you started.
Digital Messaging Service
In order to effectively send emails with the most current content from your Dyspatch account, two functions will need to be performed by your Digital Messaging Service: Template Sync and Template Render. Template Sync to update your stored templates with any new content in Dyspatch, and Template Render to build a customer email from a template.
A sync of your templates on Dyspatch should be performed on a regular schedule (once per minute maximum) to update your datastore with any newly published content.
Template Sync Steps
1. Fetch List of Templates
Use the Dyspatch List Templates API get a list of your templates.
You'll receive a paginated response with all of your templates and their details. See List Templates to view details of the response.
2. Compare updatedAt Date-time
Compare the updatedAt fields to find newly published or updated templates.
The first time you pull your templates and set up your datastore, you'll need to pull all your organization's templates. Once your templates have been cached, you can target the templates that are new or have been updated. This can be done by comparing the updatedAt fields on the templates in your datastore with the corresponding templates from the List Templates response.
3. Fetch Updated Content
We recommend your datastore caches the full API response.
4. Update Your Datastore
Update your template datastore with the new and updated templates.
Your datastore should now be synced up with Dyspatch and the new and updated templates are available for use in the next step: Template Render.
When it comes time to send an email, pull a compiled template from your datastore, insert the necessary data, and render the template to build an email.
Template Render Steps
1. Send Request Initiated
A send request is made by your system to your Digital Messaging Service.
The send request from your system should request a template by ID and will need to provide a recipient address and any necessary customer data to customize the email for the recipient.
2. Fetch Template
Fetch the requested template using its template ID and, if needed, its locale from your template datastore.
3. Prepare Data
Prepare the template for render by inserting the recipient information.
Recipient, sender, and localization data must be injected before rendering.
4. Use Jinja to Render
Use the Jinja library to render the HTML, text, and metadata for the final email.
Read more about Jinja in the Jinja Documentation available here.
5. Return for Sending
The template is customized and rendered for the end user and is ready to be returned for sending.
Ready to Send
With Template Sync and Template Render implemented your Digital Messaging Service will be able to serve the most up-to-date templates from your Dyspatch account and render customized emails ready to be passed on to your Email Service Provider for sending.