From 9bddd75bf19a7b33427f7a1bff4533f926d02451 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Tue, 25 Apr 2023 20:59:17 +0100 Subject: [PATCH] Add support for general markdown messages Signed-off-by: Marcus Noble --- main.go | 14 ++++++++++++++ payload.go | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 84e86a3..870386b 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/logger" "maunium.net/go/mautrix" + "maunium.net/go/mautrix/event" + "maunium.net/go/mautrix/format" "maunium.net/go/mautrix/id" ) @@ -123,6 +125,18 @@ func HandlePayloadPost(c *fiber.Ctx) error { } return fiber.ErrInternalServerError } + case PayloadTypeMarkdown: + _, err := matrixClient.SendMessageEvent( + id.RoomID(payload.RoomID), + event.EventMessage, + format.RenderMarkdown(payload.Message, true, true), + ) + if err != nil { + if httpErr, ok := err.(mautrix.HTTPError); ok { + return c.Status(httpErr.Response.StatusCode).SendString(httpErr.RespError.Err) + } + return fiber.ErrInternalServerError + } case PayloadTypeNotice: _, err := matrixClient.SendNotice(id.RoomID(payload.RoomID), payload.Message) if err != nil { diff --git a/payload.go b/payload.go index 1ad9790..69765ad 100644 --- a/payload.go +++ b/payload.go @@ -7,8 +7,9 @@ import ( type PayloadType string const ( - PayloadTypeText PayloadType = "text" - PayloadTypeNotice PayloadType = "notice" + PayloadTypeText PayloadType = "text" + PayloadTypeMarkdown PayloadType = "markdown" + PayloadTypeNotice PayloadType = "notice" ) type Payload struct {