diff --git a/bot/bot.go b/bot/bot.go index d3d0215..7bc3f2a 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -8,7 +8,6 @@ import ( "git.dev.m-and-m.ovh/mderasse/tesla/alert" "git.dev.m-and-m.ovh/mderasse/tesla/api" - "gopkg.in/telebot.v3/middleware" log "github.com/sirupsen/logrus" tele "gopkg.in/telebot.v3" @@ -79,10 +78,23 @@ func handleAlert(bot *tele.Bot, config *botConfig, alertChan chan api.Availabili func initMiddlewares(bot *tele.Bot, config *botConfig) { log.Infof("Trusting the following chats: %v", config.WhiteListChatIds) bot.Use( - middleware.Whitelist(config.WhiteListChatIds...), + middlewareAllowChat(config.WhiteListChatIds...), ) } +func middlewareAllowChat(chatIds ...int64) tele.MiddlewareFunc { + return func(next tele.HandlerFunc) tele.HandlerFunc { + return func(c tele.Context) error { + for _, chat := range chatIds { + if chat == c.Chat().ID { + return next(c) + } + } + return nil + } + } +} + func initCommands(bot *tele.Bot, config *botConfig) { bot.Handle(tele.OnText, func(c tele.Context) error { diff --git a/bot/config.go b/bot/config.go index c35305c..f3ef45b 100644 --- a/bot/config.go +++ b/bot/config.go @@ -85,7 +85,7 @@ func initBotConfig() (*botConfig, error) { return nil, fmt.Errorf("impossible to use TELEGRAM_WHITELIST_CHAT_IDS. format expected: int64,int64") } - config.WhiteListChatIds = append(config.AlertChatIds, chatId) + config.WhiteListChatIds = append(config.WhiteListChatIds, chatId) } return &config, nil