julmajanne.com

SMS library for Moodle

As always this document is a draft and written as personal notes. This is not a definitive guide.
NOTICE! This is only a library. This package does not contain any ready-made User Inteface for sending messages.

This SMS library supports two SMS Gateways and one SMS service:

  1. Kannel WAP/SMS Gateway (small guide to install and configure)
  2. TextMagic SMS service. If you want to use their SMS API, you need to have knowledge of their HTTPS API
  3. NowSMS SMS/MMS Gateway (does not include MMS sending at this point, this is on my TODO list)
    • Commercial software (and expensive one)
  4. Clickatell SMS Service

The SMS library download

WARNING!!! Use at your own risk!

First release Support for TextMagic's service. Send, account, message_status, receive, delete_reply and check_number commands are supported in this release.

Updated: Allow multiple recipients for one message ( recipients can be an array ). Changed HTTP GET request to version 1.1

Older versions

License

smslib is published under the GNU General Public License (GPL) and Connection class library is published under MIT License.

Installation

  1. Just unzip the package into /moodleinstalldir/lib/ directory.
  2. Add the configuration variables into config.php file.

Settings

The basic settings for all the gateways are:

$CFG->gwhost  = 'xxx.xxx.xxx.xxx';  // IP address or a hostname of the sms gateway
$CFG->gwproto = 'http';            // http or https.
$CFG->gwport  = 80;               // Port number to connec to.
$CFG->gwuser  = 'username';     // Username of the gateway or account.
$CFG->gwpass = 'password';      // Password of the gateway or account.
$CFG->gwsocketinterface = 'fsockopen'; // Socket interface to use.
$CFG->gwclient = 'kannel'; // Use this gateway library (kannel, nowsms or clickatell).

If you're using Clickatell, you'll need to define few extra variables:

$CFG->ct_api_id = '123456'; // You're Clickatell accounts api_id
$CFG->ct_balancelimit = 5; // A limit which stops message routing to the gateway.

Create a test script to test the installation:

<?php
require_once('path/to/moodle/config.php');
require_once($CFG->libdir .'/sms/smslib.php');

// Load the sms object
$sms = SMS::Loader($CFG);

// Define the recipient of this sms message.
// Number must be in international form including '+' -sign in front of it.
$to = '+358451234567';
// Or multiple recipients
// $to = array('+35840123456','+35850456789','+35845123789');

// The message it self.
$message = 'This is a test message!';

// Send the message.
if ( $sms->send_message($to, $message) ) {
echo "SMS Message sent!";
} else {
echo "Error while sending SMS Message!";
}
?>

After that you should be able to develop your own SMS enabled Modules, blocks or whatever you feel like.