Skip to content

Commit

Permalink
add ParseMode config for Telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmaks committed Oct 8, 2018
1 parent 753711e commit c3eaaab
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions provider/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,41 @@ package telegram

import (
"strconv"
"strings"

"github.com/messagebird/sachet"
"gopkg.in/telegram-bot-api.v4"
)

type TelegramConfig struct {
Token string `yaml:"token"`
Token string `yaml:"token"`
ParseMode string `yaml:"parse_mode"`
}

type Telegram struct {
bot *tgbotapi.BotAPI
bot *tgbotapi.BotAPI
ParseMode string
}

func NewTelegram(config TelegramConfig) (*Telegram, error) {
ParseMode := strings.ToLower(config.ParseMode)
switch ParseMode {
case "md", "markdown":
ParseMode = "Markdown"
case "html", "h":
ParseMode = "HTML"
default:
ParseMode = ""
}

bot, err := tgbotapi.NewBotAPI(config.Token)
if err != nil {
return nil, err
}

return &Telegram{
bot: bot,
bot: bot,
ParseMode: ParseMode,
}, nil
}

Expand All @@ -33,6 +47,7 @@ func (tg *Telegram) Send(message sachet.Message) error {
return err
}
msg := tgbotapi.NewMessage(chatID, message.Text)
msg.ParseMode = tg.ParseMode
_, err = tg.bot.Send(msg)
if err != nil {
return err
Expand Down

0 comments on commit c3eaaab

Please sign in to comment.