45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
/**
|
|
* workflowSender.js
|
|
*
|
|
* Temporary workflow-based send module for Published (whitelisted) templates.
|
|
* This is a separate code path from the legacy cURL execution route.
|
|
* The legacy cURL code in businesses.js is preserved and NOT removed.
|
|
*
|
|
* Uses env var: WORKFLOW_URL_TEST_SMS
|
|
*/
|
|
|
|
const axios = require('axios');
|
|
|
|
/**
|
|
* Send an SMS via the temporary workflow endpoint.
|
|
*
|
|
* @param {object} params
|
|
* @param {string} params.senderId - Provider sender ID
|
|
* @param {string} params.toNumber - Destination phone number
|
|
* @param {string} params.content - Resolved template content
|
|
* @returns {Promise<{ success: boolean, statusCode: number, response: any }>}
|
|
*/
|
|
async function sendViaWorkflow({ senderId, toNumber, content }) {
|
|
const workflowUrl = process.env.WORKFLOW_URL_TEST_SMS;
|
|
|
|
if (!workflowUrl || !workflowUrl.trim()) {
|
|
throw new Error('WORKFLOW_URL_TEST_SMS is not configured');
|
|
}
|
|
|
|
const payload = { senderId, toNumber, content };
|
|
|
|
const response = await axios.post(workflowUrl.trim(), payload, {
|
|
timeout: 20000,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
validateStatus: () => true, // relay all status codes; don't throw on 4xx/5xx
|
|
});
|
|
|
|
return {
|
|
success: response.status >= 200 && response.status < 300,
|
|
statusCode: response.status,
|
|
response: response.data,
|
|
};
|
|
}
|
|
|
|
module.exports = { sendViaWorkflow };
|