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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user