private async Task <OnTurnProperty> DetectIntentAndEntitiesAsync(ITurnContext turnContext) { // Handle card input (if any), update state and return. if (turnContext.Activity.Value != null) { if (turnContext.Activity.Value is JObject) { return(OnTurnProperty.FromCardInput((JObject)turnContext.Activity.Value)); } } // Acknowledge attachments from user. if (turnContext.Activity.Attachments != null && turnContext.Activity.Attachments.Count > 0) { await turnContext.SendActivityAsync("Thanks for sending me that attachment. I'm still learning to process attachments."); return(null); } // Nothing to do for this turn if there is no text specified. if (string.IsNullOrWhiteSpace(turnContext.Activity.Text) || string.IsNullOrWhiteSpace(turnContext.Activity.Text.Trim())) { return(null); } // Call to LUIS recognizer to get intent + entities. var luisResults = await _services.LuisServices[LuisConfiguration].RecognizeAsync(turnContext, default(CancellationToken)); // Return new instance of on turn property from LUIS results. // Leverages static fromLUISResults method. return(OnTurnProperty.FromLuisResults(luisResults)); }
private async Task <DialogTurnResult> BeginWhatCanYouDoDialogAsync(DialogContext innerDc, OnTurnProperty onTurnProperty) { var context = innerDc.Context; // Handle case when user interacted with what can you do card. // What can you do card sends a custom data property with intent name, text value and possible entities. // See ../WhatCanYouDo/Resources/whatCanYouDoCard.json for card definition. var queryProperty = (onTurnProperty.Entities ?? new List <EntityProperty>()).Where(item => string.Compare(item.EntityName, QueryProperty) == 0); if (queryProperty.Count() > 0) { Dictionary <string, string> response; try { response = JsonConvert.DeserializeObject <Dictionary <string, string> >(queryProperty.ElementAtOrDefault(0).Value as string); } catch { await context.SendActivityAsync("Choose a query from the card drop down before you click `Let's talk!`"); return(new DialogTurnResult(DialogTurnStatus.Empty, null)); } if (response.TryGetValue("text", out var text)) { context.Activity.Text = text; await context.SendActivityAsync($"You said: '{context.Activity.Text}'."); } // Create a set a new onturn property await _onTurnAccessor.SetAsync(context, OnTurnProperty.FromCardInput(response)); return(await BeginDialogAsync(innerDc, response)); } return(await innerDc.BeginDialogAsync(WhatCanYouDo.Name)); }