Permalink
Browse files

added ability to send SMS messages from dashboard

  • Loading branch information...
1 parent e7a0020 commit a30fd06b574c552b6f5fb4a3dfe785d15171cc40 @bnvk bnvk committed Apr 17, 2012
Showing with 94 additions and 530 deletions.
  1. +22 −0 controllers/api.php
  2. +2 −18 controllers/home.php
  3. +5 −3 libraries/Twilio.php
  4. +0 −508 libraries/Twilio_Old.php
  5. +65 −1 views/home/sms.php
View
@@ -7,6 +7,7 @@ function __construct()
parent::__construct();
$this->load->config('twilio');
+ $this->load->library('twilio');
}
/* Install App */
@@ -31,4 +32,25 @@ function install_get()
$this->response($message, 200);
}
+ function sms_send_authd_post()
+ {
+ // Send a new outgoing SMS */
+ $from = config_item('twilio_phone_number');
+ $to = $this->input->post('to_number');
+ $message = $this->input->post('sms_message');
+
+ $send_sms = $this->twilio->sms($from, $to, $message);
+
+ if ($send_sms)
+ {
+ $message = array('status' => 'success', 'message' => 'Yay, your SMS was sent');
+ }
+ else
+ {
+ $message = array('status' => 'error', 'message' => 'Dang your SMS could not be sent');
+ }
+
+ $this->response($message, 200);
+ }
+
}
View
@@ -6,7 +6,7 @@ function __construct()
parent::__construct();
$this->load->config('twilio');
- $this->load->library('Twilio');
+ $this->load->library('twilio');
$this->data['page_title'] = 'Twilio';
}
@@ -31,26 +31,10 @@ function sms()
{
$this->data['sub_title'] = 'SMS';
$this->data['responses'] = $this->twilio->request('/'.config_item('twilio_api_version').'/Accounts/'.config_item('twilio_account_sid').'/SMS/Messages', "GET", array("To" => config_item('twilio_phone_number')));
-
+
$this->render();
}
-
- function send_sms()
- {
-
- $from = '3104023675';
- $to = '9712211599';
- $message = 'This is a test...';
- $response = $this->twilio->sms($from, $to, $message);
-
- if($response->IsError)
- echo 'Error: ' . $response->ErrorMessage;
- else
- echo 'Sent message to ' . $to;
-
- }
-
function check_number()
{
View
@@ -39,7 +39,7 @@ function __construct()
$this->account_sid = config_item('twilio_account_sid');
$this->auth_token = config_item('twilio_auth_token');
$this->api_version = '2010-04-01';
- $this->number = '';
+ $this->number = config_item('twilio_phone_number');
//initialize the client
$this->_twilio = new TwilioRestClient($this->account_sid, $this->auth_token);
@@ -71,16 +71,18 @@ public function __call($method, $arguments)
*/
public function sms($from, $to, $message)
{
- $url = '/' . $this->api_version . '/Accounts/' . $this->account_sid . '/SMS/Messages';
+ $url = '/'.$this->api_version.'/Accounts/'.$this->account_sid.'/SMS/Messages';
$data = array(
- 'From' => $from,
+ 'From' => $from,
'To' => $to,
'Body' => $message,
);
if ($this->mode == 'sandbox')
+ {
$data['From'] = $this->number;
+ }
return $this->_twilio->request($url, 'POST', $data);
}
Oops, something went wrong.

0 comments on commit a30fd06

Please sign in to comment.