diff --git a/cmd/sachet/config.go b/cmd/sachet/config.go index 9720618..68ecc8f 100644 --- a/cmd/sachet/config.go +++ b/cmd/sachet/config.go @@ -53,7 +53,7 @@ var config struct { Exotel exotel.ExotelConfig CM cm.CMConfig MailruIM mailruim.MailruIMConfig - Telegram telegram.TelegramConfig + Telegram telegram.Config Turbosms turbosms.TurbosmsConfig Smsc smsc.SmscConfig OTC otc.OTCConfig diff --git a/provider/telegram/telegram.go b/provider/telegram/telegram.go index 4dac41d..cbf8b85 100644 --- a/provider/telegram/telegram.go +++ b/provider/telegram/telegram.go @@ -1,42 +1,30 @@ package telegram import ( - "strconv" - "strings" - "github.com/messagebird/sachet" "gopkg.in/telegram-bot-api.v4" + "strconv" ) -type TelegramConfig struct { +type Config struct { Token string `yaml:"token"` ParseMode string `yaml:"parse_mode"` } type Telegram struct { bot *tgbotapi.BotAPI - ParseMode string + config *Config } -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 = "" - } - +func NewTelegram(config Config) (*Telegram, error) { bot, err := tgbotapi.NewBotAPI(config.Token) if err != nil { return nil, err } return &Telegram{ - bot: bot, - ParseMode: ParseMode, + bot: bot, + config: &config, }, nil } @@ -46,8 +34,10 @@ func (tg *Telegram) Send(message sachet.Message) error { if err != nil { return err } + msg := tgbotapi.NewMessage(chatID, message.Text) - msg.ParseMode = tg.ParseMode + msg.ParseMode = tg.config.ParseMode + _, err = tg.bot.Send(msg) if err != nil { return err