Render formatting

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2021-12-05 17:55:15 +00:00
parent eaba72fb23
commit ab3fa0ea6c
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -8,6 +8,8 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/prometheus/alertmanager/template" "github.com/prometheus/alertmanager/template"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
) )
@ -32,13 +34,17 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
case "warning": case "warning":
message = fmt.Sprintf("⚠️ %s", rendered.String()) message = fmt.Sprintf("⚠️ %s", rendered.String())
case "notify": case "notify":
message = fmt.Sprintf("@room - %s", rendered.String()) message = fmt.Sprintf("🔥 @room - %s", rendered.String())
} }
} else { } else {
message = fmt.Sprintf("☑️ %s", rendered.String()) message = fmt.Sprintf(" %s", rendered.String())
} }
_, err := matrixClient.SendText(id.RoomID(getRoom(*defaultRoom)), message) _, err := matrixClient.SendMessageEvent(
id.RoomID(getRoom(*defaultRoom)),
event.EventMessage,
format.RenderMarkdown(message, true, true),
)
if err != nil { if err != nil {
fmt.Println("Failed sending to Matrix", err) fmt.Println("Failed sending to Matrix", err)
if httpErr, ok := err.(mautrix.HTTPError); ok { if httpErr, ok := err.(mautrix.HTTPError); ok {