Moodle plugin

Hi,
I am trying to configure a plugin to work with Moodle. The plugin is meant to allow users to send text messages via Moodle. When attempting to send a message nothing gets sent out and Moodle displays the following error message:

Notice : Undefined index: messages in /home/aqionlin/public_html/blocks/sms/classes/twilio_api.php on line 55
Please help. how can fix this error. it is relating to the messages variable.
Below is the code:

class TwilioAPI {
private $uri;
private $accountsid;
private $authtoken;
private $fromnumber;

public function __construct() {
    global $CFG;
    $this->accountsid = $CFG->block_sms_twilio_accountsid;
    $this->authtoken = $CFG->block_sms_twilio_auth_token;
    $this->fromnumber = $CFG->block_sms_twilio_api_from;
    $this->uri = 'https://api.twilio.com/2010-04-01/Accounts/'.$this->accountsid.'/Messages.json';

    if ($this->fromnumber[0] != '+') {
        $this->fromnumber = "+".$this->fromnumber;
    }
}

public function send_sms($to, $text) {
    if ($to[0] != '+') {
        $to = "+$to";
    }

    $result = $this->trigger_api($to, $text);
    $status = false;
    try {
        $result = json_decode($result, true);
        $status = $result["messages"][0]["status"] == 0;
    } catch (Exception $e) {
        ";";
    }
    return $status;
}

private function trigger_api($to, $text) {
    $data = array(
        'From' => $this->fromnumber,
        'To' => $to,
        'Body' => urlencode($text)
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->uri);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $this->accountsid . ':' . $this->authtoken);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

}

Sponsor our Newsletter | Privacy Policy | Terms of Service