2025-02-09 16:34:46 +08:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
tg "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
telegramToken = "7215466800:AAGwjZnXEfbbjQiA0y7qtSzbSZNUWQJnyjo"
|
|
|
|
telegramChatID = 622943829
|
|
|
|
)
|
|
|
|
|
2025-02-09 17:05:57 +08:00
|
|
|
type LogEntry struct {
|
|
|
|
AuditData struct {
|
|
|
|
Messages []string `json:"messages"`
|
|
|
|
} `json:"audit_data"`
|
|
|
|
}
|
|
|
|
|
2025-02-09 17:40:04 +08:00
|
|
|
func TelegramBotInit() (*tg.BotAPI, error) {
|
2025-02-09 16:34:46 +08:00
|
|
|
bot, err := tg.NewBotAPI(telegramToken)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to create Telegram bot:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Telegram bot connected")
|
|
|
|
|
|
|
|
// send init message on startup
|
|
|
|
testMsg := tg.NewMessage(telegramChatID, "I'm in")
|
|
|
|
_, err = bot.Send(testMsg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to send test message:", err)
|
|
|
|
}
|
|
|
|
|
2025-02-09 17:40:04 +08:00
|
|
|
return bot, nil
|
2025-02-09 16:34:46 +08:00
|
|
|
}
|
|
|
|
|
2025-02-09 17:40:04 +08:00
|
|
|
func SendTelegramAlert(bot *tg.BotAPI, message string) {
|
2025-02-09 17:05:57 +08:00
|
|
|
msg := tg.NewMessage(telegramChatID, fmt.Sprintf("🚨 *WEEWOO ALERT* 🚨\n%s", message))
|
|
|
|
_, err := bot.Send(msg)
|
|
|
|
if err != nil {
|
2025-02-09 17:30:30 +08:00
|
|
|
log.Println("Failed to send Telegram message:", err)
|
2025-02-09 17:05:57 +08:00
|
|
|
}
|
2025-02-09 16:34:46 +08:00
|
|
|
}
|