Skip to content

Commit

Permalink
Merge pull request #104 from BDelacour/feature/telegram-parse-mode
Browse files Browse the repository at this point in the history
Telegram provider : add ParseMode and DisableWebPagePreview configs
  • Loading branch information
marcel corso gonzalez authored Nov 16, 2021
2 parents 2964ecf + 18cb0bf commit edf8d3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/sachet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions provider/telegram/telegram.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
package telegram

import (
"strconv"

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

type TelegramConfig struct {
Token string `yaml:"token"`
type Config struct {
Token string `yaml:"token"`
ParseMode string `yaml:"parse_mode"`
DisableWebPagePreview bool `yaml:"disable_web_page_preview"`
}

type Telegram struct {
bot *tgbotapi.BotAPI
bot *tgbotapi.BotAPI
config *Config
}

func NewTelegram(config TelegramConfig) (*Telegram, error) {
func NewTelegram(config Config) (*Telegram, error) {
bot, err := tgbotapi.NewBotAPI(config.Token)
if err != nil {
return nil, err
}

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

Expand All @@ -32,7 +35,11 @@ func (tg *Telegram) Send(message sachet.Message) error {
if err != nil {
return err
}

msg := tgbotapi.NewMessage(chatID, message.Text)
msg.ParseMode = tg.config.ParseMode
msg.DisableWebPagePreview = tg.config.DisableWebPagePreview

_, err = tg.bot.Send(msg)
if err != nil {
return err
Expand Down

0 comments on commit edf8d3e

Please sign in to comment.