Skip to content

Commit

Permalink
Merge pull request #302 from qwqcode/main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoksr committed Aug 5, 2022
2 parents 2a4c078 + f400135 commit 9882034
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 9882034

Please sign in to comment.