matrix-pretix/internal/matrix/client.go

30 lines
600 B
Go

package matrix
import (
"git.luj0ga.de/franconian/matrix-pretix/internal/config"
"maunium.net/go/mautrix"
)
func NewClient(config *config.MatrixConfig) (*mautrix.Client, error) {
client, err := mautrix.NewClient(config.HomeserverURL, "", "")
if err != nil {
return nil, err
}
_, err := client.Login(&mautrix.ReqLogin{
Type: mautrix.AuthTypePassword,
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierTypeUser,
User: config.UserIdentifier,
},
Password: config.Password,
StoreCredentials: true,
})
if err != nil {
return nil, err
}
return client, nil
}