feat: Support Twilio Messaging Services (#4242)

This allows sending and receiving from multiple phone numbers using Twilio messaging services

Fixes: #4204
This commit is contained in:
Jordan Brough
2022-07-08 06:50:07 -06:00
committed by GitHub
parent fdf449dc87
commit 49d08a6773
22 changed files with 379 additions and 105 deletions

View File

@@ -4,6 +4,28 @@ class Twilio::WebhookSetupService
pattr_initialize [:inbox!]
def perform
if channel.messaging_service_sid?
update_messaging_service
else
update_phone_number
end
rescue Twilio::REST::TwilioError => e
Rails.logger.error "TWILIO_FAILURE: #{e.message}"
end
private
def update_messaging_service
twilio_client
.messaging.services(channel.messaging_service_sid)
.update(
inbound_method: 'POST',
inbound_request_url: twilio_callback_index_url,
use_inbound_webhook_on_number: false
)
end
def update_phone_number
if phone_numbers.empty?
Rails.logger.warn "TWILIO_PHONE_NUMBER_NOT_FOUND: #{channel.phone_number}"
else
@@ -11,12 +33,8 @@ class Twilio::WebhookSetupService
.incoming_phone_numbers(phonenumber_sid)
.update(sms_method: 'POST', sms_url: twilio_callback_index_url)
end
rescue Twilio::REST::TwilioError => e
Rails.logger.error "TWILIO_FAILURE: #{e.message}"
end
private
def phonenumber_sid
phone_numbers.first.sid
end