Add support for general markdown messages
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
parent
88cbbd17fc
commit
9bddd75bf1
14
main.go
14
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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user