1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-12-04 09:43:04 +02:00

Merge pull request #302 from qwqcode/main

This commit is contained in:
Niko Köser 2022-08-05 10:46:44 +02:00 committed by GitHub
commit 98820347bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,12 @@ import (
"github.com/pkg/errors"
)
const defaultParseMode = tgbotapi.ModeHTML
const (
ModeMarkdown = tgbotapi.ModeMarkdown
ModeHTML = tgbotapi.ModeHTML
)
var parseMode = ModeHTML // HTML is the default mode.
// Telegram struct holds necessary data to communicate with the Telegram API.
type Telegram struct {
@ -33,6 +38,14 @@ func New(apiToken string) (*Telegram, error) {
return t, nil
}
// SetParseMode sets the parse mode for the message body.
// For more information about telegram constants:
//
// -> https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api#pkg-constants
func (t *Telegram) SetParseMode(mode string) {
parseMode = mode
}
// AddReceivers takes Telegram chat IDs and adds them to the internal chat ID list. The Send method will send
// a given message to all those chats.
func (t *Telegram) AddReceivers(chatIDs ...int64) {
@ -45,7 +58,7 @@ func (t Telegram) Send(ctx context.Context, subject, message string) error {
fullMessage := subject + "\n" + message // Treating subject as message title
msg := tgbotapi.NewMessage(0, fullMessage)
msg.ParseMode = defaultParseMode
msg.ParseMode = parseMode
for _, chatID := range t.chatIDs {
select {