fix: Error shouldn't halt the campaign for entire audience (#11980)

## Summary
- handle Twilio failures per contact when running one-off SMS campaigns
- rescue errors in WhatsApp and generic SMS one-off campaigns so they
continue
- add specs confirming campaigns continue sending when a single contact
fails

fixes:  https://github.com/chatwoot/chatwoot/issues/9000

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Sojan Jose
2025-08-10 23:33:48 -07:00
committed by GitHub
parent 8ea21eeefd
commit 3214d06a83
6 changed files with 70 additions and 8 deletions

View File

@@ -29,5 +29,7 @@ class Sms::OneoffSmsCampaignService
def send_message(to:, content:)
channel.send_text_message(to, content)
rescue StandardError => e
Rails.logger.error("[SMS Campaign #{campaign.id}] Failed to send to #{to}: #{e.message}")
end
end

View File

@@ -23,7 +23,13 @@ class Twilio::OneoffSmsCampaignService
next if contact.phone_number.blank?
content = Liquid::CampaignTemplateService.new(campaign: campaign, contact: contact).call(campaign.message)
channel.send_message(to: contact.phone_number, body: content)
begin
channel.send_message(to: contact.phone_number, body: content)
rescue Twilio::REST::TwilioError, Twilio::REST::RestError => e
Rails.logger.error("[Twilio Campaign #{campaign.id}] Failed to send to #{contact.phone_number}: #{e.message}")
next
end
end
end
end

View File

@@ -89,6 +89,7 @@ class Whatsapp::OneoffCampaignService
rescue StandardError => e
Rails.logger.error "Failed to send WhatsApp template message to #{to}: #{e.message}"
Rails.logger.error "Backtrace: #{e.backtrace.first(5).join('\n')}"
raise e
# continue processing remaining contacts
nil
end
end