this is the setup in my controller for voice broadcast in cake 1.3. Probably not the best code but it works for me.
if($this->data['Recording']['voice_broadcast'] == "voice_recording"){
App::import('Vendor', 'Twilio', array('file' => 'twilio'.DS.'Services'.DS.'Twilio.php'));
$this->loadModel('Smstwilio');
$this->Smstwilio->recursive = 0;
$smsOptions_array = $this->Smstwilio->find('all', array('conditions' => array('Smstwilio.school_id' => $session_school_id)));
$account_sid = $smsOptions_array['0']['Smstwilio']['account_sid'];
$auth_token = $smsOptions_array['0']['Smstwilio']['auth_token'];
$client = new Services_Twilio($account_sid, $auth_token);
$this->loadModel('Recording');
$this->Recording->recursive = 0;
$recording = $this->Recording->findById($this->data['Queue']['recording']);
foreach($users_data as $user){
$call_number = "";
//check for phone or cell phone missing on user. if missing use the household head phone
if((empty($user['User']['phone'])) || (empty($user['User']['cell_phone']))) {
//find the head of household using user household_id and is_head => 1
$head = $this->User->find('all', array('conditions' => array('User.household_id' => $user['User']['household_id'], 'User.is_head' => '1')));
//set user email with head email
if (empty($user['User']['phone'])) {
$user['User']['phone'] = $head[0]['User']['phone'];
}
if (empty($user['User']['cell_phone'])) {
$user['User']['cell_phone'] = $head[0]['User']['cell_phone'];
}
}
if($this->data['Recording']['phone_type'] == 0){
if($user['User']['phone']){
$call_number = $user['User']['phone'];
}elseif($user['User']['cell_phone']){
$call_number = $user['User']['cell_phone'];
}
}else{
if($user['User']['cell_phone']){
$call_number = $user['User']['cell_phone'];
}elseif($user['User']['phone']){
$call_number = $user['User']['phone'];
}
}
if(!empty($call_number)){
$options = array("IfMachine" => "Continue");
try{
$call = $client->account->calls->create(
$smsOptions_array['0']['Smstwilio']['phone_number'], // From this number
$call_number, // Call this number
'http://www.domain.com/queues/play_recording.xml?recording_url='.$recording['Recording']['recording_url'],
$options
);
}catch (Exception $ex){
echo $ex->getMessage();
}
}
} //end foreach
$this->Session->setFlash(__('The Recording has been sent', true));
$this->redirect(array('action'=>'download4'));
}
if($this->data['Recording']['voice_broadcast'] == "voice_recording"){
App::import('Vendor', 'Twilio', array('file' => 'twilio'.DS.'Services'.DS.'Twilio.php'));
$this->loadModel('Smstwilio');
$this->Smstwilio->recursive = 0;
$smsOptions_array = $this->Smstwilio->find('all', array('conditions' => array('Smstwilio.school_id' => $session_school_id)));
$account_sid = $smsOptions_array['0']['Smstwilio']['account_sid'];
$auth_token = $smsOptions_array['0']['Smstwilio']['auth_token'];
$client = new Services_Twilio($account_sid, $auth_token);
$this->loadModel('Recording');
$this->Recording->recursive = 0;
$recording = $this->Recording->findById($this->data['Queue']['recording']);
foreach($users_data as $user){
$call_number = "";
//check for phone or cell phone missing on user. if missing use the household head phone
if((empty($user['User']['phone'])) || (empty($user['User']['cell_phone']))) {
//find the head of household using user household_id and is_head => 1
$head = $this->User->find('all', array('conditions' => array('User.household_id' => $user['User']['household_id'], 'User.is_head' => '1')));
//set user email with head email
if (empty($user['User']['phone'])) {
$user['User']['phone'] = $head[0]['User']['phone'];
}
if (empty($user['User']['cell_phone'])) {
$user['User']['cell_phone'] = $head[0]['User']['cell_phone'];
}
}
if($this->data['Recording']['phone_type'] == 0){
if($user['User']['phone']){
$call_number = $user['User']['phone'];
}elseif($user['User']['cell_phone']){
$call_number = $user['User']['cell_phone'];
}
}else{
if($user['User']['cell_phone']){
$call_number = $user['User']['cell_phone'];
}elseif($user['User']['phone']){
$call_number = $user['User']['phone'];
}
}
if(!empty($call_number)){
$options = array("IfMachine" => "Continue");
try{
$call = $client->account->calls->create(
$smsOptions_array['0']['Smstwilio']['phone_number'], // From this number
$call_number, // Call this number
'http://www.domain.com/queues/play_recording.xml?recording_url='.$recording['Recording']['recording_url'],
$options
);
}catch (Exception $ex){
echo $ex->getMessage();
}
}
} //end foreach
$this->Session->setFlash(__('The Recording has been sent', true));
$this->redirect(array('action'=>'download4'));
}
On Sun, Jul 7, 2013 at 8:23 AM, Yasir Arafat Hasib <arafatix@gmail.com> wrote:
Hello everybody.--
I am integrating twilio with cakephp. I hoped integration is done but after 2/3 rings the call are droping and also i failed to get the call record.
I got others data fine after call end on my database.
--Thanks & Regards.
-----------------------------------------------------------------------------------------------------------------------------
Yasir Arafat (Hasib)
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment