fix url variable not working
This commit is contained in:
@@ -31,9 +31,12 @@ async function checkIfValidEmail(emailId: string) {
|
|||||||
return { email, domain };
|
return { email, domain };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const replaceVariables = (text: string, variables: Record<string, string>) => {
|
export const replaceVariables = (
|
||||||
|
text: string,
|
||||||
|
variables: Record<string, string>
|
||||||
|
) => {
|
||||||
return Object.keys(variables).reduce((accum, key) => {
|
return Object.keys(variables).reduce((accum, key) => {
|
||||||
const re = new RegExp(`{{${key}}}`, 'g');
|
const re = new RegExp(`{{${key}}}`, "g");
|
||||||
const returnTxt = accum.replace(re, variables[key] as string);
|
const returnTxt = accum.replace(re, variables[key] as string);
|
||||||
return returnTxt;
|
return returnTxt;
|
||||||
}, text);
|
}, text);
|
||||||
@@ -74,10 +77,23 @@ export async function sendEmail(
|
|||||||
const jsonContent = JSON.parse(template.content || "{}");
|
const jsonContent = JSON.parse(template.content || "{}");
|
||||||
const renderer = new EmailRenderer(jsonContent);
|
const renderer = new EmailRenderer(jsonContent);
|
||||||
|
|
||||||
subject = replaceVariables(template.subject || '', variables || {});
|
subject = replaceVariables(template.subject || "", variables || {});
|
||||||
|
|
||||||
|
// {{}} for link replacements
|
||||||
|
const modifiedVariables = {
|
||||||
|
...variables,
|
||||||
|
...Object.keys(variables || {}).reduce(
|
||||||
|
(acc, key) => {
|
||||||
|
acc[`{{${key}}}`] = variables?.[key] || "";
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, string>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
html = await renderer.render({
|
html = await renderer.render({
|
||||||
shouldReplaceVariableValues: true,
|
shouldReplaceVariableValues: true,
|
||||||
variableValues: variables,
|
variableValues: modifiedVariables,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user