2022-07-22 19:52:41 +02:00
|
|
|
package matrix
|
|
|
|
|
|
|
|
import (
|
2022-07-23 00:33:05 +02:00
|
|
|
"git.luj0ga.de/franconian/matrix-pretix/internal/config"
|
|
|
|
|
2022-07-22 19:52:41 +02:00
|
|
|
"maunium.net/go/mautrix"
|
|
|
|
)
|
|
|
|
|
2022-07-23 00:33:05 +02:00
|
|
|
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{
|
2022-07-23 00:33:05 +02:00
|
|
|
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
|
|
|
}
|