Skip to content

Instantly share code, notes, and snippets.

@zelinskiy
Created March 17, 2017 20:45
Show Gist options
  • Select an option

  • Save zelinskiy/d0fd8f55ae100abdd340aed0baeb6523 to your computer and use it in GitHub Desktop.

Select an option

Save zelinskiy/d0fd8f55ae100abdd340aed0baeb6523 to your computer and use it in GitHub Desktop.
using Microsoft.Bot.Builder.Dialogs;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Bot.Connector;
namespace Kirill.Supports
{
public class RequestMaker:LuisDialog<object>
{
public async Task<LuisServiceResult> MakeRequest(
IDialogContext context,
IAwaitable<IMessageActivity> item)
{
var message = await item;
var messageText = await GetLuisQueryTextAsync(context, message);
var tasks = this.services
.Select(s =>
s.QueryAsync(
new Uri(messageText),
context.CancellationToken))
.ToArray();
var results = await Task.WhenAll(tasks);
var winners = from result in results.Select((value, index) => new { value, index })
let resultWinner = BestIntentFrom(result.value)
where resultWinner != null
select new LuisServiceResult(result.value, resultWinner, this.services[result.index]);
return this.BestResultFrom(winners);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment