mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 08:43:10 -07:00
return linked account from /api/health
This commit is contained in:
parent
9672b30778
commit
5d99180862
3 changed files with 29 additions and 7 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue