commit d7cdf1a4ffa35a0f725ef05aba8a4b5b414a9782
Author: Jason Robinson <mail@jasonrobinson.me>
Date: Mon May 17 01:10:13 2021 +0000
diff --git a/bridge/config/config.go b/bridge/config/config.go
index b5e03fc..a6e3c54 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -1206 +1207 @@ type Protocol struct {
MessageQueue int // IRC, size of message queue for flood control
MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping
Muc string // xmpp
+ MxID string // matrix
Name string // all protocols
Nick string // all protocols
NickFormatter string // mattermost, slack
@@ -1427 +1437 @@ type Protocol struct {
ReplaceNicks [][]string // all protocols
RemoteNickFormat string // all protocols
RunCommands []string // IRC
- Server string // IRC,mattermost,XMPP,discord
+ Server string // IRC,mattermost,XMPP,discord,matrix
SessionFile string // msteams,whatsapp
ShowJoinPart bool // all protocols
ShowTopicChange bool // slack
@@ -1577 +1587 @@ type Protocol struct {
Team string // mattermost, keybase
TeamID string // msteams
TenantID string // msteams
- Token string // gitter, slack, discord, api
+ Token string // gitter, slack, discord, api, matrix
Topic string // zulip
URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go
index 69d0264..9516a4f 100644
--- a/bridge/matrix/matrix.go
+++ b/bridge/matrix/matrix.go
@@ -7522 +7533 @@ func New(cfg *bridge.Config) bridge.Bridger {
func (b *Bmatrix) Connect() error {
var err error
b.Log.Infof("Connecting %s", b.GetString("Server"))
- b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
- if err != nil {
- return err
- }
- resp, err := b.mc.Login(&matrix.ReqLogin{
- Type: "m.login.password",
- User: b.GetString("Login"),
- Password: b.GetString("Password"),
- Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
- })
- if err != nil {
- return err
+ if b.GetString("MxID") != "" && b.GetString("Token") != "" {
+ b.mc, err = matrix.NewClient(
+ b.GetString("Server"), b.GetString("MxID"), b.GetString("Token"),
+ )
+ if err != nil {
+ return err
+ }
+ b.UserID = b.GetString("MxID")
+ b.Log.Info("Using existing Matrix credentials")
+ } else {
+ b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
+ if err != nil {
+ return err
+ }
+ resp, err := b.mc.Login(&matrix.ReqLogin{
+ Type: "m.login.password",
+ User: b.GetString("Login"),
+ Password: b.GetString("Password"),
+ Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
+ })
+ if err != nil {
+ return err
+ }
+ b.mc.SetCredentials(resp.UserID, resp.AccessToken)
+ b.UserID = resp.UserID
+ b.Log.Info("Connection succeeded")
}
- b.mc.SetCredentials(resp.UserID, resp.AccessToken)
- b.UserID = resp.UserID
- b.Log.Info("Connection succeeded")
go b.handlematrix()
return nil
}
diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample
index 5c1698a..2819b28 100644
--- a/matterbridge.toml.sample
+++ b/matterbridge.toml.sample
@@ -124512 +124516 @@ ShowTopicChange=false
#REQUIRED
Server="https://matrix.org"
-#login/pass of your bot.
+#Authentication for your bot.
+#You can use either login/password OR mxid/token. The latter will be preferred if found.
#Use a dedicated user for this and not your own!
#Messages sent from this user will not be relayed to avoid loops.
#REQUIRED
Login="yourlogin"
Password="yourpass"
+#OR
+MxID="@yourlogin:domain.tld"
+Token="tokenforthebotuser"
#Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org
#to other bridges, or only send "username".(true only sends username)