ussd-tg-proxy/src/utils.js

21 lines
425 B
JavaScript

// this regex extracts ussd reply options
const regex = /(\d).\s/g;
// TODO: converts the text to a telegram keyboard
function createKeyboard(input) {
return Array.from(input.matchAll(regex), (m) => m[1]);
}
// parses ussd responses to code and text
function parseUssdResponse(input) {
return {
code: input.slice(0, 3),
text: input.slice(4),
};
}
module.exports = {
createKeyboard,
parseUssdResponse,
};