Creating an Event Notifications template

An IBM Cloud Event Notifications template defines the layout and content of notifications (email, webhook, Slack, and more). Templates can include images, static text, and dynamic content (variables, conditional logic) based on events.

Event Notifications supports two types of templates:

  1. User-defined templates: You can design your own templates to structure notification messages.

  2. Pre-defined templates: These are standard templates defined for a pair of specific source and destination. You can customize pre-defined templates to create a user defined template.

Creating a user-defined template

  1. In the IBM Cloud console, click the menu icon hamburger icon > Platform Automation > Event notifications.

  2. Click the name of your Event Notifications instance.

  3. Select Templates from the left panel and click Create.

  4. Enter details about the template such as the name and description, and select a template type. Event Notifications currently supports the following user-defined templates:

  5. Click Add to save your updates.

Handlebars integration

Handlebars is a templating language that allows for dynamic content generation within templates. You can use Handlebars to customize notification messages by using template variables, conditional logic, and various other helpers.

Template variables

Template variables are placeholders within the notification message templates that get replaced with actual data when a notification is triggered. These variables allow you to personalize messages and include relevant information from the event being notified.

Usage

{{variable_name}}

Example:

Event Name: {{event_name}}

Conditional logic helper

Conditional logic allows you to define conditions within the message templates, enabling dynamic content generation based on the values of variables. This feature is useful for creating flexible notification messages that adapt to different scenarios.

Usage

{{#if condition}}
   
{{else}}
   
{{/if}}

Example:

{{#if severity}}
   Severity: {{severity}}
{{else}}
   No severity information available
{{/if}}

Contains helper

The contains helper allows you to check whether there is a specific word in any of the fields of the payload.

Example

"data":
{
	"message": "this is test alert from dev account"
}

Use the contains helpers like:

{
{{#contains data.message "dev"}}
"environment": "development"
{{/contains}}
}

For a full list of available helpers, see the raymond built-in helpers reference.

Examples

Payload:

"data":
{
	"message": "this is test alert from dev account",
	"secrets": [
	{
		"event_time": "2025-01-24T00:45:01Z",
		"event_triggered_by": "SecretsManager",
		"secret_expiration": "2025-04-24T00:45:01Z"
	}
],
}

Using conditional logic helpers with contains helpers

{{#if (contains data.message "dev")}}
"color":"#1E90FF"
{{else if (contains ibmendefaultlong "prod")}}
"color":"#dc143c"
{{else}}
"color":"#097969"
{{/if}}

For loop to print each key value from an array of maps

{
	{{#each data.secrets}}
	  {
	"type": "TextBlock",
	"text": "{{@key}}: {{this}}",
	"wrap": true
	},
	{{/each}}
}

For loop to print specific values from an array of maps

{{#each data.secrets}}
	{
	"secret_expiration": "{{secret_expiration}}",
	 "event_time": "{{event_time}}"
	 }
{{/each}}

Accessing a value from a payload where the key contains special characters

Payload:

"toolchain.tool-instance":{
	"name":"sample-date"
}

Accessing name:

{{[toolchain.tool-instance].name}}

To access the name value from a JSON payload where the key is "toolchain.tool-instance" , the syntax {{[toolchain.tool-instance].name}} is used because the key contains special characters and cannot directly be accessed with a dot notation.