ussd-tg-proxy/src/util.js

22 lines
471 B
JavaScript
Raw Normal View History

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