Africa’s Talking Node.js (express) USSD Application

The app developed here will help a user to view their phone number and account details (Account number and account balance).Follow this article to set up a simulator.After you have launched the simulator, go back to your sandbox dashboard and create a channel. A channel will help us to run our implementation. A channel will constitute a Service Code and Callback URL.A Service Code is the USSD code that we are going to type on our simulator and it will call the callback url upon hitting send. You can imagine a situation whereby someone is checking their balance. For instance, they will enter *144# and hit send. The *144# is a Service Code. Upon hitting send, a callback URL will be called, the URL endpoint will help to carry out the needed operations which will be to determine the actual calculation of the balance and return the results.How to create a channelUnder the USSD menu in your sandbox dashboard click Create Channel.

USSD application

To create a channel you will need acallback URL. A callback URL will be called when a user sends a request using a service code.Create a callback URL

  • Head to https://dashboard.ngrok.com/user/signup and create an account or login if you have one.
  • Download and unzip ngrok which will help us to access our localhost server through the internet.
  • After downloading the ngrok open a terminal window and navigate to the directory where you downloaded the setup.
explore ngrok setup and installation
  • Copy the command shown in the above screenshot and enter it in the terminal. Note: The above command should be run int the directory where you downloaded the ngrok
programming script
  • Run ./ngrok HTTP 3000 to start an HTTP tunnel to our localhost on port 3000. You will be able to see something like shown below.
ngrok by inconshreveable status online
  • Copy the Forwarding URL. For my case it is http://b483439b.ngrok.io
  • Paste the link in the callback URL field and input a channel of your choice and if the channel is not available you will get a suggestion as shown in the image below.
USSD application

We should have something as shown below in our USSD — Service Codes.

africas talking ussc code

Now that we have a channel fully configured we can start writing code.

  1. Initialize a node application via yarn init or npm init
  2. Install express, nodemon, body-parser and Africa's Talking dependencies via yarn add express nodemon Africa's Talking body-parser or npm install express Africa's Talking nodemon body-parser -— save
  3. In the root directory (current directory) of the app, create a file named index.js and add the following code into the file.
programming script
  1. Create another file in the root of your project and name it app.js and add the following code into the file.
const express app listen
  1.  Modify your package.json file to include a script to run the app. The file should then look something like below.
package.json ussd-app
  1.  In your root folder via the terminal type yarn start or npm start to start the app.
  2. Head to our simulator and choose the USSD option.
  3. Dial USSD — Service Code in the simulator which we generated earlier. For my case it is *384*77255#
mobile phone
  1. The following screenshots show the results after dialing the USSD code.
smartphone vector art

Feel free to play around with the options provided. This means that our USSD app if fully functional.

Related posts

The latest articles from Andela.

Visit our blog

Overcoming the Challenges of Working With a Mobile FinTech API

Andela community member Zzwia Raymond explores why, despite the potential of the MTN Mobile Money platform and its API, there are technical hurdles, from complex documentation to enhancing functionality.

How Andela Transformed Tech Hiring in 10 Years

Celebrating 10 years of transforming tech hiring by unlocking global talent across Africa, Latin America and beyond, Andela has surpassed its original goal by training nearly 110,000 technologists and assembling one of the world's largest remote tech talent marketplaces.

What GPT-4o and Gemini releases mean for AI

The latest generative AI models from OpenAI (GPT-4) and Google (Gemini 1.5 Pro, Veo, etc.) promise improved capabilities, lower costs, and transformative applications across various industries by integrating advanced AI technologies into business operations.

We have a 96%+
talent match success rate.

The Andela Talent Operating Platform provides transparency to talent profiles and assessment before hiring. AI-driven algorithms match the right talent for the job.