diff --git a/app/services/twilio/delivery_status_service.rb b/app/services/twilio/delivery_status_service.rb index bf8422fcd..bed390aa5 100644 --- a/app/services/twilio/delivery_status_service.rb +++ b/app/services/twilio/delivery_status_service.rb @@ -47,8 +47,10 @@ class Twilio::DeliveryStatusService @twilio_channel ||= if params[:MessagingServiceSid].present? ::Channel::TwilioSms.find_by(messaging_service_sid: params[:MessagingServiceSid]) elsif params[:AccountSid].present? && params[:From].present? - ::Channel::TwilioSms.find_by!(account_sid: params[:AccountSid], phone_number: params[:From]) + ::Channel::TwilioSms.find_by(account_sid: params[:AccountSid], phone_number: params[:From]) end + log_channel_not_found if @twilio_channel.blank? + @twilio_channel end def message @@ -56,4 +58,14 @@ class Twilio::DeliveryStatusService @message ||= twilio_channel.inbox.messages.find_by(source_id: params[:MessageSid]) end + + def log_channel_not_found + Rails.logger.warn( + '[TWILIO] Delivery status channel lookup failed ' \ + "account_sid=#{params[:AccountSid]} " \ + "from=#{params[:From]} " \ + "messaging_service_sid=#{params[:MessagingServiceSid]} " \ + "message_sid=#{params[:MessageSid]}" + ) + end end diff --git a/app/services/twilio/incoming_message_service.rb b/app/services/twilio/incoming_message_service.rb index 5d695ebb2..d67b6d515 100644 --- a/app/services/twilio/incoming_message_service.rb +++ b/app/services/twilio/incoming_message_service.rb @@ -26,12 +26,23 @@ class Twilio::IncomingMessageService def twilio_channel @twilio_channel ||= ::Channel::TwilioSms.find_by(messaging_service_sid: params[:MessagingServiceSid]) if params[:MessagingServiceSid].present? if params[:AccountSid].present? && params[:To].present? - @twilio_channel ||= ::Channel::TwilioSms.find_by!(account_sid: params[:AccountSid], - phone_number: params[:To]) + @twilio_channel ||= ::Channel::TwilioSms.find_by(account_sid: params[:AccountSid], + phone_number: params[:To]) end + log_channel_not_found if @twilio_channel.blank? @twilio_channel end + def log_channel_not_found + Rails.logger.warn( + '[TWILIO] Incoming message channel lookup failed ' \ + "account_sid=#{params[:AccountSid]} " \ + "to=#{params[:To]} " \ + "messaging_service_sid=#{params[:MessagingServiceSid]} " \ + "sms_sid=#{params[:SmsSid]}" + ) + end + def inbox @inbox ||= twilio_channel.inbox end