send messages to matrix

This commit is contained in:
Bel LaPointe
2022-01-10 22:18:24 -05:00
parent 1ef59469a0
commit cfbed43632
7 changed files with 102 additions and 3 deletions

41
message/matrix.go Normal file
View File

@@ -0,0 +1,41 @@
package message
import (
"fmt"
"local/truckstop/config"
"github.com/matrix-org/gomatrix"
)
type Matrix struct {
homeserver string
username string
token string
room string
}
func NewMatrix() Matrix {
conf := config.Get().Message.Matrix
return Matrix{
homeserver: conf.Homeserver,
username: conf.Username,
token: conf.Token,
room: conf.Room,
}
}
func (m Matrix) client() (*gomatrix.Client, error) {
return gomatrix.NewClient(m.homeserver, m.username, m.token)
}
func (m Matrix) Send(text string) error {
c, err := m.client()
if err != nil {
return err
}
resp, err := c.SendText(m.room, text)
if err != nil {
return err
}
return fmt.Errorf("%+v", resp)
}