Logo

Docs / MsgGO

Discover how to integrate and manage your notification system with our simple yet powerful messaging service.

Docs

Message Templates

Message templates in MsgGO allow you to customize the content and format of notifications sent to various delivery targets when an event is received. Using templates, you can create dynamic messages that include data from the received event, making your notifications more informative and contextually relevant.

Understanding Message Templates

Message templates define how your notifications appear when delivered to destinations like Slack, email, or SMS. With MsgGO's templating system, you can:

  • Create multiple templates for a single event definition
  • Define different templates for different delivery targets
  • Include dynamic content using event data variables
  • Create conditional content using Twig templating language

Each delivery definition must have a message template assigned to it to determine what content will be sent when an event is received.

Creating Message Templates

You can create message templates in two ways:

Method 1: From the Events List

  1. Navigate to the Events section in the left sidebar
  2. Find the event you want to create a template for
  3. Click the Add delivery button next to the event
  4. In the modal dialog, select a delivery target
  5. Fill in all required fields for your selected delivery target (e.g., for Slack, select workspace and channel first)
  6. After filling required fields, the Message template option will appear
  7. Choose New message template from the dropdown
  8. Enter a name for your template and create your message content
  9. Click Save to create both the delivery target and the template

Method 2: From Event Editing

  1. Navigate to the event definition you want to create templates for
  2. Scroll down to the "Message templates" section
  3. Click the New button to create a new template
  4. Enter a name for your template
  5. Select which delivery target this template applies to
  6. Create your message content
  7. Click Save to store your template

Using Twig in Templates

MsgGO now uses Twig as its templating language. Twig is a flexible, secure, and feature-rich template engine that provides powerful features for creating dynamic content.

Basic Twig Syntax

Variables: Access data with double curly braces:

{{ event.name }}
{% if data.status == 'success' %}
  Success!
{% else %}
  Failure!
{% endif %}
{% for item in data.items %}
  - {{ item.name }}
{% endfor %}
{% set greeting = 'Hello' %}
{% set name = data.user.firstname %}
{{ greeting }}, {{ name }}!
{{ data.message|upper }}

Available Variables

When creating message templates, you can use the following variables to insert dynamic content:

Variable Description
event.name Event name
event.receivedAt Date of receiving the event (format: YYYY/MM/DD HH:MM:SS)
data Object containing all data delivered with the event. To see all data in serialized form, use the json_encode filter: {{ data | json_encode }}
data.keyName Access to a specific key in the data

To insert these variables into your template, place them between double curly braces as per Twig syntax. For example:

New event received: {{ event.name }}
Time: {{ event.receivedAt }}
Status: {{ data.status }}

Filters allow you to modify variables and expressions. They are separated from the variable by a pipe symbol (|). Multiple filters can be chained, with the output of one filter applied to the next.

Basic Filter Syntax:

{{ name|title }}
{{ list|json_ncode(', ') }}
{{ (1..5)|json_encode }}
{{ ('HELLO' ~ 'WORLD')|lower }}

MsgGO provides several useful filters that you can use to format your message content. Here's a complete list with examples:

{{ "hello world"|capitalize }}
{# Output: Hello World #}

Delivery Target-Specific Formatting

Each delivery target in MsgGO has its own formatting capabilities and limitations. The message editor will automatically adapt based on the delivery target you select.

Slack

  • Uses Slack Markdown for formatting
  • Supports bold, italic, code blocks, and other Slack-specific formatting
  • For more details on Slack formatting, see Slack's formatting documentation

Email

  • Uses standard Markdown for formatting
  • Supports headings, lists, links, and other common markdown features
  • Maximum message length: 40,000 characters
  • For more details on Email formatting, see Markdown Guide

SMS

  • Uses plain text only (no formatting)
  • Does not support diacritical marks, emoji, or UTF-8 special characters
  • Any special characters will be automatically converted to ASCII equivalents or removed
  • Maximum message length varies by region, generally limited to 160 characters

URL (Webhook)

Delivery Target Limitations

Different delivery targets have specific limitations that you should be aware of:

  • SMS: Cannot contain diacritical marks, emoji, or UTF-8 characters. These will be automatically converted to ASCII equivalents or removed. Limited to 160 characters per message.
  • Email: Maximum content length of 40,000 characters. HTML elements may be stripped depending on the receiving email client.
  • Slack: Maximum of 4,000 characters per message. Some advanced formatting may not display correctly in all Slack clients.

Best Practices for Message Templates

  • Keep templates concise: Focus on the most important information, especially for SMS and chat platforms
  • Use variables effectively: You don't need to worry about missing data - if a variable doesn't exist, it simply won't be rendered
  • Test your templates: Send test events to verify your templates work as expected
  • Consider the context: Design templates with the delivery channel in mind
  • Use descriptive names: Give your templates clear names that indicate their purpose

By effectively using message templates in MsgGO, you can ensure that the right information reaches the right people in the most appropriate format for each communication channel.