Files
archie/internal/config/chat_frontends.go
T

46 lines
1.2 KiB
Go

package config
import "strings"
// ChatFrontEnd is one conversational front-end [chat] can enable. ID is its
// stable identifier.
type ChatFrontEnd struct {
ID string
Name string
Configured bool
}
// FrontEnds returns every chat front-end this configuration enables, in
// dashboard order. Whitespace-only values do not count as configured.
func (c ChatConfig) FrontEnds() []ChatFrontEnd {
return []ChatFrontEnd{
{
ID: "telegram",
Name: "Telegram",
Configured: c.Telegram.Token != (SecretRef{}),
},
{
ID: "email",
Name: "Email",
Configured: strings.TrimSpace(c.Email.ListenAddr) != "",
},
{
ID: "webhook",
Name: "Webhook gateway",
Configured: strings.TrimSpace(c.WebhookAddr) != "",
},
}
}
// AnyFrontEndConfigured reports whether at least one conversational front-end
// has credentials. The setup checklist asks this as a yes/no question; every
// other consumer wants the per-front-end detail FrontEnds returns.
func (c ChatConfig) AnyFrontEndConfigured() bool {
for _, frontEnd := range c.FrontEnds() {
if frontEnd.Configured {
return true
}
}
return false
}