Moodle SMS through Africa's Talking: a free SMS gateway plugin
Moodle 4.5 added SMS gateways for things like login codes, but core ships only Amazon (and Modica from 5.x). Our free smsgateway_africastalking sends Moodle's SMS through Africa's Talking.
Short answer: since Moodle 4.5, Moodle can send SMS through “SMS gateways”, for example the codes of SMS-based multi-factor login. Moodle 4.5 ships one gateway, Amazon (AWS); Moodle 5.3 adds Modica. For schools whose SMS provider is Africa’s Talking, there was no Moodle gateway. Our free plugin, smsgateway_africastalking, adds one.
This is the eighth plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works.
Setting it up
- Site administration > Plugins > SMS > Manage SMS gateways > Create new SMS gateway, and pick Africa’s Talking.
- Enter your Africa’s Talking username and API key, and optionally a sender ID or short code you registered with them.
- Set the country code in the same form (for example 254 for Kenya), so numbers saved without a + are sent in full international form.
- To test first, use the username
sandboxwith a sandbox API key. Messages then only appear in Africa’s Talking’s simulator, and nobody’s phone rings.
A message is marked as sent in Moodle only when Africa’s Talking answers that the recipient’s status is “Success”. A wrong number, a missing balance or a bad key is marked as failed, so admins see it.
The plugin stores no data itself. It sends the phone number and the message text to Africa’s Talking, and says so in Moodle’s privacy registry. It supports Moodle 4.5 LTS to 5.3 and is GPL. The code is on GitHub.
How a Moodle SMS gateway works
From Moodle 5.3’s SMS subsystem and its two built-in gateways:
- The gateway is one class extending
\core_sms\gatewaywith asend()method that returns the message marked sent or failed. Core keeps the record of every message. - Admin settings are added to core’s own gateway form through a hook, not a settings page of your own. Core’s form already has a name and a country code field, and our first version added a second country code field by mistake. Reading core’s form caught it before release.
- HTTP calls go through Moodle’s own HTTP client, which tests can replace with a fake that records each request. Our tests check the exact address, the
apikeyheader and the form fields sent, for both the live and sandbox hosts. - Africa’s Talking’s documentation pages refused automated reading, so we took the endpoint, headers and fields from their official PHP library’s source instead.
We tested it with PHPUnit (success, a refused number, a bad key, the sandbox host) and a Behat run where an admin creates the gateway through the real form.
What Studio learned
The SMS gateway guide is now in DevLMS Studio’s builder, including the two field names core’s form already uses.
Need SMS through another provider, or WhatsApp messages for course reminders? Describe it in DevLMS Studio and watch it built and tested in a real Moodle.
Need a plugin like this for your own Moodle?
Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.
Open DevLMS Studio