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 channel

Under the USSD menu in your sandbox dashboard click Create Channel.

To create a channel you will need a callback 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.
  • 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
  • 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.
  • 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.

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

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.
  4. Create another file in the root of your project and name it app.js and add the following code into the file.
  5.  Modify your package.json file to include a script to run the app. The file should then look something like below.
  6.  In your root folder via the terminal type yarn start or npm start to start the app.
  7. Head to our simulator and choose the USSD option.
  8. Dial USSD — Service Code in the simulator which we generated earlier. For my case it is *384*77255#
  9. The following screenshots show the results after dialing the USSD code.

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

featured_image
About the Author

James Muigai

Software Engineer at Andela

Thanks for subscribing!

 

More Insights

October 10, 2019

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

James Muigai

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 channel

Under the USSD menu in your sandbox dashboard click Create Channel.

To create a channel you will need a callback 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.
  • 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
  • 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.
  • 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.

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

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.
  4. Create another file in the root of your project and name it app.js and add the following code into the file.
  5.  Modify your package.json file to include a script to run the app. The file should then look something like below.
  6.  In your root folder via the terminal type yarn start or npm start to start the app.
  7. Head to our simulator and choose the USSD option.
  8. Dial USSD — Service Code in the simulator which we generated earlier. For my case it is *384*77255#
  9. The following screenshots show the results after dialing the USSD code.

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

featured_image
About the Author

James Muigai

Software Engineer at Andela

Thanks for subscribing!

 

More Insights

Urban Ishimwe’s Software Dev Journey

Perhaps in another life, Urban Ishimwe might have been some famous Social Media Influencer helping b...

16_October_2019

Practices and behaviours of highly productive remote teams

I have worked remotely as a Software engineer with several companies for over four years now. This a...

7_October_2019

Andela & GitHub Partner to Host CodeNaija 2019; Nigeria’s Biggest Hackathon Event of the Year

We’re excited to announce that we will be hosting the CodeNaija 2019 hackathon event in partnershi...

4_October_2019

An Introduction to Python Generators and Coroutines

Before we get into the topic, let's get some definitions right first: Iterator - this is an obj...

30_September_2019

Tapping into your Dev Beast Mode

Before jumping into the gist of this article it is important to understand what it hopes to achieve ...

19_September_2019

The Future of Andela

We started Andela five years ago to solve a simple but pervasive global challenge: Brilliance is eve...

17_September_2019

Partners

Tap into a global talent pool and hire the “right” developers in days, not months.

Developers

Accelerate your career by working with high-performing engineering teams around the world.

BECOME A DEVELOPER

Hire Developers

We take great pride in matching our developers with the best partners. Tell us about your team below!

preloader_image

Thank you for your interest

A member of our team will reach out to you soon.