Skip to content

Instantly share code, notes, and snippets.

@kamituel
Last active December 22, 2015 23:39
Show Gist options
  • Save kamituel/6548441 to your computer and use it in GitHub Desktop.
Save kamituel/6548441 to your computer and use it in GitHub Desktop.
Open API USSD handling (Heroku)
var http = require('http');
http.createServer(function (req, res) {
if (req.method !== 'POST') {
res.writeHead(405, {'Content-Type': 'text/plain'});
return res.end(req.method + ' not allowed. Use POST instead.');
}
var data = '';
req.setEncoding('utf8');
req.on('data', processPayload);
req.on('end', sendResponse);
function sendResponse () {
var ussd = JSON.parse(data).api.request['ussd-pull'];
res.writeHead(200, {'Content-type': 'text/plain'});
res.end('Hello ' + ussd.callee + ' who sent ' + ussd.code);
}
function processPayload (chunk) {
data += chunk;
}
}).listen(process.env.PORT || 5000);
{
"name": "ussd-heroku",
"version": "0.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD"
}
web: node app.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment