This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
summer-utils/notifier/telegram.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)
}
}