Skip to content

Commit 3366d6c

Browse files
authored
Add banned phones functionality (#126)
1 parent d4dad5e commit 3366d6c

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

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

+47-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class LiveCallRouting::Twilio::V3 < Integration
77
{key: :force_input, type: :boolean, default: false},
88
{key: :record, type: :boolean, default: false},
99
{key: :record_email, type: :string, default: ""},
10+
{key: :banned_phone, type: :string, default: ""},
1011
{key: :dial_pause, type: :integer}
1112
]
1213
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
@@ -32,6 +33,7 @@ class LiveCallRouting::Twilio::V3 < Integration
3233
self.option_force_input ||= false
3334
self.option_record ||= false
3435
self.option_record_email ||= ""
36+
self.option_banned_phone ||= ""
3537
end
3638

3739
SPEAK_OPTIONS = {
@@ -67,6 +69,14 @@ def option_record_emails
6769
self.option_record_email.split(",")
6870
end
6971

72+
def option_banned_phones=(x)
73+
self.option_banned_phone = Array(x).join(",")
74+
end
75+
76+
def option_banned_phones
77+
self.option_banned_phone.split(",")
78+
end
79+
7080
def option_record_emails_list=(x)
7181
# what comes in as json, via tagify
7282
uniq_array = []
@@ -83,6 +93,22 @@ def option_record_emails_list
8393
option_record_emails
8494
end
8595

96+
def option_banned_phones_list=(x)
97+
# what comes in as json, via tagify
98+
uniq_array = []
99+
begin
100+
uniq_array = JSON.parse(x).map { |y| y["value"] }.uniq
101+
rescue JSON::ParserError => exception
102+
Rails.logger.debug(exception)
103+
end
104+
105+
self.option_banned_phones = uniq_array
106+
end
107+
108+
def option_banned_phones_list
109+
option_banned_phones
110+
end
111+
86112
def validate_record_emails
87113
errors.add(:record_emails, "must be a valid email") if option_record_emails.any? { |x| !(x.match(URI::MailTo::EMAIL_REGEXP) || ["team", "team-admin", "on-call"].include?(x)) }
88114
end
@@ -111,8 +137,20 @@ def adapter_will_route_alert?
111137
true
112138
end
113139

140+
def is_banned?
141+
from_number = adapter_incoming_request_params.dig("From")
142+
return false unless from_number.present?
143+
option_banned_phones.any? { |x| from_number.include?(x) }
144+
rescue
145+
false
146+
end
147+
114148
def adapter_action
115-
:create
149+
if is_banned?
150+
:other
151+
else
152+
:create
153+
end
116154
end
117155

118156
def adapter_thirdparty_id
@@ -131,6 +169,14 @@ def adapter_process_create
131169
end
132170

133171
def adapter_response_incoming
172+
if is_banned?
173+
_twiml.reject
174+
175+
adapter_source_log&.sublog("Caller #{adapter_incoming_request_params.dig("From")} on blocked list. Rejected call.")
176+
adapter_source_log&.save
177+
178+
return adapter_controller&.render(xml: _twiml.to_xml)
179+
end
134180
# if this was attached to a router
135181
if !adapter_alert.meta["live_call_router_team_prefix_ids"].present? && routers.size > 0 && account.subscription_feature_routers?
136182
adapter_alert.logs.create!(message: "Routed to router. Attempting to get a list of teams...")

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

+6
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@
7777
<p class="form-hint"><%== t(".option_record_emails_list_hint_html") %></p>
7878
</div>
7979

80+
<div class="form-group group" data-controller="tagify">
81+
<%= form.label :option_banned_phones_list %>
82+
<%= form.text_field :option_banned_phones_list, class: "form-control", data: { tagify_target: "input" } %>
83+
<p class="form-hint"><%== t(".option_banned_phones_list_hint_html") %></p>
84+
</div>
85+
8086
</div>

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

+13
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@
170170
</dd>
171171
</div>
172172

173+
<div class="sm:col-span-2">
174+
<dt class="text-sm font-medium text-gray-500">
175+
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_banned_phones_list") %>
176+
</dt>
177+
<dd class="mt-1 text-sm text-gray-900">
178+
<div class="flex items-center gap-2">
179+
<p class="flex text-sm truncate">
180+
<%= integration.option_banned_phones.length %>
181+
</p>
182+
</div>
183+
</dd>
184+
</div>
185+
173186
<div class="sm:col-span-1">
174187
<dt class="text-sm font-medium text-gray-500">
175188
<%= t("activerecord.attributes.pager_tree/integrations/live_call_routing/twilio/v3.option_force_input") %>

config/locales/en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ en:
8383
option_force_input_hint_html: "Force the caller to select a team (even if the integration only has one team)"
8484
option_record_hint_html: "Record a voicemail when no one acknowledges the call"
8585
option_record_emails_list_hint_html: "List of email addresses to notify when a voicemail has been recorded"
86+
option_banned_phones_list_hint_html: "List of phone numbers that are banned from calling the integration"
8687
v3_mailer:
8788
call_recording:
8889
subject: "🎧 Alert #%{tiny_id} - New voicemail from %{from}"
@@ -211,6 +212,7 @@ en:
211212
option_force_input: "Force Caller Input"
212213
option_record: "Voicemail"
213214
option_record_emails_list: "Voicemail Emails"
215+
option_banned_phones_list: "Banned Phones"
214216
"pager_tree/integrations/logic_monitor/v3":
215217
option_access_id: "Logic Monitor Access ID"
216218
option_access_key: "Logic Monitor Access Key"

0 commit comments

Comments
 (0)