return linked account from /api/health

This commit is contained in:
Egor 2026-02-07 12:58:36 -08:00
parent 9672b30778
commit 5d99180862
3 changed files with 29 additions and 7 deletions

View file

@ -25,6 +25,7 @@ type Integration interface {
type Integrations struct { type Integrations struct {
Dispatcher *notification.Dispatcher Dispatcher *notification.Dispatcher
Signal *signal.Integration Signal *signal.Integration
Telegram *telegram.Integration
integrations []Integration integrations []Integration
} }
@ -51,6 +52,7 @@ func Initialize(cfg *config.Config, store *notification.Store, logger *slog.Logg
return &Integrations{ return &Integrations{
Dispatcher: dispatcher, Dispatcher: dispatcher,
Signal: signalIntegration, Signal: signalIntegration,
Telegram: telegramIntegration,
integrations: integrations, integrations: integrations,
} }
} }

View file

@ -44,6 +44,10 @@ func (t *Integration) GetSender() *Sender {
return t.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) { func (t *Integration) RegisterRoutes(router *chi.Mux, auth func(http.Handler) http.Handler) {
RegisterRoutes(router, t.handlers, auth) RegisterRoutes(router, t.handlers, auth)
} }

View file

@ -17,7 +17,8 @@ type healthResponse struct {
} }
type integrationHealth 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) { 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() { if s.integrations.Signal != nil && s.integrations.Signal.IsEnabled() {
signalClient := s.integrations.Signal.GetHandlers().GetClient() signalClient := s.integrations.Signal.GetHandlers().GetClient()
account, _ := signalClient.GetLinkedAccount() account, _ := signalClient.GetLinkedAccount()
resp.Signal = &integrationHealth{ if account != nil {
Linked: account != nil, resp.Signal = &integrationHealth{
Linked: true,
Account: account.Number,
}
} else {
resp.Signal = &integrationHealth{
Linked: false,
}
} }
} }
if s.cfg.IsProtonEnabled() { if s.cfg.IsProtonEnabled() {
resp.Proton = &integrationHealth{ resp.Proton = &integrationHealth{
Linked: true, Linked: true,
Account: s.cfg.ProtonIMAPUsername,
} }
} }
if s.cfg.IsTelegramEnabled() { if s.integrations.Telegram != nil && s.integrations.Telegram.IsEnabled() {
resp.Telegram = &integrationHealth{ telegramClient := s.integrations.Telegram.GetHandlers().GetClient()
Linked: true, if telegramClient != nil {
bot, err := telegramClient.GetMe()
if err == nil {
resp.Telegram = &integrationHealth{
Linked: true,
Account: "@" + bot.Username,
}
}
} }
} }