diff --git a/internal/dialogue/session.go b/internal/dialogue/session.go index 452d27f..a573c99 100644 --- a/internal/dialogue/session.go +++ b/internal/dialogue/session.go @@ -21,6 +21,7 @@ type Slots struct { Time time.Time HasTime bool Key string + Value string // payload for a fact key, mirrors router.Slots.Value HasKey bool Text string Fn string @@ -104,6 +105,9 @@ func InheritSlots(prev, cur Slots) Slots { out.Key = prev.Key out.HasKey = true } + if out.Value == "" && prev.Value != "" { + out.Value = prev.Value + } if out.Text == "" && prev.Text != "" { out.Text = prev.Text } diff --git a/internal/dialogue/session_test.go b/internal/dialogue/session_test.go index 819efa7..735896d 100644 --- a/internal/dialogue/session_test.go +++ b/internal/dialogue/session_test.go @@ -113,4 +113,14 @@ func TestInheritSlots(t *testing.T) { if inherited6.Text != "какая погода в москве" { t.Error("should inherit text when current is empty") } + + prevValue := Slots{Key: "water", HasKey: true, Value: `"drank"`} + inherited7 := InheritSlots(prevValue, Slots{}) + if inherited7.Value != `"drank"` { + t.Error("should inherit value when current is empty") + } + kept := InheritSlots(prevValue, Slots{Value: "2l"}) + if kept.Value != "2l" { + t.Error("should keep current value") + } }