fix: Twilio channel selection when MessagingServiceSid is empty (#5040)
- Fixes channel selection logic in incoming_message_service for Twilio messages ref: #4242
This commit is contained in:
@@ -4,6 +4,8 @@ class Twilio::IncomingMessageService
|
||||
pattr_initialize [:params!]
|
||||
|
||||
def perform
|
||||
return if twilio_channel.blank?
|
||||
|
||||
set_contact
|
||||
set_conversation
|
||||
@message = @conversation.messages.create(
|
||||
@@ -19,14 +21,17 @@ class Twilio::IncomingMessageService
|
||||
|
||||
private
|
||||
|
||||
def twilio_inbox
|
||||
@twilio_inbox ||=
|
||||
::Channel::TwilioSms.find_by(messaging_service_sid: params[:MessagingServiceSid]) ||
|
||||
::Channel::TwilioSms.find_by!(account_sid: params[:AccountSid], phone_number: params[:To])
|
||||
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])
|
||||
end
|
||||
@twilio_channel
|
||||
end
|
||||
|
||||
def inbox
|
||||
@inbox ||= twilio_inbox.inbox
|
||||
@inbox ||= twilio_channel.inbox
|
||||
end
|
||||
|
||||
def account
|
||||
@@ -34,7 +39,7 @@ class Twilio::IncomingMessageService
|
||||
end
|
||||
|
||||
def phone_number
|
||||
twilio_inbox.sms? ? params[:From] : params[:From].gsub('whatsapp:', '')
|
||||
twilio_channel.sms? ? params[:From] : params[:From].gsub('whatsapp:', '')
|
||||
end
|
||||
|
||||
def formatted_phone_number
|
||||
@@ -78,7 +83,7 @@ class Twilio::IncomingMessageService
|
||||
end
|
||||
|
||||
def additional_attributes
|
||||
if twilio_inbox.sms?
|
||||
if twilio_channel.sms?
|
||||
{
|
||||
from_zip_code: params[:FromZip],
|
||||
from_country: params[:FromCountry],
|
||||
|
||||
Reference in New Issue
Block a user