iachat/app/controllers/api/v1/widget
Vishnu Narayanan c884cdefde
feat: add per-account daily rate limit for outbound emails (#13411)
Introduce a daily cap on non-channel outbound emails to prevent abuse.

Fixes https://linear.app/chatwoot/issue/CW-6418/ses-incident-jan-28

## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality not to work as expected)

## Summary
- Adds a Redis-based daily counter to rate limit outbound emails per
account, preventing email abuse
- Covers continuity emails (WebWidget/API), conversation transcripts,
and agent notifications
  - Email channel replies are excluded (paid feature, not abusable)
- Adds account suspension check in `ConversationReplyMailer` to block
already-queued emails for suspended accounts

  ## Limit Resolution Hierarchy
1. Per-account override (`account.limits['emails']`) — SuperAdmin
configurable
2. Enterprise plan-based (`ACCOUNT_EMAILS_PLAN_LIMITS`
InstallationConfig)
3. Global default (`ACCOUNT_EMAILS_LIMIT` InstallationConfig, default:
100)
  4. Fallback (`ChatwootApp.max_limit` — effectively unlimited)

  ## Enforcement Points
  | Path | Where | Behavior |
  |------|-------|----------|
| WebWidget/API continuity |
`SendEmailNotificationService#should_send_email_notification?` |
Silently skipped |
| Widget transcript | `Widget::ConversationsController#transcript` |
Returns 429 |
| API transcript | `ConversationsController#transcript` | Returns 429 |
| Agent notifications | `Notification::EmailNotificationService#perform`
| Silently skipped |
  | Email channel replies | Not rate limited | Paid feature |
| Suspended accounts | `ConversationReplyMailer` | Blocked at mailer
level |
2026-02-03 02:06:51 +05:30
..
integrations feat: Add the support for video calls with Dyte in the live-chat widget (#6208) 2023-01-09 11:52:31 -08:00
base_controller.rb feat: show ReplyTo in widget UI (#8094) 2023-10-27 13:35:02 +05:30
campaigns_controller.rb fix: Show campaigns only if the feature is enabled (#11420) 2025-05-05 19:41:28 -07:00
configs_controller.rb feat: allow configuring attachment upload limit (#12835) 2025-11-17 14:03:08 -08:00
contacts_controller.rb chore: Fix contact model silently discarding invalid attributes (#4994) 2022-07-08 13:58:09 +05:30
conversations_controller.rb feat: add per-account daily rate limit for outbound emails (#13411) 2026-02-03 02:06:51 +05:30
direct_uploads_controller.rb Feat: authenticate direct upload (#4160) 2022-03-16 13:54:18 +05:30
events_controller.rb feat: Builder for creating Campaign conversations (#2192) 2021-05-03 20:23:09 +05:30
inbox_members_controller.rb fix: Improve performance of most hit APIs in widget (#11089) 2025-03-14 17:37:36 -07:00
labels_controller.rb chore: Prevent i18n config bleeding across requests (#1214) 2020-10-05 17:55:46 +05:30
messages_controller.rb feat: show ReplyTo in widget UI (#8094) 2023-10-27 13:35:02 +05:30