31 lines
627 B
JavaScript
31 lines
627 B
JavaScript
// npm imports
|
|
const phin = require("phin");
|
|
|
|
// module imports
|
|
const cache = require("./cache");
|
|
const util = require("./utils");
|
|
|
|
// proxy requests to ussd-server
|
|
// TODO: handle errors
|
|
async function proxy(phone, input = "") {
|
|
const sessionId = await cache.get(phone);
|
|
|
|
const { body } = await phin({
|
|
// TODO: get value from confini
|
|
url: "",
|
|
method: "POST",
|
|
parse: "string",
|
|
form: {
|
|
sessionId: sessionId,
|
|
phoneNumber: phone,
|
|
// TODO: get value from confini
|
|
serviceCode: "",
|
|
text: input,
|
|
},
|
|
});
|
|
|
|
return util.parseUssdResponse(body);
|
|
}
|
|
|
|
module.exports = { proxy };
|