Skip to content

Commit bf7b24b

Browse files
authored
Feature Twilio Live Call Routing API Region Support (#129)
1 parent 18c1a39 commit bf7b24b

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

Appraisals

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
appraise "rails-7" do
22
gem "rails", "~> 7.0.0"
3+
gem "concurrent-ruby", "1.3.4"
34
end
45

56
appraise "rails-master" do

app/models/pager_tree/integrations/live_call_routing/twilio/v3.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class LiveCallRouting::Twilio::V3 < Integration
44
{key: :account_sid, type: :string, default: nil},
55
{key: :api_key, type: :string, default: nil},
66
{key: :api_secret, type: :string, default: nil},
7+
{key: :api_region, type: :string, default: "ashburn.us1"},
78
{key: :force_input, type: :boolean, default: false},
89
{key: :record, type: :boolean, default: false},
910
{key: :record_email, type: :string, default: ""},
@@ -12,6 +13,8 @@ class LiveCallRouting::Twilio::V3 < Integration
1213
]
1314
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
1415

16+
API_REGIONS = ["ashburn.us1", "dublin.ie1", "sydney.au1"]
17+
1518
has_one_attached :option_connect_now_media
1619
has_one_attached :option_music_media
1720
has_one_attached :option_no_answer_media
@@ -22,6 +25,7 @@ class LiveCallRouting::Twilio::V3 < Integration
2225
validates :option_account_sid, presence: true
2326
validates :option_api_key, presence: true
2427
validates :option_api_secret, presence: true
28+
validates :option_api_region, inclusion: {in: API_REGIONS}
2529
validates :option_force_input, inclusion: {in: [true, false]}
2630
validates :option_record, inclusion: {in: [true, false]}
2731
validate :validate_record_emails
@@ -30,6 +34,7 @@ class LiveCallRouting::Twilio::V3 < Integration
3034
self.option_account_sid ||= nil
3135
self.option_api_key ||= nil
3236
self.option_api_secret ||= nil
37+
self.option_api_region ||= "ashburn.us1"
3338
self.option_force_input ||= false
3439
self.option_record ||= false
3540
self.option_record_email ||= ""
@@ -393,8 +398,12 @@ def _additional_datums
393398
]
394399
end
395400

401+
def _api_region
402+
API_REGIONS.include?(option_api_region) ? option_api_region : "ashburn.us1"
403+
end
404+
396405
def _client
397-
@_client ||= ::Twilio::REST::Client.new(self.option_api_key, self.option_api_secret, self.option_account_sid)
406+
@_client ||= ::Twilio::REST::Client.new(self.option_api_key, self.option_api_secret, self.option_account_sid, _api_region)
398407
end
399408

400409
def _call

app/views/pager_tree/integrations/live_call_routing/twilio/v3/_form_options.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
</div>
2424
</div>
2525

26+
<div class="form-group group">
27+
<%= form.label :option_api_region %>
28+
<%= form.select :option_api_region, [["US1 (Ashburn)", "ashburn.us1"], ["IE1 (Dublin)", "dublin.ie1"], ["AU1 (Sydney)", "sydney.au1"]], {}, class:'form-control' %>
29+
<p class="form-hint"><%== t(".option_api_region_hint_html") %></p>
30+
</div>
31+
2632
<div class="form-group group">
2733
<%= form.label :option_welcome_media %>
2834
<%= form.file_field :option_welcome_media, accept: "audio/*", class: "file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-gray-50 file:text-gray-700 hover:file:bg-gray-100" %>

app/views/pager_tree/integrations/live_call_routing/twilio/v3/_show_options.html.erb

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="sm:col-span-2">
1+
<div class="sm:col-span-1">
22
<dt class="text-sm font-medium text-gray-500">
33
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_account_sid") %>
44
</dt>
@@ -11,6 +11,26 @@
1111
</dd>
1212
</div>
1313

14+
<div class="sm:col-span-1">
15+
<dt class="text-sm font-medium text-gray-500">
16+
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_api_region") %>
17+
</dt>
18+
<dd class="mt-1 text-sm text-gray-900">
19+
<div class="flex items-center gap-2">
20+
<p class="text-sm truncate">
21+
<%=
22+
case integration.option_api_region
23+
when "dublin.ie1" then "IE1 (Dublin)"
24+
when "sydney.au1" then "AU1 (Sydeny)"
25+
else
26+
"US1 (Ashburn)"
27+
end
28+
%>
29+
</p>
30+
</div>
31+
</dd>
32+
</div>
33+
1434
<div class="sm:col-span-1">
1535
<dt class="text-sm font-medium text-gray-500">
1636
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_api_key") %>

config/locales/en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ en:
7878
option_account_sid_hint_html: "Twilio Account SID"
7979
option_api_key_hint_html: "Twilio API Key"
8080
option_api_secret_hint_html: "Twilio API Secret"
81+
option_api_region_hint_html: "Twilio API Region (must match API key/secret and number configuration regions)"
8182
option_welcome_media_hint_html: "A <a href='https://www.twilio.com/docs/voice/twiml/play#supported-audio-file-types' target='_blank'>.mp3</a> recording that will be played first to caller (ex: \"Hello, you have reached the Devop's on-call support line.\")"
8283
option_please_wait_media_hint_html: "A <a href='https://www.twilio.com/docs/voice/twiml/play#supported-audio-file-types' target='_blank'>.mp3</a> recording to be played before wait music music (default: <a href='https://app.pagertree.com/audios/please-wait.mp3' target='_blank'>Please wait while you are being connected</a>)"
8384
option_music_media_hint_html: "A <a href='https://www.twilio.com/docs/voice/twiml/play#supported-audio-file-types' target='_blank'>.mp3</a> recording or wait music to be played while the caller waits for someone to acknowledge the alert (default: <a href='http://com.twilio.sounds.music.s3.amazonaws.com/oldDog_-_endless_goodbye_%28instr.%29.mp3' target='_blank'>Endless Goodbye</a>)"
@@ -209,6 +210,7 @@ en:
209210
option_account_sid: "Twilio Account SID"
210211
option_api_key: "Twilio API Key"
211212
option_api_secret: "Twilio API Secret"
213+
option_api_region: "Twilio API Region"
212214
option_welcome_media: "Welcome Recording"
213215
option_please_wait_media: "Before Wait Music Recording"
214216
option_music_media: "Wait Music Recording"

gemfiles/rails_7.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gem "twilio-ruby", "~> 5.64"
1313
gem "ulid", "~> 1.3"
1414
gem "validate_url", "~> 1.0"
1515
gem "rails", "~> 7.0.0"
16+
gem "concurrent-ruby", "1.3.4"
1617

1718
group :development, :test do
1819
gem "dotenv-rails", "~> 2.7"

0 commit comments

Comments
 (0)