Skip to content

Commit a31aeb5

Browse files
committed
feat(rocketchat): support plain text attribute
Add plainText attribute to set plain text message additionally to attachment. Signed-off-by: Patrick Remy <patrick-remy@users.noreply.github.com>
1 parent b49dfc0 commit a31aeb5

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

config/notifiers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ type RocketchatConfig struct {
975975
Title string `yaml:"title,omitempty" json:"title,omitempty"`
976976
TitleLink string `yaml:"title_link,omitempty" json:"title_link,omitempty"`
977977
Text string `yaml:"text,omitempty" json:"text,omitempty"`
978+
PlainText string `yaml:"plain_text,omitempty" json:"plain_text,omitempty"`
978979
Fields []*RocketchatAttachmentField `yaml:"fields,omitempty" json:"fields,omitempty"`
979980
ShortFields bool `yaml:"short_fields" json:"short_fields,omitempty"`
980981
Emoji string `yaml:"emoji,omitempty" json:"emoji,omitempty"`

docs/configuration.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,12 +1360,15 @@ token_id_file: <filepath>
13601360
13611361
13621362
[ color: <tmpl_string | default '{{ if eq .Status "firing" }}red{{ else }}green{{ end }}' ]
1363-
[ emoji <tmpl_string | default = '{{ template "rocketchat.default.emoji" . }}'
1364-
[ icon_url <tmpl_string | default = '{{ template "rocketchat.default.iconurl" . }}'
1365-
[ text <tmpl_string | default = '{{ template "rocketchat.default.text" . }}'
1366-
[ title <tmpl_string | default = '{{ template "rocketchat.default.title" . }}'
1367-
[ titleLink <tmpl_string | default = '{{ template "rocketchat.default.titlelink" . }}'
1368-
[ text: <tmpl_string | default = '{{ template "rocketchat.default.text" . }}'
1363+
[ emoji: <tmpl_string | default = '{{ template "rocketchat.default.emoji" . }}' ]
1364+
[ icon_url: <tmpl_string | default = '{{ template "rocketchat.default.iconurl" . }}' ]
1365+
[ text: <tmpl_string | default = '{{ template "rocketchat.default.text" . }}' ]
1366+
[ title: <tmpl_string | default = '{{ template "rocketchat.default.title" . }}' ]
1367+
[ titleLink: <tmpl_string | default = '{{ template "rocketchat.default.titlelink" . }}' ]
1368+
[ text: <tmpl_string | default = '{{ template "rocketchat.default.text" . }}' ]
1369+
# rocketchat notifications do not contain attachment title, you could set this
1370+
# to {{ template "rocketchat.default.title" . }} to include title in push
1371+
[ plain_text: <tmpl_string> ]
13691372
fields:
13701373
[ <rocketchat_field_config> ... ]
13711374
[ image_url <tmpl_string> ]

notify/rocketchat/rocketchat.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ type Notifier struct {
4646
postJSONFunc func(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
4747
}
4848

49-
// PostMessage Payload for postmessage rest API
49+
// PostMessage.Attachment Payload for postmessage rest API
5050
//
51-
// https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/
51+
// https://developer.rocket.chat/apidocs/post-message
5252
type Attachment struct {
5353
Title string `json:"title,omitempty"`
5454
TitleLink string `json:"title_link,omitempty"`
@@ -62,11 +62,10 @@ type Attachment struct {
6262

6363
// PostMessage Payload for postmessage rest API
6464
//
65-
// https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/
65+
// https://developer.rocket.chat/apidocs/post-message
6666
type PostMessage struct {
6767
Channel string `json:"channel,omitempty"`
6868
Text string `json:"text,omitempty"`
69-
ParseUrls bool `json:"parseUrls,omitempty"`
7069
Alias string `json:"alias,omitempty"`
7170
Emoji string `json:"emoji,omitempty"`
7271
Avatar string `json:"avatar,omitempty"`
@@ -205,6 +204,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
205204
Channel: tmplText(n.conf.Channel),
206205
Emoji: tmplText(n.conf.Emoji),
207206
Avatar: tmplText(n.conf.IconURL),
207+
Text: tmplText(n.conf.PlainText),
208208
Attachments: []Attachment{*att},
209209
}
210210
if err != nil {

0 commit comments

Comments
 (0)