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 {
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,
}
}

View file

@ -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)
}

View file

@ -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,
}
}
}
}