Skip to content

Instantly share code, notes, and snippets.

@TheBeachMaster
Last active September 20, 2017 18:41
Show Gist options
  • Save TheBeachMaster/a08666b45ce22f1176f6d97b840cfb01 to your computer and use it in GitHub Desktop.
Save TheBeachMaster/a08666b45ce22f1176f6d97b840cfb01 to your computer and use it in GitHub Desktop.
Sample Africa's Talking USSD Node App
var express = require('express')
var app = express()
var options = {
sandbox: true, //false if going to prod
apiKey: '', //Your Africas Talking Sandox or Live Key
username: '', // Your Username: "sandbox" for testing...
format: 'json'
};
var AfricasTalking = require('africastalking')(options);
app.post('/ussd', new AfricasTalking.USSD((params, next) => {
var endSession = false;
var message = '';
console.log(params); //DEBUGGING REMOVE
if (params.text === '') {
message = "Welcome to My Awesome Service \n";
message += "1: To Halla back \n";
message += "2: For more awesomeness";
} else if (params.text === '1') {
message = "Yoh 'Sup?";
endSession = true;
} else if (params.text === '2') {
message = "Enter 1 for a shocker \n";
message += "Enter 2 for another shocker";
endSession = false;
} else if (params.text === '2*2') {
message = "Dude.... \n";
endSession = true;
} else if (params.text === '2*1') {
message = "You mad broh?! \n";
endSession = true;
} else {
message = "Invalid option";
endSession = true;
}
next({
response: message,
endSession: endSession
});
}));
app.get('/', function(req, res) {
res.send('Alive!')
})
app.listen(3000, function() {
console.log('App live on port 3000!')
})
{
"name": "nodeussd",
"version": "1.0.0",
"description": "Node USSD application",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [
"USSD",
"Node"
],
"author": "Arthur Kennedy Otieno",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"africastalking": "0.0.9",
"express": "^4.15.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment