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:
@@ -1,22 +1,28 @@
|
||||
class MessageContentPresenter < SimpleDelegator
|
||||
def outgoing_content
|
||||
content_to_send = if should_append_survey_link?
|
||||
survey_link = survey_url(conversation.uuid)
|
||||
custom_message = inbox.csat_config&.dig('message')
|
||||
custom_message.present? ? "#{custom_message} #{survey_link}" : I18n.t('conversations.survey.response', link: survey_link)
|
||||
else
|
||||
content
|
||||
end
|
||||
|
||||
Messages::MarkdownRendererService.new(
|
||||
content_to_send,
|
||||
content_with_survey_link,
|
||||
conversation.inbox.channel_type,
|
||||
conversation.inbox.channel
|
||||
).render
|
||||
end
|
||||
|
||||
def webhook_content
|
||||
content_with_survey_link
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def content_with_survey_link
|
||||
if should_append_survey_link?
|
||||
survey_link = survey_url(conversation.uuid)
|
||||
custom_message = inbox.csat_config&.dig('message')
|
||||
custom_message.present? ? "#{custom_message} #{survey_link}" : I18n.t('conversations.survey.response', link: survey_link)
|
||||
else
|
||||
content
|
||||
end
|
||||
end
|
||||
|
||||
def should_append_survey_link?
|
||||
input_csat? && !inbox.web_widget?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user