36 lines
697 B
Go
36 lines
697 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"html/template"
|
||
|
"log"
|
||
|
|
||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||
|
)
|
||
|
|
||
|
type TelegramBotSender interface {
|
||
|
Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
|
||
|
}
|
||
|
|
||
|
type TgSender struct {
|
||
|
bot TelegramBotSender
|
||
|
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
|
||
|
}
|