Skip to content

Commit

Permalink
Supported reply_to_message_id for Telegram topics.
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimRezvov committed Oct 16, 2023
1 parent acb5840 commit 41a7817
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ type TelegramConfig struct {
Message string `yaml:"message,omitempty" json:"message,omitempty"`
DisableNotifications bool `yaml:"disable_notifications,omitempty" json:"disable_notifications,omitempty"`
ParseMode string `yaml:"parse_mode,omitempty" json:"parse_mode,omitempty"`
ReplyToMessageID int64 `yaml:"reply_to_message_id,omitempty" json:"reply_to_message_id,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand Down
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,18 @@ attributes:
# ID of the chat where to send the messages.
[ chat_id: <int> ]

# id of the message in response to which the notification will be sent.
# Primarily intended for sending notifications to a specific Telegram topic.
# see https://telegram.org/blog/topics-in-groups-collectible-usernames
# To do this, you need to pass the id of the first message in the topic by this parameter.
# In order to find out the id of the first message in a topic, in the Telegram desktop client,
# right-click on the first message in the topic, select "Copy Message Link".
# Get a link like:
# https://t.me/c/1234567890/1234/1235
# The second part of the link is the id of the first message in the topic:
# 1234
[ reply_to_message_id: <int> ]

# Message template.
[ message: <tmpl_string> default = '{{ template "telegram.default.message" .}}' ]

Expand Down
1 change: 1 addition & 0 deletions notify/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
}

message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{
ReplyTo: &telebot.Message{ID: int(n.conf.ReplyToMessageID)},
DisableNotification: n.conf.DisableNotifications,
DisableWebPagePreview: true,
})
Expand Down

0 comments on commit 41a7817

Please sign in to comment.