Hubtel USSD
Based on Hubtel's USSD API
About
This package helps you to build maintainable and scalable USSD applications by breaking down your "long switch" statement USSD application into modules
Getting Started
Check out this link to know how you can acquire a USSD code from Hubtel.
Installing
Install the package from npm
npm install --save hubtel-ussd
Usage
Check the example folder for an example using expressjs
//app.js const Hubtel = ;const HubtelUSSD = ;const HubtelRequest = HubtelRequest; //setup CORSconst cors = ; app; //route which serves as the endpoint to your ussd applicationapp;});
Done 😊
Api
ResponseTypes
is an object with two properties response
and release
for indicating the type of response in a sequence.
const hubtel = ; const ResponseTypes =hubtelResponseTypes; ResponseTypesresponse // 'Response' ResponseTypesrelease // 'Release'
HubtelUSSD
is a class with one method process
which takes two parameters a Request (an instance of HubtelUSSDReqeust)
and
an array
of sequence
;
const Hubtel = ; const HubtelUSSD = ; const HubtelRequest = HubtelRequest; let request = /** populate properties **/; let response = await HubtelUSSD; //response is an instance of HubtelUSSDResponse
All seqeunces
must have a handle
method and must return an instance of HubtelUSSDResponse (Response)
.
The package automagically injects a ussdRequest
parameter into the handle
method of each sequence
. This ussdRequest
is an
instace of HubtelUSSDRequest
which grants access to all properties and methods in the request
.
//sequence1.jsconst hubtel = ;const Response = hubtelResponse;const ResponseTypes = hubtelResponseTypes; /* * A ussdRequest object which is an instance of HubtelUSSDRequest * this gives us access to methods such as {mobile,sessionId,serviceCode,type} etc **/ async { //ussdRequest.mobile --- returns the mobile number of the user performing the request. etc return 'Welcome to Freebie Service.\n1. Free Food\n2. Free Drink\n3. Free Airtime'ResponseTypesresponse; } moduleexports = Sequence1;
Visit Hubtel's USSD Api documentation page for the list of methods on the request and response classes
Running the tests
npm test
Authors
- Norris Oduro - Norris1z
License
This project is licensed under the MIT License