function add_from_twilio_recording() { $json = array('error' => false, 'message' => ''); $to = preg_replace('/[^0-9]*/', '', $this->input->post('to')); $callerid = preg_replace('/[^0-9]*/', '', $this->input->post('callerid')); if (strlen($to) == 0) { $json['error'] = true; $json['message'] = "You must provide a number to call."; } else { if (strlen($callerid) == 0) { $json['error'] = true; $json['message'] = "You must have an incoming number to record a greeting. <a href=\"" . site_url('numbers') . "\">Get a Number</a>"; } else { $rest_access_token = $this->make_rest_access(); $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint); $path = 'audiofiles!prompt_for_recording_twiml'; $recording_url = stripslashes(site_url("twiml/redirect/" . $path . "/{$rest_access_token}")); $response = $twilio->request("Accounts/{$this->twilio_sid}/Calls", 'POST', array("Caller" => $callerid, "Called" => $to, "Url" => $recording_url)); if ($response->IsError) { $json['message'] = $response->ErrorMessage; $json['error'] = true; } else { $callSid = $response->ResponseXml->Call->Sid[0]; $ci =& get_instance(); // Create a place holder for our recording $audioFile = new VBX_Audio_File(); $audioFile->label = "Recording with " . format_phone($to); $audioFile->user_id = intval($this->session->userdata('user_id')); $audioFile->recording_call_sid = "{$callSid}"; $audioFile->tag = $this->input->post('tag'); $audioFile->save(); $json['id'] = $audioFile->id; } } } $data = array(); $data['json'] = $json; $this->response_type = 'json'; $this->respond('', null, $data); }
function add_from_twilio_recording() { $json = array('error' => false, 'message' => ''); $to = $this->input->post('to'); $callerid = $this->input->post('callerid'); if (strlen($to) == 0) { $json['error'] = true; $json['message'] = "You must provide a number to call."; } else { if (strlen($callerid) == 0) { $json['error'] = true; $json['message'] = "You must have an incoming number to record a greeting. <a href=\"" . site_url('numbers') . "\">Get a Number</a>"; } else { $rest_access_token = $this->make_rest_access(); $path = 'audiofiles!prompt_for_recording_twiml'; $recording_url = stripslashes(site_url("twiml/redirect/" . $path . "/{$rest_access_token}")); try { $account = OpenVBX::getAccount(); $call = $account->calls->create($callerid, $to, $recording_url); // Create a place holder for our recording $audioFile = new VBX_Audio_File((object) array('label' => 'Recording with ' . format_phone($to), 'user_id' => intval($this->session->userdata('user_id')), 'recording_call_sid' => $call->sid, 'tag' => $this->input->post('tag'))); $audioFile->save(); $json['id'] = $audioFile->id; } catch (Exception $e) { $json['message'] = $e->getMessage(); $json['error'] = true; } } } $data = array(); $data['json'] = $json; $this->response_type = 'json'; $this->respond('', null, $data); }