GithubHelp home page GithubHelp logo

ussd-with-africastalking-101's Introduction

Ussd with Africastalking 101

What is USSD

USSD (Unstructured Supplementary Service Data) is a communications protocol used in GSM networks for sending short text messages. USSD is similar in format to SMS. However, it is an instant messaging service, so messages are not stored on the operator side or on the subscriber's device.

Simple Code with Africastalking ENV

Ussd with Africastalking demo code

<?php
#sessionId from the Post request
$sessionId=$_POST['sessionId'];
#serviceCode from the Post request
$serviceCode=$_POST['serviceCode'];
# phoneNumber from the Post request
$phoneNumber=$_POST['phoneNumber'];
# text from the Post request
$text=$_POST['text'];

if ($text == ""){
 # check is the first connection is empty and provice response stating with CON to indicate connection.
 $response="CON What would you want to check \n";
 $response .="1. My Account No \n";
 $response .="2. My phone Number";
}
# if you choose option 1
else if ($text == "1") {
 # business login for the first level response
 $response = "CON Choose account information you want to view \n";
 $response .= "1. Account Number \n";
 $response .= "2. Account Balance";
}
# if you choose option 2
else if ($text == "2") {
 # business login for the first level response with END t end the connection
 $response = "END You phone number is ".$phoneNumber;
# if you choose option 1 the second level supplied option 1
} else if($text == "1*1"){
# business login for the second i.e.*ussd*1*1# level response then END to end the Session
 $accountNumber = "ACC1001";

 $response = "END Your account Number is ".$accountNumber;
}
# if you choose option 1 the second level supplied option 2
else if ($text == "1*2") {
# business login for the second i.e.*ussd*1*1# level response then END to end the Session
 $balance = "KES 10,000";
 # code...
 $response= "END Your balance is ".$balance;
}
# include the Header
header('Content-type: text/plain');
# display the response
echo $response;

?>

Deploy the code on heroku my endpoint https://ussd-uat.herokuapp.com/index.php

Go to africastalking create account and then navigate to USSD code and create channel as below. Image description

You will be provided with the details to simulate the USSD.

Then click Launch Simulator as below

Image description

Input you test number and click connect as below

Image description

Go ahead and test the USSD code

Image description

All done now you should have a display as below

Image description

Code on github Francis Kinyurufranciskinyuru

Credits to Africastalking developers platform Developers platform Francis Kagai youtube tutorial Francis Kagai

ussd-with-africastalking-101's People

Contributors

franciskinyuru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.