-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix.go
38 lines (33 loc) · 653 Bytes
/
matrix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
"os"
)
type MatrixMessage struct {
Message string `json:"message"`
Body string `json:"body"`
}
func SendMatrixMessage(content string) error {
messageBytes, marshalErr := json.Marshal(&MatrixMessage{
Message: "m.text",
Body: content,
})
if marshalErr != nil {
log.Println("Failed to send matrix message", marshalErr)
return marshalErr
}
MATRIX_API := os.Getenv("MATRIX_API")
if MATRIX_API == "" {
log.Println("MATRIX_API envitonment not set")
return nil
}
http.Post(
MATRIX_API,
"application/json",
bytes.NewReader(messageBytes),
)
return nil
}