USSD App Development with Javascript

AJALA ABDULSAMII
4 min readNov 7, 2017

In developing countries where fast internet is still a myth, or when services can be simplified to as little user interaction as possible, USSD Applications is arguably one of the winning solutions.

sample ussd application

We are going to be using javascript to write a simple backend logic of USSD application. The whole process has been simplified by a company called AfricasTalking.com They made the whole process simple to the bearest minimum that we only need to create a server with an endpoint to receive http requests and we send back HTTP responses in return. An article has been written prior to this but I see a need to rewrite it putting Javascript into consideration. This should be easily understood and pluggable into large NodeJS applications.

Let’s get started

Step 1: In your desired location(directory), run terminal/cmd and type

npm init -y
npm install -S express body-parser morgan

this initialize your working folder with a package.json and install these dependencies:

Express: for creating your server endpoint, body-parser: for decoding what gets to the server and decode them to what the server can use and morgan: for logging on the server as to what endpoint got a request and the data sent to it. Don’t worry if these sounds confusing, you will understand in the code.

Step 2: Create a server.js file and write your code like so

USSD server script (Ps: read through the code, it is well commented to explain its logic)

Step 3: modify your start script in package.json file like so:

{  "name": "ussd_server",  "version": "1.0.0",  "description": "A sample USSD server tutorial with AfricasTaslking.com service",  "main": "server.js",  "scripts": {    "start": "node server.js"  },  "keywords": [    "USSD",    "NODE"  ],  "author": "Your Name <email>",  "license": "MIT",  "dependencies": {    "body-parser": "^1.18.2",    "express": "^4.16.2",    "morgan": "^1.9.0"  }}

Step 4: Setup heroku (a simplified cloud deployment service) by following this link https://devcenter.heroku.com/articles/heroku-cli if you don’t already have it set up on your machine.

Step 5: Push your code to heroku running these in your terminal line by line

git init
git add .
git commit -m "first commit"
heroku create
git push heroku master
heroku open

after successfully running these commands, your browser will automatically open the app via its heroku link and you should see:

This is tutorial App on creating your first USSD app in 5 minutes or less by Ajala Abdulsamii (lol) in your browser

just like I have in my own here. Copy that heroku app address in your browser, we will need it soon.

Step 6: Create a free account at Africastalking.com

Services offered at Africastalking.com

Step 7: Click the “Go to Sandbox App” button on your dashboard

Africastalking sandbox
Sandbox Dashboard showing all the services they offer on the menu

Step 8: Click the USSD menu item to see the dropdown, and select the “Create Channel” option.

The USSD code format for their Nigerian USSD is

*384*YOUR CHANNEL NO#

So your USSD code would look like this *384*1300#

(check for your country if you are not a Nigerian or your service is not meant for nigeria)

The callback URL is the server side endpoint that the USSD application is going to hit every time a user dials your USSD code. In your own case the address you copied earlier from your browser.

So click ‘create channel’

Boom! You have a USSD apps built and setup

To see a demo of our USSD apps in action, AfricasTalking.com have provided a simulator to test your apps here https://simulator.africastalking.com:1517/

You can try my demo USSD application with *384*1960#

Excited uhn? Don’t rush to your phone yet, remember your app was created in sandbox. To go live head on to their website to review their pricing on https://africastalking.com/services/ussd/pricing

Ps: Their USSD code is only available on MTN and 9Mobile as at the time this article was written. Plans are on the way to support other networks as well.

Credits:

“You’ve heard of Africastalking”… by Douglas Kesi-Ayeba K of Devcenter.co blog

Useful links:

Website:https://africastalking.com/

Documentation: http://docs.africastalking.com/

--

--

AJALA ABDULSAMII

A computer programmer(Fullstack developer) and tech enthusiast