Templatize receiver details in receiver in Subscription of Notification Service
Is your feature request related to a problem? Please describe. Based on this PRD and this RFC. We plan to move responsibility of sending notification to siren from provider. There is a need to flexibly send custom notification messages to each receiver type.
Describe the solution you'd like
The Flow Custom notification message could be implemented with a pre-defined template assigned to each receiver in the subscription flow. When subscribing a notification, one should pass this struct.
type Subscription struct {
ID uint64 `json:"id"`
URN string `json:"urn"`
Namespace uint64 `json:"namespace"`
Receivers []Receiver `json:"receivers"`
Match map[string]string `json:"match"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Each receiver needs to be like this
type Receiver struct {
ID uint64 `json:"id"`
Type string `json:"type"`
Configuration map[string]string `json:"configuration"`
}
Depending on the receiver type, receiver configuration could have various field. A new template field could be added to define that this receiver of the subscription would use the template for the notification message.
The Template
The template could be created with the same way as user create template for the rules. Instead of having a type rule, template would have type notification. The content of the template should be compatible with the contract of receiver type payload. For example, this is how the slack notification template is.
apiVersion: v2
type: template
name: alert-slack-details
body:
receiver_type: slack
attachments:
- text: '[[.text]]'
icon_emoji: ':eagle:'
link_names: false
color: '[[.color]]'
title: '[[.title]]'
pretext: '[[.pretext]]'
text: '[[.text]]'
actions:
- type: button
text: 'Runbook :books:'
url: '[[.runbook"]]'
- type: button
text: 'Dashboard :bar_chart:'
url: '[[.dashboard"]]'
variables:
- name: color
type: string
description: slack color
default: #2eb886
- name: text
type: string
default: This is an alert
- name: title
type: string
default: Alert
- name: pretext
type: string
description: Pre-text of slack alert
default: Siren
- name: runbook
type: string
description: url to runbook
default: http://url
- name: dashboard
type: string
description: url to dashboard
default: http://url
tags:
- slack
Template will be rendered when notification is being dispatched and before a notification message is generated. Therefore, notification message would contain the rendered version of the notification message. Other than that, variables are being populated based on labels that the notification has.