From 753e7c44298c3020031aa814f3c177daf1d5915d Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Mon, 11 Jul 2022 12:58:24 -0500 Subject: [PATCH] Do not specify origination number when sending SMS with Sender ID (#6572) changelog: Internal, Telephony, Do not specify origination number when sending SMS with Sender ID --- lib/telephony/pinpoint/sms_sender.rb | 11 ++++++++--- spec/lib/telephony/pinpoint/sms_sender_spec.rb | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/telephony/pinpoint/sms_sender.rb b/lib/telephony/pinpoint/sms_sender.rb index 506e2c31a32..2261739d9d8 100644 --- a/lib/telephony/pinpoint/sms_sender.rb +++ b/lib/telephony/pinpoint/sms_sender.rb @@ -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) @@ -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, }, }, }, @@ -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 diff --git a/spec/lib/telephony/pinpoint/sms_sender_spec.rb b/spec/lib/telephony/pinpoint/sms_sender_spec.rb index b36c4efa035..edfeb2a9886 100644 --- a/spec/lib/telephony/pinpoint/sms_sender_spec.rb +++ b/spec/lib/telephony/pinpoint/sms_sender_spec.rb @@ -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!', @@ -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', }, },