Strip newlines from Slack payload

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2024-07-27 11:09:40 +01:00
parent 801574a245
commit 1d26f341c7
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/slack-go/slack"
@ -13,8 +14,11 @@ import (
)
func HandleSlackPayloadPost(c *fiber.Ctx) error {
body := string(c.Body())
body = strings.ReplaceAll(body, "\n", "\\n")
payload := slack.WebhookMessage{}
if err := c.BodyParser(&payload); err != nil {
if err := json.Unmarshal([]byte(body), &payload); err != nil {
fmt.Println("Failed to parse payload", string(c.Body()), err)
return err
}