Website/telegram.go

43 lines
842 B
Go
Raw Permalink Normal View History

2024-08-14 10:43:07 +00:00
package main
import (
"log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func startTelegramBot() {
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
_, err := bot.Send(msg)
if err != nil {
log.Printf("Error sending message: %v", err)
}
}
}
2024-08-16 12:46:31 +00:00
func sendTelegramNotification(message string) {
if bot == nil {
log.Println("Telegram bot is not initialized")
return
}
// Replace with the actual chat ID you want to send messages to
chatID := int64(YOUR_TELEGRAM_CHAT_ID)
msg := tgbotapi.NewMessage(chatID, message)
_, err := bot.Send(msg)
if err != nil {
log.Printf("Error sending Telegram notification: %v", err)
}
}