package main
import (
"html/template"
"log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type TelegramBot interface {
Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
GetUpdatesChan(u tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel
StopReceivingUpdates()
}
type EmptyBot struct{}
func (_ EmptyBot) Send(_ tgbotapi.Chattable) (tgbotapi.Message, error) {
return tgbotapi.Message{}, nil
}
func (_ EmptyBot) GetUpdatesChan(u tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel {
ch := make(chan tgbotapi.Update)
close(ch)
return ch
}
func (_ EmptyBot) StopReceivingUpdates() {}
type TgSender struct {
bot TelegramBot
s SatelNameGetter
logger *log.Logger
chatIds []int64
}
func (self TgSender) Send(msg GenericMessage, tpl *template.Template) error {
if len(self.chatIds) == 0 {
return nil
}
message := msg.Format(tpl, self.s, self.logger)
for _, chatId := range self.chatIds {
toSend := tgbotapi.NewMessage(chatId, message)
toSend.ParseMode = "HTML"
_, err := self.bot.Send(toSend)
if err != nil {
return err
}
}
return nil
}