Skip to content

Commit 0520edd

Browse files
committed
Fill response parameters.
1 parent c84ac36 commit 0520edd

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using BotSharp.Platform.Abstraction;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace BotSharp.Core.ContextStorage
7+
{
8+
public class ContextStorageInFile : IContextStorage
9+
{
10+
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace BotSharp.Platform.Abstraction
6+
{
7+
public interface IContextStorage
8+
{
9+
}
10+
}

BotSharp.Platform.Dialogflow/DialogflowAi.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public override async Task<TResult> AssembleResult<TResult>(AiResponse response)
133133
});
134134

135135
var matches = Regex.Matches(presetResponse.Messages.Random().Speech, "\".*?\"").Cast<Match>();
136-
var speech = matches.ToList().Random();
136+
var speech = matches.Count() == 0 ? String.Empty : matches.ToList().Random().Value;
137+
138+
var contexts = HandleContexts(presetResponse);
137139

138140
var aiResponse = new AIResponseResult
139141
{
@@ -143,17 +145,33 @@ public override async Task<TResult> AssembleResult<TResult>(AiResponse response)
143145
{
144146
IntentName = response.Intent
145147
},
148+
Intent = response.Intent,
146149
Fulfillment = new AIResponseFulfillment
147150
{
148151
Messages = presetResponse.Messages.ToList<object>(),
149-
Speech = speech.Value.Substring(1, speech.Length - 2)
152+
Speech = speech.Length > 1 ? speech.Substring(1, speech.Length - 2) : String.Empty
150153
},
151154
Score = response.Score,
152155
Source = response.Source,
156+
Contexts = contexts.ToArray(),
153157
Parameters = presetResponse.Parameters.Where(x => !String.IsNullOrEmpty(x.Value)).ToDictionary(item => item.Name, item => (object)item.Value)
154158
};
155159

156160
return (TResult)(object)aiResponse;
157161
}
162+
163+
private List<AIContext> HandleContexts(IntentResponse response)
164+
{
165+
var newContexts = response.Contexts.Select(x => new AIContext
166+
{
167+
Name = x.Name,
168+
Lifespan = x.Lifespan,
169+
Parameters = response.Parameters.Select(p => new KeyValuePair<string, object>(p.Name, p.Value)).ToDictionary(d => d.Key, d => d.Value == null ? String.Empty : d.Value)
170+
}).ToList();
171+
172+
// persist
173+
174+
return newContexts;
175+
}
158176
}
159177
}

0 commit comments

Comments
 (0)