iachat/lib/integrations
Sivin Varghese 72509f9e38
chore: Improve translation service with HTML and plain text support (#11305)
# Pull Request Template

## Description

This PR changes to translation to properly handle different content
types during translation.

### Changes

1. **Email translation with HTML support**
   - Properly detects and preserves HTML content from emails
   - Sets `mime_type` to 'text/html' when HTML content is present

2. **Email translation with plain text support**
   - Falls back to email text content when HTML is not available
- Sets `mime_type` to 'text/plain' when HTML is not available and
content type includes 'text/plain'

3. **Plain message with plain text support (Non email channels)**
   - Sets `mime_type` to 'text/plain' for non-email channels
- Fixes an issue where Markdown formatting was being lost due to
incorrect `mime_type`
   
**Note**: Translation for very long emails is not currently supported.

Fixes
https://linear.app/chatwoot/issue/CW-4244/translate-button-doesnt-work-in-email-channels

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

**Loom video**

https://www.loom.com/share/8f8428ed2cfe415ea5cb6c547c070f00?sid=eab9fa11-05f8-4838-9181-334bee1023c4


## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2025-04-16 17:59:06 +05:30
..
captain feat: Generate SSO URL in Chatwoot, move Captain to primary tab (#9871) 2024-08-01 19:22:34 -07:00
csml chore: Use "create!" and "save!" bang methods when not checking the result (#5358) 2022-09-13 17:40:06 +05:30
dialogflow feat: Integration with Captain (alpha) (#9834) 2024-07-25 14:24:04 -07:00
dyte feat: Upgrade Dyte apis to v2 (#10706) 2025-02-19 14:47:48 -08:00
facebook feat: Facebook delivery reports (#8136) 2023-11-20 12:22:45 +05:30
google_translate chore: Improve translation service with HTML and plain text support (#11305) 2025-04-16 17:59:06 +05:30
linear feat: Linear OAuth 2.0 (#10851) 2025-02-27 18:15:53 +05:30
openai feat: Improve reply suggestions using help center articles (#9026) 2024-03-03 20:25:19 -08:00
slack chore: Rescue slack link unfurling errors. (#11033) 2025-03-06 15:57:16 -08:00
bot_processor_service.rb fix: hook exception for empty hook (#6646) 2023-03-10 16:40:15 +05:30
openai_base_service.rb chore: Update GPT Model (#10111) 2024-09-16 09:41:20 +05:30