So they have this nice example inside the EchoBot sample to demonstrate chains
public static readonly IDialog<string> dialog = Chain.PostToChain()
.Select(msg => msg.Text)
.Switch(
new Case<string, IDialog<string>>(text =>
{
var regex = new Regex("^reset");
return regex.Match(text).Success;
}, (context, txt) =>
{
return Chain.From(() => new PromptDialog.PromptConfirm("Are you sure you want to reset the count?",
"Didn't get that!", 3)).ContinueWith<bool, string>(async (ctx, res) =>
{
string reply;
if (await res)
{
ctx.UserData.SetValue("count", 0);
reply = "Reset count.";
}
else
{
reply = "Did not reset count.";
}
return Chain.Return(reply);
});
}),
new RegexCase<IDialog<string>>(new Regex("^help", RegexOptions.IgnoreCase), (context, txt) =>
{
return Chain.Return("I am a simple echo dialog with a counter! Reset my counter by typing \"reset\"!");
}),
new DefaultCase<string, IDialog<string>>((context, txt) =>
{
int count;
context.UserData.TryGetValue("count", out count);
context.UserData.SetValue("count", ++count);
string reply = string.Format("{0}: You said {1}", count, txt);
return Chain.Return(reply);
}))
.Unwrap()
.PostToUser();
}
However instead of using a REGEX to determine my conversation path I would much rather use a LUIS Intent. I'm using this nice piece of code to extract the LUIS Intent.
public static async Task<LUISQuery> ParseUserInput(string strInput)
{
string strRet = string.Empty;
string strEscaped = Uri.EscapeDataString(strInput);
using (var client = new HttpClient())
{
string uri = Constants.Keys.LUISQueryUrl + strEscaped;
HttpResponseMessage msg = await client.GetAsync(uri);
if (msg.IsSuccessStatusCode)
{
var jsonResponse = await msg.Content.ReadAsStringAsync();
var _Data = JsonConvert.DeserializeObject<LUISQuery>(jsonResponse);
return _Data;
}
}
return null;
}
Now unfortunately because this is async it doesn't play well with the LINQ query to run the case statement. Can anyone provide me some code that will allow me to have a case statement inside my chain based on LUIS Intents?