Add option to merge answers for summary

This commit is contained in:
Toastie 2025-02-04 19:30:12 +13:00
parent d8e1863182
commit 78c111be54
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
2 changed files with 18 additions and 2 deletions

View file

@ -134,6 +134,10 @@ public class InterviewStep
[JsonProperty("step-references")]
public Dictionary<string, ReferencedInterviewStep> references = new();
// If set will merge answers with the delimiter, otherwise will overwrite
[JsonProperty("answer-delimiter")]
public string answerDelimiter;
// Possible questions to ask next, an error message, or the end of the interview.
[JsonProperty("steps")]
public Dictionary<string, InterviewStep> steps = new();
@ -203,8 +207,14 @@ public class InterviewStep
if (!string.IsNullOrWhiteSpace(summaryField) && !string.IsNullOrWhiteSpace(answer))
{
// TODO: Add option to merge answers
summary[summaryField] = answer;
if (answerDelimiter != null && summary.Contains(summaryField))
{
summary[summaryField] += answerDelimiter + answer;
}
else
{
summary[summaryField] = answer;
}
}
// This will always contain exactly one or zero children.
@ -305,6 +315,7 @@ public class InterviewStep
}
}
// TODO: Warning for answer-delimiter if there is no summary-field
// TODO: Add url button here when implemented
if (messageType is MessageType.REFERENCE_END)
{

View file

@ -191,6 +191,11 @@
"type": "boolean",
"title": "Add Summary",
"description": "This adds a summary field to the end of the message."
},
"answer-delimiter": {
"type": "string",
"title": "Answer Delimiter",
"description": "If the user has already answered a question with the same summary-field as this step the answer will be merged with the existing answer using this delimiter. If this is not set the old answer will be replaced by the new one."
}
},
"required": [ "message-type" ],