Show undefined variable warning before sending messaeg

This commit is contained in:
Muhsin 2022-12-26 15:16:55 +05:30
parent efa3d41ea6
commit ea69d46b9e
4 changed files with 67 additions and 2 deletions

View file

@ -40,3 +40,19 @@ export const getMessageVariables = ({ conversation }) => {
'agent.email': assignee?.email ? assignee?.email : '',
};
};
export const getUndefinedVariablesInMessage = ({ message, variables }) => {
const regex = /{{(.*?)}}/g;
const matches = message.match(regex);
const undefinedVariables = [];
matches.forEach(match => {
const variable = match
.replace('{{', '')
.replace('}}', '')
.trim();
if (!variables[variable]) {
undefinedVariables.push(match);
}
});
return undefinedVariables;
};