Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/telephony/pinpoint/sms_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def send(message:, to:, country_code:, otp: nil)
end

response = nil
sender_id = Telephony.config.country_sender_ids[country_code.to_s]
Telephony.config.pinpoint.sms_configs.each do |sms_config|
start = Time.zone.now
client = build_client(sms_config)
Expand All @@ -38,8 +39,8 @@ def send(message:, to:, country_code:, otp: nil)
sms_message: {
body: message,
message_type: 'TRANSACTIONAL',
origination_number: origination_number(country_code, sms_config),
sender_id: Telephony.config.country_sender_ids[country_code.to_s],
origination_number: origination_number(country_code, sms_config, sender_id),
sender_id: sender_id,
},
},
},
Expand Down Expand Up @@ -134,7 +135,11 @@ def build_client(sms_config)
)
end

def origination_number(country_code, sms_config)
# To ensure Sender ID is used where needed, the origination number must not be
# specified.
def origination_number(country_code, sms_config, sender_id)
return nil if sender_id

if sms_config.country_code_longcode_pool&.dig(country_code).present?
sms_config.country_code_longcode_pool[country_code].sample
else
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/telephony/pinpoint/sms_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def ==(other)
context 'in a country with sender_id' do
let(:country_code) { 'PH' }

it 'sends a message with a shortcode and sender_id' do
it 'sends a message with a sender_id and no origination number' do
mock_build_client
response = subject.send(
message: 'This is a test!',
Expand All @@ -192,7 +192,7 @@ def ==(other)
sms_message: {
body: 'This is a test!',
message_type: 'TRANSACTIONAL',
origination_number: '123456',
origination_number: nil,
sender_id: 'sender2',
},
},
Expand Down