Skip to content

Commit

Permalink
add parsemode option for telegram (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
parrasajad committed Aug 24, 2022
1 parent b9b6a8b commit ae8f638
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -109,6 +109,8 @@ telegram:
telegram_api_key: "XXXXXXXXXXXX"
telegram_chat_id: "XXXXXXXX"
telegram_format: "{{data}}"
# https://core.telegram.org/bots/api#formatting-options
telegram_parsemode: "Markdown" # None/Markdown/MarkdownV2/HTML

pushover:
- id: "push"
Expand Down
15 changes: 9 additions & 6 deletions pkg/providers/telegram/telegram.go
Expand Up @@ -16,10 +16,11 @@ type Provider struct {
}

type Options struct {
ID string `yaml:"id,omitempty"`
TelegramAPIKey string `yaml:"telegram_api_key,omitempty"`
TelegramChatID string `yaml:"telegram_chat_id,omitempty"`
TelegramFormat string `yaml:"telegram_format,omitempty"`
ID string `yaml:"id,omitempty"`
TelegramAPIKey string `yaml:"telegram_api_key,omitempty"`
TelegramChatID string `yaml:"telegram_chat_id,omitempty"`
TelegramFormat string `yaml:"telegram_format,omitempty"`
TelegramParseMode string `yaml:"telegram_parsemode,omitempty"`
}

func New(options []*Options, ids []string) (*Provider, error) {
Expand All @@ -38,8 +39,10 @@ func (p *Provider) Send(message, CliFormat string) error {
var TelegramErr error
for _, pr := range p.Telegram {
msg := utils.FormatMessage(message, utils.SelectFormat(CliFormat, pr.TelegramFormat))

url := fmt.Sprintf("telegram://%s@telegram?channels=%s", pr.TelegramAPIKey, pr.TelegramChatID)
if pr.TelegramParseMode == "" {
pr.TelegramParseMode = "None"
}
url := fmt.Sprintf("telegram://%s@telegram?channels=%s&parsemode=%s", pr.TelegramAPIKey, pr.TelegramChatID, pr.TelegramParseMode)
err := shoutrrr.Send(url, msg)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed to send telegram notification for id: %s ", pr.ID))
Expand Down

0 comments on commit ae8f638

Please sign in to comment.