npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hubtel-ps

v1.1.0

Published

hubtel progammable services

Downloads

15

Readme

Hubtel Programmable Service (Hubte-ps)

hubtel-ps is library for communicating with the Programmable Services API gateway. It simplify the process for connecting your application to your users who are using USSD, the Hubtel App, Hubtel Mall, and Hubtel Point Of Sales (POS) Apps.

Concept

Hubtel-ps creates an easy to use abstraction layer for communicating with hubtel programmable services for USSD,MOBILE AND POS. Hubtel-ps allows you to define all your responses or request handlers with descriptors whichi allows it to automatically filters for the best response for any request received.

So you only setup your handlers or responses and Hubtel-ps handles the rest

Features

  • Automatically filters Multiple responses for correct response to use
  • Saves all session data including user inputs using Lokijs
  • Allows retrieval of user input values at any sequence of choice using ClientState value as Key
  • Automatically cleans up all stored session data using an interval

Usage/Examples

Initialising hps and hpsEngine

const hps = require('hubtel-ps');
const hpsEngine = hps.init();

Defining a single request handler

    hpsEngine.addHandler(new hps.SequenceHandler(
         [0,1], // valid sequence state, use for filtering type of handler to use
        null, // valid pervious user input. use for filtering handler. NULL means ignore
        (request)=>{ // action function. main code to execute and return responds HUBTEL API
            console.log(request) // the request object to access data such as user input and other data
            return new hps.Response({
                Type: hps.ResponseTypes.response,
                Message: 'Welcome to Naconm. Select Option',
                Label: 'Welcome to Naconm',
                DataType: hps.DataTypes.select,
                FieldType: hps.FieldTypes.number,
                ClientState: 'option',
                Data: [
                    {Display: 'Document Deleivery Request', Value:1},
                    {Display: 'Cancel', Value:2},
                    ],
                })
            }
    ))

Attach multiple handlers or request respones at once via addHandlers()

const hps = require('hubtel-ps');
const hpsHandlers = [];

// Home 
hpsHandlers.push(
    new hps.SequenceHandler(
        [0,1], // valid sequence state, use for filtering type of handler to use
        null, // valid pervious user input. use for filtering handler. NULL means ignore
        (request)=>{ // action function. main code to execute and return responds HUBTEL API
            console.log(request) // the request object to access data such as user input and other data
            return new hps.Response({
                Type: hps.ResponseTypes.response,
                Message: 'Welcome to Naconm. Select Option',
                Label: 'Welcome to Naconm',
                DataType: hps.DataTypes.select,
                FieldType: hps.FieldTypes.number,
                ClientState: 'option',
                Data: [
                    {Display: 'Document Deleivery Request', Value:1},
                    {Display: 'Cancel', Value:2},
                    ],
                })
            }
    )
);


// Select Region
hpsHandlers.push(
    new hps.SequenceHandler(
        [2], // valid sequance state where this handler can be used. you can provide multiple sequences
        1, // Valid user input before this handler or response can be applied
        (request)=>{
        return new hps.Response({
            Type: hps.ResponseTypes.response,
            Message: 'Enter Delivery Region',
            DataType: hps.DataTypes.input,
            FieldType: hps.FieldTypes.text,
            ClientState: 'region' // Used as the key for storing the user input or response to this
        })
    }
    )
);

....

// Now Attach hpsHandlers array to the hps Engine;
// this makes all handlers in array directly accessible to the hpsEngine for filtering
hpsEngine.addHandlers(hpsHandlers);

Processing Request

router.post("/", function (req, res, next) {

    //Create hpsRequest from body
    const ussdrequest = new hps.Request(req.body);

    //process the request and produce appropraite response
    return hpsEngine.process(ussdrequest).then(response => {
        // console.log({response});
        return res.json(response);
    }).catch(err => {
        // return res.status(500).json({
        // "Type": "Release",
        // "Message": "End of Route",
        // "ClientState": "2017-03-30",
        // "MaskNextRoute": true
    });
    });

Processing Payment Callback and Fulfillment Request

router.post("/complete", function (req, res, next) {
    return hpsEngine.processPayment(req.body, async(paymentRequest)=> {


        //Get session Data stored with lokiJs
        // const sessionData = hps.getSessionData(paymentRequest.SessionId);


        // Implement any custom function or database operation
        // const student = await Student.findOne({schoolcode:'naconm01', indexnumber: sessionData.indexnumber});
        // if(!student){
        // return {ServiceStatus: hps.ServiceStatus.failed, ExtraData:{message: 'student not found'}}
        // }


        // Commit data to database of perform custom operation with successfull payment
        // const delivery = new TranscriptDelivery(paymentRequest);
        // delivery.User = student.user;
        // delivery.Student = student._id;
        // delivery.Indexnumber = student.indexnumber;
        // delivery.Name = student.surname  + ' ' + student.othernames;
        // await delivery.save();

        // Return ServiceStatus to confirm succesful completion of service
        return {ServiceStatus: hps.ServiceStatus.successs, ExtraData:{}}

        // Return failed or Unknown if service completion fialed from your point
        return {ServiceStatus: hps.ServiceStatus.failed, ExtraData:{}}


    }).then(response => {
        // console.log({response});
        return res.json(response); // return fulfillment response automatically
    }).catch(err => {
        console.log({err})
        return res.status(500).json({
        "Type": "Release",
        "Message": "End of Route",
        "MaskNextRoute": true
    });
    });
});

License

MIT

Authors