Skip to content

Commit f2ca14a

Browse files
committed
fix(core): gestion des blocs conditionnels imbriqués pour les boutons d'options en fin de message
1 parent 396583d commit f2ca14a

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

app/js/core/chatbot/parsers/helpers/processorsChatbotContent.mjs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,44 @@ export function handleKeywords(line, currentData) {
3030
currentData.keywords.push(line.replace("- ", "").trim());
3131
}
3232

33-
// Gestion des blocs conditionnels si on a du contenu dynamique
33+
// Gestion des blocs conditionnels, éventuellement imbriqués
3434
export function handleDynamicContent(line, currentData, yaml) {
35-
if (yaml && yaml.dynamicContent && regexDynamicContentIfBlock.test(line)) {
36-
currentData.condition =
35+
if (!yaml || !yaml.dynamicContent) return false;
36+
37+
// On initialise la pile si elle n'existe pas
38+
if (!currentData.conditionStack) {
39+
currentData.conditionStack = [];
40+
}
41+
42+
// Bloc d'ouverture `if`
43+
if (regexDynamicContentIfBlock.test(line)) {
44+
const condition =
3745
(line.match(regexDynamicContentIfBlock) &&
3846
line.match(regexDynamicContentIfBlock)[1]) ||
3947
"";
4048

49+
currentData.conditionStack.push(condition);
50+
51+
// Combine toutes les conditions avec &&
52+
currentData.condition = currentData.conditionStack.join(" && ");
4153
currentData.content.push(line + "\n");
4254
currentData.listParsed = true;
4355
return true;
4456
}
45-
if (yaml && yaml.dynamicContent && line.includes("`endif`")) {
46-
currentData.condition = "";
57+
58+
// Bloc de fermeture `endif`
59+
if (line.includes("`endif`")) {
60+
// Retire la condition du niveau d'imbrication actuel
61+
if (currentData.conditionStack.length > 0) {
62+
currentData.conditionStack.pop();
63+
}
64+
65+
currentData.condition = currentData.conditionStack.join(" && ") || "";
4766
currentData.content.push(line + "\n");
4867
currentData.listParsed = true;
4968
return true;
5069
}
70+
5171
return false;
5272
}
5373

0 commit comments

Comments
 (0)