@@ -7,6 +7,7 @@ class LiveCallRouting::Twilio::V3 < Integration
7
7
{ key : :force_input , type : :boolean , default : false } ,
8
8
{ key : :record , type : :boolean , default : false } ,
9
9
{ key : :record_email , type : :string , default : "" } ,
10
+ { key : :banned_phone , type : :string , default : "" } ,
10
11
{ key : :dial_pause , type : :integer }
11
12
]
12
13
store_accessor :options , *OPTIONS . map { |x | x [ :key ] } . map ( &:to_s ) , prefix : "option"
@@ -32,6 +33,7 @@ class LiveCallRouting::Twilio::V3 < Integration
32
33
self . option_force_input ||= false
33
34
self . option_record ||= false
34
35
self . option_record_email ||= ""
36
+ self . option_banned_phone ||= ""
35
37
end
36
38
37
39
SPEAK_OPTIONS = {
@@ -67,6 +69,14 @@ def option_record_emails
67
69
self . option_record_email . split ( "," )
68
70
end
69
71
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
+
70
80
def option_record_emails_list = ( x )
71
81
# what comes in as json, via tagify
72
82
uniq_array = [ ]
@@ -83,6 +93,22 @@ def option_record_emails_list
83
93
option_record_emails
84
94
end
85
95
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
+
86
112
def validate_record_emails
87
113
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 ) ) }
88
114
end
@@ -111,8 +137,20 @@ def adapter_will_route_alert?
111
137
true
112
138
end
113
139
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
+
114
148
def adapter_action
115
- :create
149
+ if is_banned?
150
+ :other
151
+ else
152
+ :create
153
+ end
116
154
end
117
155
118
156
def adapter_thirdparty_id
@@ -131,6 +169,14 @@ def adapter_process_create
131
169
end
132
170
133
171
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
134
180
# if this was attached to a router
135
181
if !adapter_alert . meta [ "live_call_router_team_prefix_ids" ] . present? && routers . size > 0 && account . subscription_feature_routers?
136
182
adapter_alert . logs . create! ( message : "Routed to router. Attempting to get a list of teams..." )
0 commit comments