Category Covered

Integrating CakePHP with Twillio

How you will integrate twillio on cakephp? Here i am going to write step by step.

Step1: Download the twillio from the below link and extract it to projectName/app/vendor

Directly you may download from the given links or

Step2: create a controller twillio_controller.php with the following content

App::import('Vendor', 'Twilio', array('file' => 'twilio-php-master'.DS.'Services'.DS.'Twilio.php'));
//- See more at:

class TwiliosController extends AppController {

    function beforeFilter() {
        $this->Auth->authorize = 'controller';
        $this->Auth->allow('attempt_call','call_tracking', 'send_text', 'get_account_info', 'get_list_of_accounts', 'call', 'screen_for_machine', 'complete_call');
        $this->Auth->fields = array('username' => 'username', 'password' => 'password');
        $this->Auth->autoRedirect = false;
        var $uses = array("Call");
        //Trial account
        var $sid = 'AC7bf1b33ad470159107c01b8ef5704221';
        var $token = '8d0cd85dda9c5c5ca85f9d73c1a2b2e3';
    //initialize twilio services
    public function send_text() {
        $client = new Services_Twilio($this->sid, $this->token);
        $send_to = '+880 1922291533';
        $message_text = 'This is test sms using test cred';
        $message = $client->account->sms_messages->create($this->twilio_number, $send_to, $message_text);
        echo $message->date_created."<br/>";
        echo $message->to."<br/>";
        echo $message->from."<br/>";
        echo $message->body."<br/>";
    function get_account_info(){
        $client = new Services_Twilio($this->sid, $this->token);
        $account = $client->accounts->get($this->sid);
        echo $account->date_created;
    function get_list_of_accounts(){
        $client = new Services_Twilio($this->sid, $this->token);
        foreach ($client->accounts as $account) {
            echo $account->sid;
    // initialize twilio services
    public function call() {
        /*$client = new Services_Twilio($this->sid, $this->token);
        $send_to = '+880 1922291533';
        $call = $client->account->calls->create($this->twilio_number, $send_to, "", array());

        echo $call->sid;
        echo $call->DialCallDuration;
        echo $call->RecordingUrl;
        //echo $call->date_created."<br/>";
        //echo $call->to."<br/>";
        //echo $call->from."<br/>";
        //echo $call->body."<br/>";
    function attempt_call(){
        $this->layout = "blank";
        if( !empty($_REQUEST) ){
        //Set multiple real nubmers to call
        //$numbers = array("<number to call 1>", "<number to call 2>", "<number to call n>");
        $numbers = array("813-325-4340"); //Real number of Brent
        $number_index = isset($this->params["url"]["number_index"]) ? $this->params["url"]["number_index"] : "0";
        $DialCallStatus = isset($this->params["url"]["DialCallStatus"]) ? $this->params["url"]["DialCallStatus"] : "";
        $this->set("numbers", $numbers);
    function screen_for_machine(){
        $this->layout = "blank";
    function complete_call(){
        $this->layout = "blank";
    function call_tracking(){
        $this->paginate = array('limit'=>20,'order'=>'Call.created DESC');
        $this->set('calls', $this->paginate( $this->Call ));

Step3: Create a view folder named "twillios"