Discover how to integrate and manage your notification system with our simple yet powerful messaging service.
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.
Message templates define how your notifications appear when delivered to destinations like Slack, email, or SMS. With MsgGO's templating system, you can:
Each delivery definition must have a message template assigned to it to determine what content will be sent when an event is received.
You can create message templates in two ways:
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.
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 }}
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 #}
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.
Different delivery targets have specific limitations that you should be aware of:
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.