Customize Alert Template

The application alerts can notify you when your queries match some arbitrary criteria.

Next to the setting labeled “Template”, click the dropdown and select “Custom template”. A box will appear, consisting of input fields for subject and body.

Any static content is valid, and you can also incorporate some built-in template variables:

  • ALERT_STATUS - The evaluated alert status (string).

  • ALERT_CONDITION - The alert condition operator (string).

  • ALERT_THRESHOLD - The alert threshold (string or number).

  • ALERT_NAME - The alert name (string).

  • ALERT_URL - The alert page url (string).

  • QUERY_NAME - The correlated query name (string).

  • QUERY_URL - The correlated query page url (string).

  • QUERY_RESULT_VALUE - The query result value (string or number).

  • QUERY_RESULT_ROWS - The query result rows (value array).

  • QUERY_RESULT_COLS - The query result columns (string array).

  • QUERY_RESULT_TABLE - Query results formatted as two dimensional array of values.

An example subject, for instance, could be: Alert "{{ALERT_NAME}}" changed status to {{ALERT_STATUS}}

Click the “Preview” toggle button to preview the rendered result and save your changes by clicking the “Save” button.

The preview is useful for verifying that template variables get rendered correctly. It is not an accurate representation of the eventual notification content, as each alert destinations can display notifications differently.

The preview is useful for verifying that template variables get rendered correctly. It is not an accurate representation of the eventual notification content, as each alert destinations can display notifications differently.

To return to the default the application message templates, re-select “Default template” at any time.

Examples of two types of customized templates you can provide:

Text-Based Template:

  • This type uses placeholders within a string to represent real-time data.

  • Placeholders are enclosed in double curly braces: {{ }}.

  • Use dot notation to access list items (e.g., {{symbol.0}} for the first item).

  • Formatting options (like .2% or :,.2f) can be appended to variables to display values in specific formats.

When using "Each time alert is evaluated for each row in the result", you don't need to specify the row (e.g., {{symbol}} for the item).

JSON-Based Template:

  • This type employs the JSON format, offering a more structured and rich content presentation.

  • Key Elements:

    • content: A string where you can place general content.

    • embeds: An array that can contain multiple embed objects. Each embed object can have:

      • title: The main heading of the embed.

      • color: A numerical value representing the color of the embed line in decimal format.

      • image: An object with a URL for the image to display.

      • fields: An array of objects, where each object represents a piece of data to display. Each field can have:

        • name: The name or label for the data.

        • value: The value of the data, with placeholders (like {{block_link}}).

        • inline: A boolean (true or false) indicating if the field should be displayed inline with others.

By understanding these elements, you can effectively customize alert templates in the application to suit your specific needs. Remember to always test your templates to ensure they display as expected when triggered.

Let's have a look at this example, using "Each time alert is evaluated for each row in the result" notification type

If we use this query:

We can write this custom template for our alert:

here's how the columns map to the template:

  • block: Reflected in the template as {{block_link.2}} which is a hyperlink to the block on Etherscan, referring to the third row of "block_link" column.

  • timestamp: Appears in the template as {{timestamp.2}} and will display the timestamp of the event, referring to the third row of "timestamp" column.

  • amount: Appears as {{amount.1:,.2f}} DOLA in the template. The format :,.2f indicates that the amount will be displayed with two decimal places and commas as thousand separators, followed by the word "DOLA". .1refers to the second row of "amount" column.

  • transaction_hash: Reflected as {{transaction_hash_link.0}} in the template, which is a hyperlink to the specific transaction on Etherscan. .0 refers to the first row of "transaction_hash_link" column.

Now if we want to use another notification type such as "Each time alert is evaluated until back to normal" and specify a particular row from the query result in the template, we can write this custom template:

{
   "content":"",
   "embeds":[
      {
         "title":"Debt Converter : Redemption detected",
         "color":78368,
         "image":{
            "url":""
         },
         "fields":[
            {
               "name":"Block",
               "value":"{{block_link.2}}",  // Referring to the third row's block link
               "inline":false
            },
            {
               "name":"Timestamp",
               "value":"{{timestamp.2}}",  // Referring to the third row's timestamp
               "inline":false
            },
            {
               "name":"Amount",
               "value":"{{amount.1:,.2f}} DOLA",  // Referring to the third row's amount
               "inline":false
            },
            {
               "name":"Transaction",
               "value":"{{transaction_hash_link.0}}",  // Referring to the third row's transaction link
               "inline":false
            }
         ]
      }
   ]
}

If you wish to modify an alert, click the “Edit” button at the top of the alert page.

Last updated