matrix-development-lauge/matrix-bot/matrix-bot.go

36 lines
966 B
Go

package matrixbot
import (
"fmt"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
"roese.dev/matrix-development-lauge/modules/config"
)
func SendMessage(header string, content string, url string) {
cfg := config.Cfg.Bot
client, err := mautrix.NewClient(cfg.HomeserverUrl, "", "")
if err != nil {
panic(err)
}
_, err = client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: cfg.User},
Password: cfg.Password,
StoreCredentials: true,
})
if err != nil {
panic(err)
}
//msg := format.RenderMarkdown(fmt.Sprintf("Thema: Radko-Stöckl-Schule - Aktuelles <h4>%s</h4>%s<br>%s", header, content, url), false, true)
//client.SendMessageEvent(id.RoomID(cfg.RoomId), event.EventMessage, &msg)
client.SendNotice(id.RoomID(cfg.RoomId), fmt.Sprintf("Thema: Radko-Stöckl-Schule - Aktuelles <h4>%s</h4>%s<br>%s", header, content, url))
}