Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Twilio Live Call Routing API Region Support #129

Merged
merged 3 commits into from
Jan 27, 2025
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
1 change: 1 addition & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
appraise "rails-7" do
gem "rails", "~> 7.0.0"
gem "concurrent-ruby", "1.3.4"
end

appraise "rails-master" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class LiveCallRouting::Twilio::V3 < Integration
{key: :account_sid, type: :string, default: nil},
{key: :api_key, type: :string, default: nil},
{key: :api_secret, type: :string, default: nil},
{key: :api_region, type: :string, default: "ashburn.us1"},
{key: :force_input, type: :boolean, default: false},
{key: :record, type: :boolean, default: false},
{key: :record_email, type: :string, default: ""},
Expand All @@ -12,6 +13,8 @@ class LiveCallRouting::Twilio::V3 < Integration
]
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"

API_REGIONS = ["ashburn.us1", "dublin.ie1", "sydney.au1"]

has_one_attached :option_connect_now_media
has_one_attached :option_music_media
has_one_attached :option_no_answer_media
Expand All @@ -22,6 +25,7 @@ class LiveCallRouting::Twilio::V3 < Integration
validates :option_account_sid, presence: true
validates :option_api_key, presence: true
validates :option_api_secret, presence: true
validates :option_api_region, inclusion: {in: API_REGIONS}
validates :option_force_input, inclusion: {in: [true, false]}
validates :option_record, inclusion: {in: [true, false]}
validate :validate_record_emails
Expand All @@ -30,6 +34,7 @@ class LiveCallRouting::Twilio::V3 < Integration
self.option_account_sid ||= nil
self.option_api_key ||= nil
self.option_api_secret ||= nil
self.option_api_region ||= "ashburn.us1"
self.option_force_input ||= false
self.option_record ||= false
self.option_record_email ||= ""
Expand Down Expand Up @@ -393,8 +398,12 @@ def _additional_datums
]
end

def _api_region
API_REGIONS.include?(option_api_region) ? option_api_region : "ashburn.us1"
end

def _client
@_client ||= ::Twilio::REST::Client.new(self.option_api_key, self.option_api_secret, self.option_account_sid)
@_client ||= ::Twilio::REST::Client.new(self.option_api_key, self.option_api_secret, self.option_account_sid, _api_region)
end

def _call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
</div>
</div>

<div class="form-group group">
<%= form.label :option_api_region %>
<%= form.select :option_api_region, [["US1 (Ashburn)", "ashburn.us1"], ["IE1 (Dublin)", "dublin.ie1"], ["AU1 (Sydney)", "sydney.au1"]], {}, class:'form-control' %>
<p class="form-hint"><%== t(".option_api_region_hint_html") %></p>
</div>

<div class="form-group group">
<%= form.label :option_welcome_media %>
<%= 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" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="sm:col-span-2">
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_account_sid") %>
</dt>
Expand All @@ -11,6 +11,26 @@
</dd>
</div>

<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_api_region") %>
</dt>
<dd class="mt-1 text-sm text-gray-900">
<div class="flex items-center gap-2">
<p class="text-sm truncate">
<%=
case integration.option_api_region
when "dublin.ie1" then "IE1 (Dublin)"
when "sydney.au1" then "AU1 (Sydeny)"
else
"US1 (Ashburn)"
end
%>
</p>
</div>
</dd>
</div>

<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_api_key") %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ en:
option_account_sid_hint_html: "Twilio Account SID"
option_api_key_hint_html: "Twilio API Key"
option_api_secret_hint_html: "Twilio API Secret"
option_api_region_hint_html: "Twilio API Region (must match API key/secret and number configuration regions)"
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.\")"
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>)"
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>)"
Expand Down Expand Up @@ -209,6 +210,7 @@ en:
option_account_sid: "Twilio Account SID"
option_api_key: "Twilio API Key"
option_api_secret: "Twilio API Secret"
option_api_region: "Twilio API Region"
option_welcome_media: "Welcome Recording"
option_please_wait_media: "Before Wait Music Recording"
option_music_media: "Wait Music Recording"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem "twilio-ruby", "~> 5.64"
gem "ulid", "~> 1.3"
gem "validate_url", "~> 1.0"
gem "rails", "~> 7.0.0"
gem "concurrent-ruby", "1.3.4"

group :development, :test do
gem "dotenv-rails", "~> 2.7"
Expand Down
Loading