UNPKG

pswincom-gateway-typed

Version:

Send SMS messages through LINK Mobility / PSWinCom Gateway, TypeScript version.

31 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendSms = void 0; const iconv_lite_1 = require("iconv-lite"); const xml2js_1 = require("xml2js"); const make_sms_result_js_1 = require("./make-sms-result.js"); const make_xml_request_model_js_1 = require("./make-xml-request-model.js"); const sendSms = async (options) => { const fetchFunction = options.fetch || fetch; const xml = (0, make_xml_request_model_js_1.makeXmlRequestModel)(options); const body = (0, iconv_lite_1.encode)(xml, 'latin1'); const hostname = process.env.PSW_GW_HOST || 'xml.pswin.com'; const path = process.env.PSW_GW_PATH || ''; const port = process.env.PSW_GW_PORT || '443'; const url = `https://${hostname}:${port}${path}`; const response = await fetchFunction(url, { method: 'POST', headers: { 'Content-Type': 'text/xml', 'Content-Length': String(body.length), }, body: body, }); const responseText = await response.text(); const xmlResponse = await (0, xml2js_1.parseStringPromise)(responseText, { explicitArray: false, }); return (0, make_sms_result_js_1.makeSmsResult)(xmlResponse, options.receivers); }; exports.sendSms = sendSms; //# sourceMappingURL=send-sms.js.map