sanity for template filling

This commit is contained in:
Ritul Jadhav 2026-03-27 13:26:02 +05:30
parent 0eb09d66a8
commit ab7944e866
2 changed files with 3 additions and 11 deletions

View File

@ -1,8 +1,5 @@
const COMPANY_ID_QUERY_KEYS = [
'companyId',
'company_id',
'blt-gtw-fc-cid',
'bltt-gtw-f-c-cid',
];
const COMPANY_ID_STORAGE_KEY = 'sms_runtime_company_id';

View File

@ -129,10 +129,6 @@ function normalizeSenderId(value) {
return normalizeText(value).toUpperCase();
}
function renderTemplateWithUsername(template, username) {
return String(template || '').replace(/\{#var#\}/g, normalizeText(username));
}
function isValidCurlCommand(rawCurl) {
return normalizeText(rawCurl).toLowerCase().startsWith('curl');
}
@ -419,15 +415,15 @@ router.delete('/:businessId', async (req, res) => {
// POST /api/businesses/resolve-template
router.post('/resolve-template', async (req, res) => {
try {
console.log('[ResolveTemplate] Incoming payload:', JSON.stringify(req.body, null, 2));
const companyId = getCompanyId(req);
const applicationId = getApplicationId(req);
const event = normalizeText(req.body?.event);
const username = normalizeText(req.body?.username);
if (!companyId) return res.status(400).json({ error: 'companyId is required' });
if (!applicationId) return res.status(400).json({ error: 'applicationId is required' });
if (!event) return res.status(400).json({ error: 'event is required' });
if (!username) return res.status(400).json({ error: 'username is required' });
const business = await findBusinessByApplicationId(companyId, applicationId);
if (!business) {
@ -447,9 +443,8 @@ router.post('/resolve-template', async (req, res) => {
companyId,
applicationId,
event: eventSlug,
username,
templateId: normalizeText(tmpl.templateId),
template: renderTemplateWithUsername(tmpl.selectedTemplate, username),
template: tmpl.selectedTemplate,
});
} catch (err) {
sendRouteError(res, err);