protected virtual async Task MessageReceived(IDialogContext context, IAwaitable <IMessageActivity> item) { if (this.handlerByIntent == null) { this.handlerByIntent = new Dictionary <string, IntentActivityHandler>(GetHandlersByIntent()); } var message = await item; var messageText = await GetLuisQueryTextAsync(context, message); // TODO: obtain CancellationToken from IPostToBot.PostAsync var tasks = this.services.Select(s => s.QueryAsync(messageText, CancellationToken.None)).ToArray(); var winner = this.BestResultFrom(await Task.WhenAll(tasks)); IntentActivityHandler handler = null; if (winner == null || !this.handlerByIntent.TryGetValue(winner.BestIntent.Intent, out handler)) { handler = this.handlerByIntent[string.Empty]; } if (handler != null) { await handler(context, item, winner?.Result); } else { var text = $"No default intent handler found."; throw new Exception(text); } }
protected virtual async Task DispatchToIntentHandler(IDialogContext context, IAwaitable <IMessageActivity> item, IntentRecommendation bestIntent, LuisResult result) { if (this.handlerByIntent == null) { this.handlerByIntent = new Dictionary <string, IntentActivityHandler>(GetHandlersByIntent()); } IntentActivityHandler handler = null; if (result == null || !this.handlerByIntent.TryGetValue(bestIntent.Intent, out handler)) { handler = this.handlerByIntent[string.Empty]; } if (handler != null) { await handler(context, item, result); } else { var text = $"No default intent handler found."; throw new Exception(text); } }