truckstop/message/matrix.go

38 lines
650 B
Go

package message
import (
"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
}
_, err = c.SendText(m.room, text)
return err
}