Skip to content

Commit 02be753

Browse files
authored
Merge pull request #414 from iceljc/features/refine-save-state-by-args
refine save state by args
2 parents 1814304 + 8af7466 commit 02be753

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public Dictionary<string, string> Load(string conversationId, bool isReadOnly =
127127
_historyStates = _db.GetConversationStates(conversationId);
128128
var dialogs = _db.GetConversationDialogs(conversationId);
129129
var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User || x.MetaData?.Role == UserRole.Client)
130+
.GroupBy(x => x.MetaData?.MessageId)
131+
.Select(g => g.First())
130132
.OrderBy(x => x.MetaData?.CreateTime)
131133
.ToList();
132134
var curMsgIndex = userDialogs.FindIndex(x => !string.IsNullOrEmpty(curMsgId) && x.MetaData?.MessageId == curMsgId);
@@ -342,9 +344,17 @@ public void SaveStateByArgs(JsonDocument args)
342344
{
343345
foreach (JsonProperty property in root.EnumerateObject())
344346
{
345-
if (!string.IsNullOrEmpty(property.Value.ToString()))
347+
var propertyValue = property.Value;
348+
var stateValue = propertyValue.ToString();
349+
if (!string.IsNullOrEmpty(stateValue))
346350
{
347-
SetState(property.Name, property.Value, source: StateSource.Application);
351+
if (propertyValue.ValueKind == JsonValueKind.True ||
352+
propertyValue.ValueKind == JsonValueKind.False)
353+
{
354+
stateValue = stateValue?.ToLower();
355+
}
356+
357+
SetState(property.Name, stateValue, source: StateSource.Application);
348358
}
349359
}
350360
}

0 commit comments

Comments
 (0)