42 lines
842 B
Go
42 lines
842 B
Go
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|