Add support for general markdown messages

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2023-04-25 20:59:17 +01:00
parent 88cbbd17fc
commit 9bddd75bf1
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
2 changed files with 17 additions and 2 deletions

14
main.go
View File

@ -8,6 +8,8 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/fiber/v2/middleware/logger"
"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"
) )
@ -123,6 +125,18 @@ func HandlePayloadPost(c *fiber.Ctx) error {
} }
return fiber.ErrInternalServerError 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: case PayloadTypeNotice:
_, err := matrixClient.SendNotice(id.RoomID(payload.RoomID), payload.Message) _, err := matrixClient.SendNotice(id.RoomID(payload.RoomID), payload.Message)
if err != nil { if err != nil {

View File

@ -8,6 +8,7 @@ type PayloadType string
const ( const (
PayloadTypeText PayloadType = "text" PayloadTypeText PayloadType = "text"
PayloadTypeMarkdown PayloadType = "markdown"
PayloadTypeNotice PayloadType = "notice" PayloadTypeNotice PayloadType = "notice"
) )