matrix-pretix/internal/matrix/client.go

30 lines
599 B
Go
Raw Normal View History

2022-07-22 19:52:41 +02:00
package matrix
import (
"git.luj0ga.de/franconian/matrix-pretix/internal/config"
2022-07-22 19:52:41 +02:00
"maunium.net/go/mautrix"
)
func NewClient(config *config.MatrixConfig) (*mautrix.Client, error) {
client, err := mautrix.NewClient(config.HomeserverURL, "", "")
if err != nil {
return nil, err
}
2022-07-23 00:36:28 +02:00
_, 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
2022-07-22 19:52:41 +02:00
}