send messages to matrix
This commit is contained in:
41
message/matrix.go
Normal file
41
message/matrix.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user