feat: Add support for HTML emails in outgoing messages (#12662)
This PR adds sending custom HTML content in outgoing email messages
through Chatwoot's Email channels, while maintaining backward
compatibility with existing markdown rendering.
### API Usage
**Endpoint:** `POST
/api/v1/accounts/{account_id}/conversations/{conversation_id}/messages`
```json
{
"content": "Fallback text content",
"email_html_content": "<div><h1>Welcome!</h1><p>This is <strong>custom HTML</strong></p></div>"
}
```
---------
Co-authored-by: Muhsin <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -179,6 +179,63 @@ describe Messages::MessageBuilder do
|
||||
expect(message.content_attributes[:cc_emails]).to eq ['test1@test.com', 'test2@test.com', 'test3@test.com']
|
||||
expect(message.content_attributes[:bcc_emails]).to eq ['test1@test.com', 'test2@test.com', 'test3@test.com']
|
||||
end
|
||||
|
||||
context 'when custom email content is provided' do
|
||||
before do
|
||||
account.enable_features('quoted_email_reply')
|
||||
end
|
||||
|
||||
it 'creates message with custom HTML email content' do
|
||||
params = ActionController::Parameters.new({
|
||||
content: 'Regular message content',
|
||||
email_html_content: '<p>Custom <strong>HTML</strong> content</p>'
|
||||
})
|
||||
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
|
||||
expect(message.content_attributes.dig('email', 'html_content', 'full')).to eq '<p>Custom <strong>HTML</strong> content</p>'
|
||||
expect(message.content_attributes.dig('email', 'html_content', 'reply')).to eq '<p>Custom <strong>HTML</strong> content</p>'
|
||||
expect(message.content_attributes.dig('email', 'text_content', 'full')).to eq 'Regular message content'
|
||||
expect(message.content_attributes.dig('email', 'text_content', 'reply')).to eq 'Regular message content'
|
||||
end
|
||||
|
||||
it 'does not process custom email content when quoted_email_reply feature is disabled' do
|
||||
account.disable_features('quoted_email_reply')
|
||||
params = ActionController::Parameters.new({
|
||||
content: 'Regular message content',
|
||||
email_html_content: '<p>Custom HTML content</p>'
|
||||
})
|
||||
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
|
||||
expect(message.content_attributes.dig('email', 'html_content')).to be_nil
|
||||
expect(message.content_attributes.dig('email', 'text_content')).to be_nil
|
||||
end
|
||||
|
||||
it 'does not process custom email content for private messages' do
|
||||
params = ActionController::Parameters.new({
|
||||
content: 'Regular message content',
|
||||
email_html_content: '<p>Custom HTML content</p>',
|
||||
private: true
|
||||
})
|
||||
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
|
||||
expect(message.content_attributes.dig('email', 'html_content')).to be_nil
|
||||
expect(message.content_attributes.dig('email', 'text_content')).to be_nil
|
||||
end
|
||||
|
||||
it 'falls back to default behavior when no custom email content is provided' do
|
||||
params = ActionController::Parameters.new({
|
||||
content: 'Regular **markdown** content'
|
||||
})
|
||||
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
|
||||
expect(message.content_attributes.dig('email', 'html_content', 'full')).to include('<strong>markdown</strong>')
|
||||
expect(message.content_attributes.dig('email', 'text_content', 'full')).to eq 'Regular **markdown** content'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user