diff --git a/main.go b/main.go index a3c9af0..ab64cc6 100644 --- a/main.go +++ b/main.go @@ -26,8 +26,18 @@ type Configuration struct { HTTPToken string } -func generateMatrixMessageBody(alert template.Alert) string { - return fmt.Sprintf("**%v** %v.", alert.Status, alert.Annotations["summary"]) +func getMatrixMessageFor(alert template.Alert) gomatrix.HTMLMessage { + var prefix string + switch alert.Status { + case "firing": + prefix = "FIRING " + case "resolved": + prefix = "RESOLVED " + default: + prefix = fmt.Sprintf("%v ", alert.Status) + } + + return gomatrix.GetHTMLMessage("m.text", prefix + alert.Annotations["summary"]) } func getMatrixClient(homeserver string, user string, token string, targetRoomID string) *gomatrix.Client { @@ -78,9 +88,9 @@ func handleIncomingHooks( w http.ResponseWriter, r *http.Request, logger.Printf("Received valid hook from %v", r.RemoteAddr) for _, alert := range payload.Alerts { - body := generateMatrixMessageBody(alert) - logger.Printf("> %v", body) - _, err := matrixClient.SendText(targetRoomID, body) + msg := getMatrixMessageFor(alert) + logger.Printf("> %v", msg.Body) + _, err := matrixClient.SendMessageEvent(targetRoomID, "m.room.message", msg) if err != nil { logger.Printf(">> Could not forward to Matrix: %v", err) }