diff --git a/service/integration/integration.go b/service/integration/integration.go index 98ebe51..40d9e4c 100644 --- a/service/integration/integration.go +++ b/service/integration/integration.go @@ -25,6 +25,7 @@ type Integration interface { type Integrations struct { Dispatcher *notification.Dispatcher Signal *signal.Integration + Telegram *telegram.Integration integrations []Integration } @@ -51,6 +52,7 @@ func Initialize(cfg *config.Config, store *notification.Store, logger *slog.Logg return &Integrations{ Dispatcher: dispatcher, Signal: signalIntegration, + Telegram: telegramIntegration, integrations: integrations, } } diff --git a/service/integration/telegram/integration.go b/service/integration/telegram/integration.go index c14afc3..43ced9b 100644 --- a/service/integration/telegram/integration.go +++ b/service/integration/telegram/integration.go @@ -44,6 +44,10 @@ func (t *Integration) GetSender() *Sender { return t.sender } +func (t *Integration) GetHandlers() *Handlers { + return t.handlers +} + func (t *Integration) RegisterRoutes(router *chi.Mux, auth func(http.Handler) http.Handler) { RegisterRoutes(router, t.handlers, auth) } diff --git a/service/server/handlers_health.go b/service/server/handlers_health.go index 60f05c4..55cf5a5 100644 --- a/service/server/handlers_health.go +++ b/service/server/handlers_health.go @@ -17,7 +17,8 @@ type healthResponse struct { } type integrationHealth struct { - Linked bool `json:"linked"` + Linked bool `json:"linked"` + Account string `json:"account,omitempty"` } func (s *Server) handleHealthCheck(w http.ResponseWriter, r *http.Request) { @@ -35,20 +36,35 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { if s.integrations.Signal != nil && s.integrations.Signal.IsEnabled() { signalClient := s.integrations.Signal.GetHandlers().GetClient() account, _ := signalClient.GetLinkedAccount() - resp.Signal = &integrationHealth{ - Linked: account != nil, + if account != nil { + resp.Signal = &integrationHealth{ + Linked: true, + Account: account.Number, + } + } else { + resp.Signal = &integrationHealth{ + Linked: false, + } } } if s.cfg.IsProtonEnabled() { resp.Proton = &integrationHealth{ - Linked: true, + Linked: true, + Account: s.cfg.ProtonIMAPUsername, } } - if s.cfg.IsTelegramEnabled() { - resp.Telegram = &integrationHealth{ - Linked: true, + if s.integrations.Telegram != nil && s.integrations.Telegram.IsEnabled() { + telegramClient := s.integrations.Telegram.GetHandlers().GetClient() + if telegramClient != nil { + bot, err := telegramClient.GetMe() + if err == nil { + resp.Telegram = &integrationHealth{ + Linked: true, + Account: "@" + bot.Username, + } + } } }