-
Notifications
You must be signed in to change notification settings - Fork 3
/
configuration.go
79 lines (64 loc) · 2.35 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"os"
"strings"
"github.com/rs/zerolog"
"go.mau.fi/util/dbutil"
"go.mau.fi/zeroconfig"
"maunium.net/go/mautrix/id"
"github.com/beeper/chatwoot/chatwootapi"
)
type BackfillConfiguration struct {
ChatwootConversations bool `yaml:"chatwoot_conversations"`
ConversationIDStateEvents bool `yaml:"conversation_id_state_events"`
}
type HomeserverWhitelist struct {
Enable bool `yaml:"enable"`
Allowed []string `yaml:"allowed"`
}
type StartNewChat struct {
Enable bool `yaml:"enable"`
Endpoint string `yaml:"endpoint"`
Token string `yaml:"token"`
}
type Configuration struct {
// Authentication settings
Homeserver string `yaml:"homeserver"`
Username id.UserID `yaml:"username"`
PasswordFile string `yaml:"password_file"`
// Chatwoot Authentication
ChatwootBaseUrl string `yaml:"chatwoot_base_url"`
ChatwootAccessTokenFile string `yaml:"chatwoot_access_token_file"`
ChatwootAccountID chatwootapi.AccountID `yaml:"chatwoot_account_id"`
ChatwootInboxID chatwootapi.InboxID `yaml:"chatwoot_inbox_id"`
// Database settings
Database dbutil.Config `yaml:"database"`
// Bot settings
HomeserverWhitelist HomeserverWhitelist `yaml:"homeserver_whitelist"`
StartNewChat StartNewChat `yaml:"start_new_chat"`
CanonicalDMPrefix string `yaml:"canonical_dm_prefix"`
BridgeIfMembersLessThan int `yaml:"bridge_if_members_less_than"`
RenderMarkdown bool `yaml:"render_markdown"`
// Webhook listener settings
ListenPort int `yaml:"listen_port"`
// Logging configuration
Logging zeroconfig.Config `yaml:"logging"`
// Backfill configuration
Backfill BackfillConfiguration `yaml:"backfill"`
}
func (c *Configuration) GetPassword(log *zerolog.Logger) (string, error) {
log.Debug().Str("password_file", c.PasswordFile).Msg("reading password from file")
buf, err := os.ReadFile(c.PasswordFile)
if err != nil {
return "", err
}
return strings.TrimSpace(string(buf)), nil
}
func (c *Configuration) GetChatwootAccessToken(log *zerolog.Logger) (string, error) {
log.Debug().Str("access_token_file", c.ChatwootAccessTokenFile).Msg("reading access token from file")
buf, err := os.ReadFile(c.ChatwootAccessTokenFile)
if err != nil {
return "", err
}
return strings.TrimSpace(string(buf)), nil
}