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