feat: add Telegram bot with notifications and scheduler

This commit is contained in:
Cosmo
2026-02-06 13:16:50 +00:00
parent 5a40127edd
commit 9e467b0448
19 changed files with 1007 additions and 110 deletions

View File

@@ -9,10 +9,12 @@ import (
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
"github.com/daniil/homelab-api/internal/bot"
"github.com/daniil/homelab-api/internal/config"
"github.com/daniil/homelab-api/internal/handler"
customMiddleware "github.com/daniil/homelab-api/internal/middleware"
"github.com/daniil/homelab-api/internal/repository"
"github.com/daniil/homelab-api/internal/scheduler"
"github.com/daniil/homelab-api/internal/service"
)
@@ -43,11 +45,28 @@ func main() {
habitService := service.NewHabitService(habitRepo)
taskService := service.NewTaskService(taskRepo)
// Initialize Telegram bot
telegramBot, err := bot.New(cfg.TelegramBotToken, userRepo, taskRepo, habitRepo)
if err != nil {
log.Printf("Failed to initialize Telegram bot: %v", err)
}
// Start bot in goroutine
if telegramBot != nil {
go telegramBot.Start()
}
// Initialize scheduler
sched := scheduler.New(telegramBot, userRepo, taskRepo, habitRepo)
sched.Start()
defer sched.Stop()
// Initialize handlers
authHandler := handler.NewAuthHandler(authService)
habitHandler := handler.NewHabitHandler(habitService)
taskHandler := handler.NewTaskHandler(taskService)
healthHandler := handler.NewHealthHandler()
profileHandler := handler.NewProfileHandler(userRepo)
// Initialize middleware
authMiddleware := customMiddleware.NewAuthMiddleware(cfg.JWTSecret)
@@ -89,6 +108,10 @@ func main() {
r.Put("/auth/me", authHandler.UpdateProfile)
r.Put("/auth/password", authHandler.ChangePassword)
// Profile routes
r.Get("/profile", profileHandler.Get)
r.Put("/profile", profileHandler.Update)
// Habits routes
r.Get("/habits", habitHandler.List)
r.Post("/habits", habitHandler.Create)