fix: Send raw content in webhook payloads instead of channel-rendered markdown (#13896)

Webhook payloads (`message_created`, `message_updated`) started sending
channel-rendered HTML in the `content` field instead of the original raw
message content after PR #12878. This broke downstream agent bots and
integrations that expected plain text or markdown. 
Closes https://linear.app/chatwoot/issue/PLA-109/webhook-payloads-send-channel-rendered-html-instead-of-raw-content

## How to reproduce

1. Connect an agent bot to a WebWidget inbox
2. Send a message with markdown formatting (e.g. `**bold**`) from the
widget
3. Observe the agent bot webhook payload — `content` field contains
`<p><strong>bold</strong></p>` instead of `**bold**`

## What changed

Split `MessageContentPresenter` into two public methods:
- `outgoing_content` — renders markdown for the target channel (used by
channel delivery services)
- `webhook_content` — returns raw content with CSAT survey URL when
applicable, no markdown rendering (used by `webhook_data`)

Updated `Message#webhook_data` to use `webhook_content` instead of
`outgoing_content`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Muhsin Keloth
2026-03-25 16:56:22 +04:00
committed by GitHub
parent 6ff643b045
commit 608be1036b
4 changed files with 52 additions and 15 deletions

View File

@@ -401,12 +401,11 @@ RSpec.describe Message do
expect(message.webhook_data.key?(:attachments)).to be false
end
it 'uses outgoing_content for webhook content' do
message = create(:message, content: 'Test content')
expect(message).to receive(:outgoing_content).and_return('Outgoing test content')
it 'uses raw content without markdown rendering for webhook content' do
message = create(:message, content: 'Test **bold** content')
webhook_data = message.webhook_data
expect(webhook_data[:content]).to eq('Outgoing test content')
expect(webhook_data[:content]).to eq('Test **bold** content')
end
it 'includes CSAT survey link in webhook content for input_csat messages' do
@@ -414,7 +413,6 @@ RSpec.describe Message do
conversation = create(:conversation, inbox: inbox)
message = create(:message, conversation: conversation, content_type: 'input_csat', content: 'Rate your experience')
expect(message.outgoing_content).to include('survey/responses/')
expect(message.webhook_data[:content]).to include('survey/responses/')
end
end