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 {
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ 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()
|
||||||
|
if account != nil {
|
||||||
resp.Signal = &integrationHealth{
|
resp.Signal = &integrationHealth{
|
||||||
Linked: account != nil,
|
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() {
|
||||||
|
telegramClient := s.integrations.Telegram.GetHandlers().GetClient()
|
||||||
|
if telegramClient != nil {
|
||||||
|
bot, err := telegramClient.GetMe()
|
||||||
|
if err == nil {
|
||||||
resp.Telegram = &integrationHealth{
|
resp.Telegram = &integrationHealth{
|
||||||
Linked: true,
|
Linked: true,
|
||||||
|
Account: "@" + bot.Username,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue