Fill response parameters.

This commit is contained in:
haiping008 2018-12-07 15:21:36 -06:00
parent c84ac36288
commit 0520eddc6e
3 changed files with 42 additions and 2 deletions

View file

@ -0,0 +1,12 @@
using BotSharp.Platform.Abstraction;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.ContextStorage
{
public class ContextStorageInFile : IContextStorage
{
}
}

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Abstraction
{
public interface IContextStorage
{
}
}

View file

@ -133,7 +133,9 @@ namespace BotSharp.Platform.Dialogflow
});
var matches = Regex.Matches(presetResponse.Messages.Random().Speech, "\".*?\"").Cast<Match>();
var speech = matches.ToList().Random();
var speech = matches.Count() == 0 ? String.Empty : matches.ToList().Random().Value;
var contexts = HandleContexts(presetResponse);
var aiResponse = new AIResponseResult
{
@ -143,17 +145,33 @@ namespace BotSharp.Platform.Dialogflow
{
IntentName = response.Intent
},
Intent = response.Intent,
Fulfillment = new AIResponseFulfillment
{
Messages = presetResponse.Messages.ToList<object>(),
Speech = speech.Value.Substring(1, speech.Length - 2)
Speech = speech.Length > 1 ? speech.Substring(1, speech.Length - 2) : String.Empty
},
Score = response.Score,
Source = response.Source,
Contexts = contexts.ToArray(),
Parameters = presetResponse.Parameters.Where(x => !String.IsNullOrEmpty(x.Value)).ToDictionary(item => item.Name, item => (object)item.Value)
};
return (TResult)(object)aiResponse;
}
private List<AIContext> HandleContexts(IntentResponse response)
{
var newContexts = response.Contexts.Select(x => new AIContext
{
Name = x.Name,
Lifespan = x.Lifespan,
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)
}).ToList();
// persist
return newContexts;
}
}
}