IBM Cloud Docs
Creating an Event Notifications template

Creating an Event Notifications template

An IBM Cloud Event Notifications template is a pre-defined layout that includes images, text, and dynamic content based on an event. You can use a template as a base and customize it rather than creating a new one from scratch each time.

Creating a 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.

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

  5. Click Add to save your updates.

Handlebars Integration

Handlebars is a templating language that allows for dynamic content generation within templates. Handlebars can be used to customize notification messages 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 users 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 users 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 users 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}}
}

There are more helpers available for use that can be referenced from here

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 along 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 and every key value from array of map

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

For loop to print specific values from a array of map

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

Accessing value from payload where the key contains special chanracters

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.