32 lines
643 B
Go
32 lines
643 B
Go
package notifier
|
|
|
|
import (
|
|
tgBotApi5 "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
"log"
|
|
"strconv"
|
|
)
|
|
|
|
type Telegram struct {
|
|
bot *tgBotApi5.BotAPI
|
|
chatId int64
|
|
}
|
|
|
|
func newTelegram(token, chat string) (*Telegram, error) {
|
|
bot, err := tgBotApi5.NewBotAPI(token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
chatId, err := strconv.ParseInt(chat, 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Telegram{bot: bot, chatId: chatId}, nil
|
|
}
|
|
|
|
func (t *Telegram) SendMessage(s string) {
|
|
_, err := t.bot.Send(tgBotApi5.NewMessage(t.chatId, s))
|
|
if err != nil {
|
|
log.Printf("[Notifier:Telegram] Failed to send message: %s\n", err)
|
|
}
|
|
}
|