ussd-router
is a free utility for easy routing in USSD applications.
npm i ussd-router
See also:
import { ussdRouter } from 'ussd-router';
const text1 = ussdRouter('544*1*2'); // '544*1*2'
const text2 = ussdRouter('544*1*2*00*3'); // '544*1*3'
const text3 = ussdRouter('544*1*2*0*1*2'); // '1*2'
const text4 = ussdRouter('544*1*2*0*1*2*00*3'); // '1*3'
import express from 'express';
import { ussdRouter } from 'ussd-router';
// ...
app.post('/webhook/ussd', (req, res) => {
const { body: { text: rawText } } = req;
const text = ussdRouter(rawText);
if (text === '1') {
res
.status(200)
.send('View: \n1. My account number \n2. My balance');
}
// ...
});
# install dependencies
npm i
# build
npm run build
# lint
npm run lint
# test
npm t