No publish if curl fails. This failed after changing sms sending on curl basis insetad of workflows

This commit is contained in:
Ritul Jadhav 2026-04-08 17:50:14 +05:30
parent f3fcc1ef51
commit 6448ad1e32

View File

@ -3483,30 +3483,30 @@ router.post('/:businessId/templates/:slug/publish', async (req, res) => {
} }
const deterministicRender = renderTemplateWithDeterministicSample(tmpl); const deterministicRender = renderTemplateWithDeterministicSample(tmpl);
const publishedTemplate = withTemplateDefaults({
// Mark template as whitelisted ...tmpl,
tmpl.templateId = normalizeText(templateId); templateId: normalizeText(templateId),
tmpl.status = 'whitelisted'; status: 'whitelisted',
tmpl.isRuntimeEnabled = isTemplateRuntimeEnabled(tmpl); isRuntimeEnabled: isTemplateRuntimeEnabled(tmpl),
tmpl.updatedAt = new Date().toISOString(); updatedAt: new Date().toISOString(),
await uploadJSON(folder, slug, tmpl); });
let sendResult; let sendResult;
try { try {
sendResult = await sendTemplateViaCurl({ sendResult = await sendTemplateViaCurl({
boundProfile, boundProfile,
template: tmpl, template: publishedTemplate,
runtimeValues: { runtimeValues: {
content: deterministicRender.content, content: deterministicRender.content,
toNumber: normalizeText(toNumber), toNumber: normalizeText(toNumber),
templateId: tmpl.templateId, templateId: publishedTemplate.templateId,
senderId: boundProfile.provider?.senderId, senderId: boundProfile.provider?.senderId,
dltEntityId: boundProfile.provider?.dltEntityId, dltEntityId: boundProfile.provider?.dltEntityId,
}, },
}); });
} catch (sendErr) { } catch (sendErr) {
return res.status(sendErr.status || 502).json({ return res.status(sendErr.status || 502).json({
error: 'Template published but send failed', error: 'Template send test failed; template not published',
code: sendErr.code, code: sendErr.code,
details: sendErr.details || sendErr.message, details: sendErr.details || sendErr.message,
renderedContent: deterministicRender.content, renderedContent: deterministicRender.content,
@ -3517,7 +3517,7 @@ router.post('/:businessId/templates/:slug/publish', async (req, res) => {
if (!sendResult.success) { if (!sendResult.success) {
return res.status(502).json({ return res.status(502).json({
error: 'Template published but send failed', error: 'Template send test failed; template not published',
code: 'CURL_PROVIDER_ERROR', code: 'CURL_PROVIDER_ERROR',
details: { details: {
statusCode: sendResult.statusCode, statusCode: sendResult.statusCode,
@ -3529,11 +3529,13 @@ router.post('/:businessId/templates/:slug/publish', async (req, res) => {
}); });
} }
await uploadJSON(folder, slug, publishedTemplate);
res.json({ res.json({
success: true, success: true,
renderedContent: deterministicRender.content, renderedContent: deterministicRender.content,
renderState: deterministicRender.renderState, renderState: deterministicRender.renderState,
template: withTemplateDefaults(tmpl), template: publishedTemplate,
transport: sendResult.transport, transport: sendResult.transport,
sendResult, sendResult,
}); });