From 1d26f341c7d10f9d8bd3c83c4eeacfe6d9940369 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Sat, 27 Jul 2024 11:09:40 +0100 Subject: [PATCH] Strip newlines from Slack payload Signed-off-by: Marcus Noble --- slack.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/slack.go b/slack.go index 80cb31f..a6e1a74 100644 --- a/slack.go +++ b/slack.go @@ -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 }