public static async Task <LuisData> ExecuteLuisQuery(IConfiguration configuration, ITurnContext turnContext, CancellationToken cancellationToken) { try { //// Create the LUIS settings from configuration. var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], configuration["LuisAPIHostName"] ); var recognizer = new LuisRecognizer(luisApplication); // The actual call to LUIS var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken); var(intent, score) = recognizerResult.GetTopScoringIntent(); string topintent = intent.ToString().ToLower(); LuisData ld = new LuisData(); ld.intent = "bookingFacility"; ld.intent = topintent; ld.FacilityID = recognizerResult.Entities["FacilityID"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.EmployeeID = recognizerResult.Entities["EmployeeID"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.FacilityType = recognizerResult.Entities["FacilityType"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.FacilityPreference = recognizerResult.Entities["FacilityPreference"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.PersonAmount = recognizerResult.Entities["PersonAmount"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.Floor = recognizerResult.Entities["Floor"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; ld.Date = recognizerResult.Entities["datetimeV2"]?.FirstOrDefault()?.ToString().ToLower() ?? string.Empty; return(ld); } catch (Exception ex) { return(null); } }
public static async Task<LuisData> ExecuteLuisQuery(IConfiguration configuration, ITurnContext turnContext, CancellationToken cancellationToken) { // Create the LUIS settings from configuration. var luisApplication = new LuisApplication( configuration["LuisAppId"], configuration["LuisAPIKey"], configuration["LuisAPIHostName"] ); var recognizer = new LuisRecognizer(luisApplication); // The actual call to LUIS var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken); var (intent, score) = recognizerResult.GetTopScoringIntent(); string topintent = intent.ToString().ToLower(); string entity=recognizerResult.Entities["claimno"]?.FirstOrDefault()?.ToString().ToLower(); LuisData ld = new LuisData(); ld.intent = topintent; ld.claimnumber = entity; return ld; }
// Add QnAMaker /// <summary> /// Every conversation turn for our Echo Bot will call this method. /// There are no dialogs used, since it's "single turn" processing, meaning a single /// request and response. /// </summary> /// <param name="turnContext">A <see cref="ITurnContext"/> containing all the data needed /// for processing this conversation turn. </param> /// <param name="cancellationToken">(Optional) A <see cref="CancellationToken"/> that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A <see cref="Task"/> that represents the work queued to execute.</returns> /// <seealso cref="BotStateSet"/> /// <seealso cref="ConversationState"/> /// <seealso cref="IMiddleware"/> public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { //string uid = turnContext.Activity.From.Id; //string uname = turnContext.Activity.From.Name; var state = await _accessors.UserDataState.GetAsync(turnContext, () => new UserData()); string usertext = string.Empty; string reply = string.Empty; if (turnContext.Activity.Type == ActivityTypes.Message) { try { JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString()); usertext = commandToken["x"].Value <string>(); turnContext.Activity.Text = usertext; } catch (Exception ex) { try { usertext = turnContext.Activity.Text.ToString(); } catch { usertext = turnContext.Activity.Value.ToString(); turnContext.Activity.Text = usertext; } } try { var dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken); var dialogResult = await dialogContext.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { switch (dialogResult.Status) { case DialogTurnStatus.Empty: LuisData ld = new LuisData(); ld = await LuisHelper.ExecuteLuisQuery(Configuration, turnContext, cancellationToken); switch (ld.intent) { case "none": reply = "Sorry did I not understand. I think i am running out of my bot super powers!"; await turnContext.SendActivityAsync(MessageFactory.Text(reply), cancellationToken); break; case "welcome": var response1 = dh.welcomedefault(turnContext); await turnContext.SendActivityAsync(response1, cancellationToken); break; case "bookfacilities": await dialogContext.BeginDialogAsync("booking", ld, cancellationToken); break; case "navigatefacilities": await dialogContext.BeginDialogAsync("navigation", ld, cancellationToken); break; case "endConversation": reply = "Is there anything else i can help you with"; await turnContext.SendActivityAsync(MessageFactory.Text(reply), cancellationToken); break; } break; case DialogTurnStatus.Waiting: // The active dialog is waiting for a response from the user, so do nothing. break; case DialogTurnStatus.Complete: await dialogContext.EndDialogAsync(); break; default: await dialogContext.CancelAllDialogsAsync(); break; } } // Save states in the accessor // Get the conversation state from the turn context. // Set the property using the accessor. await _accessors.UserDataState.SetAsync(turnContext, state); // Save the new state into the conversation state. await _accessors.ConversationState.SaveChangesAsync(turnContext); await _accessors.UserState.SaveChangesAsync(turnContext); } catch (Exception ex) { //dal.InsertErrorLog(state.UserID, "OnTurnAsync", ex.Message.ToString(), "Tech"); } } else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate && turnContext.Activity.MembersAdded.FirstOrDefault()?.Id == turnContext.Activity.Recipient.Id) { var response1 = dh.welcomedefault(turnContext); await turnContext.SendActivityAsync(response1, cancellationToken); } }