fix: strip markdown hard-break backslashes from webhook payloads (#13950)

This commit is contained in:
Sivin Varghese
2026-04-16 13:19:35 +05:30
committed by GitHub
parent b5264a2560
commit 48533e2a5d
7 changed files with 73 additions and 2 deletions

View File

@@ -10,6 +10,6 @@ module PushDataHelper
end
def webhook_data
Conversations::EventDataPresenter.new(self).push_data
Conversations::EventDataPresenter.new(self).webhook_data
end
end

View File

@@ -170,6 +170,13 @@ class Message < ApplicationRecord
data
end
def webhook_push_event_data
push_event_data.merge(
content: Messages::WebhookContentNormalizer.normalize(content),
processed_message_content: Messages::WebhookContentNormalizer.normalize(processed_message_content)
)
end
def webhook_data
data = {
account: account.webhook_data,

View File

@@ -21,12 +21,21 @@ class Conversations::EventDataPresenter < SimpleDelegator
}
end
# Like #push_data but with message text normalized for external integrations (webhooks).
def webhook_data
push_data.merge(messages: webhook_push_messages)
end
private
def push_messages
[messages.where(account_id: account_id).chat.last&.push_event_data].compact
end
def webhook_push_messages
[messages.where(account_id: account_id).chat.last&.webhook_push_event_data].compact
end
def push_meta
{
sender: contact.push_event_data,

View File

@@ -8,7 +8,7 @@ class MessageContentPresenter < SimpleDelegator
end
def webhook_content
content_with_survey_link
Messages::WebhookContentNormalizer.normalize(content_with_survey_link)
end
private

View File

@@ -0,0 +1,10 @@
# Strips CommonMark hard line breaks from stored markdown source (backslash before newline).
# ProseMirror / the dashboard editor emits this form so soft breaks survive as markdown;
# webhook consumers expect plain newlines without a visible backslash (e.g. WhatsApp gateways).
class Messages::WebhookContentNormalizer
def self.normalize(text)
return text if text.blank?
text.gsub(/\\\r?\n/, "\n")
end
end