Get Started

Reject an Incoming Call

This howto uses features launched in Twilio's 2010-04-01 API

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.

Usage

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.

Concepts

This HowTo demonstrates rejecting certain calls using the TwiML <Reject> verb while answering other calls with the <Say> verb.

Download

reject.zip

Implementation

  • 1

    • Twilio receives an incoming call and makes an HTTP POST request to http://yourapp.com/reject
  • 2

    • 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 <Say> text.

      • howtos/reject/reject.rb
        # 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