There are times when you may not want your Twilio application to answer a call to your Twilio phone number. Instead, you may want return a disconnected or busy signal to the caller and not be billed for the call. For example, you may want to reject a particular caller who is overusing or abusing your Twilio application. This HowTo shows how to use the
<Reject> verb to implement a simple blacklist with just a few lines of code.
When a caller dials your Twilio number, your application decides on the fly whether to accept or reject the call. You can change the phone numbers in the example below to set up a simple blacklist.
The request is handled by code that determines the appropriate response. In this case, calls from (415) 555-4345 and (610) 555-7069 are rejected, while all others are answered and hear the
# This code is designed to run with Sinatra, a lightweight ruby webapp framework # Responds to POSTs to http://yourapp.com/reject require 'rubygems' require 'sinatra' post '/reject' do blacklist = ['+14155554345', '+16105557069'] if blacklist.include? params[:From] "<Response><Reject/></Response>" else "<Response><Say>Congratulations! You got through</Say></Response>" end end