const phin = require("phin"); const config = require("./config"); const log = require("./log"); async function proxy(sessionId, phone, input = "") { const requestOptions = { url: config.get("USSD_ENDPOINT"), method: "POST", parse: "string", form: { sessionId: sessionId, phoneNumber: phone, serviceCode: config.get("USSD_CODE"), text: input, }, }; log.debug(requestOptions, "request options"); try { const { body } = await phin(requestOptions); log.debug({ body: body }, "response body"); return body; } catch (error) { log.error(error); return "ERR Something went wrong, try again later."; } } module.exports = { proxy };