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"
|
||||||
"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 {
|
||||||
|
@ -7,8 +7,9 @@ import (
|
|||||||
type PayloadType string
|
type PayloadType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PayloadTypeText PayloadType = "text"
|
PayloadTypeText PayloadType = "text"
|
||||||
PayloadTypeNotice PayloadType = "notice"
|
PayloadTypeMarkdown PayloadType = "markdown"
|
||||||
|
PayloadTypeNotice PayloadType = "notice"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Payload struct {
|
type Payload struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user