private async Task <DialogTurnResult> CallTrain(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var trainResponses = stepContext.Values[QnAData] as List <QueryResult>; var currentQuery = stepContext.Values[CurrentQuery] as string; var reply = stepContext.Context.Activity.Text; var dialogOptions = GetDialogOptionsValue(stepContext); var qnaDialogResponseOptions = dialogOptions[QnADialogResponseOptions] as QnADialogResponseOptions; if (trainResponses.Count > 1) { var qnaResult = trainResponses.FirstOrDefault(kvp => kvp.Questions[0] == reply); if (qnaResult != null) { stepContext.Values[QnAData] = new List <QueryResult>() { qnaResult }; var records = new FeedbackRecord[] { new FeedbackRecord { UserId = stepContext.Context.Activity.Id, UserQuestion = currentQuery, QnaId = qnaResult.Id, } }; var feedbackRecords = new FeedbackRecords { Records = records }; // Call Active Learning Train API await _services.QnAMakerService.CallTrainAsync(feedbackRecords).ConfigureAwait(false); return(await stepContext.NextAsync(new List <QueryResult>() { qnaResult }, cancellationToken).ConfigureAwait(false)); } else if (reply.Equals(qnaDialogResponseOptions.CardNoMatchText, StringComparison.OrdinalIgnoreCase)) { await stepContext.Context.SendActivityAsync(qnaDialogResponseOptions.CardNoMatchResponse, cancellationToken : cancellationToken).ConfigureAwait(false); return(await stepContext.EndDialogAsync().ConfigureAwait(false)); } else { return(await stepContext.ReplaceDialogAsync(QnAMakerDialogName, stepContext.ActiveDialog.State["options"], cancellationToken).ConfigureAwait(false)); } } return(await stepContext.NextAsync(stepContext.Result, cancellationToken).ConfigureAwait(false)); }
private async Task <DialogTurnResult> CallTrain(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var trainResponses = stepContext.Values[QnAData] as List <QueryResult>; var currentQuery = stepContext.Values[CurrentQuery] as string; var reply = stepContext.Context.Activity.Text; if (trainResponses.Count() > 1) { var qnaResult = trainResponses.Where(kvp => kvp.Questions[0] == reply).FirstOrDefault(); if (qnaResult != null) { stepContext.Values[QnAData] = new List <QueryResult>() { qnaResult }; var records = new FeedbackRecord[] { new FeedbackRecord { UserId = stepContext.Context.Activity.Id, UserQuestion = currentQuery, QnaId = qnaResult.Id, } }; var feedbackRecords = new FeedbackRecords { Records = records }; // Call Active Learning Train API await _services.QnAMakerService.CallTrainAsync(feedbackRecords); return(await stepContext.NextAsync(new List <QueryResult>(){ qnaResult }, cancellationToken)); } else if (reply.Equals(cardNoMatchText)) { await stepContext.Context.SendActivityAsync(cardNoMatchResponse, cancellationToken : cancellationToken); return(await stepContext.EndDialogAsync()); } else { return(await stepContext.ReplaceDialogAsync(ActiveLearningDialogName, stepContext.ActiveDialog.State["options"], cancellationToken)); } } return(await stepContext.NextAsync(stepContext.Result, cancellationToken)); }
private QnAMakerDialogHelper GetDialogHelper(IDialogContext context, CustomQnAMakerResults qnaResult) { var message = context.Activity.AsMessageActivity(); FeedbackRecord feedback = null; if (message != null) { feedback = new FeedbackRecord { UserId = message.From.Id, UserQuestion = message.Text }; } return(new QnAMakerDialogHelper(qnaResult, feedback, _qnAService)); }
// Will only be included if _feedbackOptions.FeedbackEnabled is set to true private async Task <DialogTurnResult> RequestFeedbackComment(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Clear feedback state await _feedbackAccessor.DeleteAsync(stepContext.Context).ConfigureAwait(false); var userResponse = stepContext.Context.Activity.Text; if (userResponse == (string)_feedbackOptions.DismissAction.Value) { // user dismissed feedback action prompt return(await stepContext.NextAsync()); } var botResponses = await _previousResponseAccessor.GetAsync(stepContext.Context, () => new List <Activity>()); // Get last activity of previous dialog to send with feedback data var feedbackActivity = botResponses.Count >= 2 ? botResponses[botResponses.Count - 2] : botResponses.LastOrDefault(); var record = new FeedbackRecord() { Request = feedbackActivity, Tag = "EndOfDialogFeedback" }; if (_feedbackOptions.FeedbackActions.Any(f => userResponse == (string)f.Value)) { // user selected a feedback action record.Feedback = userResponse; await _feedbackAccessor.SetAsync(stepContext.Context, record).ConfigureAwait(false); if (_feedbackOptions.CommentsEnabled) { return(await stepContext.PromptAsync(DialogIds.FeedbackPrompt, new PromptOptions() { Prompt = FeedbackUtil.GetFeedbackCommentPrompt(stepContext.Context), })); } else { return(await stepContext.NextAsync()); } } else { // user sent a query unrelated to feedback return(await stepContext.NextAsync(new FeedbackUtil.RouteQueryFlag { RouteQuery = true })); } }
private static async Task ProcessCmdMessage(FeedbackRecord record) { using (var db = new IsmIoTPortalContext()) { // Achtung .Substring(4), weil die ersten 3 Zeichen das Präfix "CMD" sind int CommandId = Convert.ToInt32(record.OriginalMessageId.Substring(4)); // Beim Senden des Commands wurde der Schlüssel des DB Eintrages als MessageId angegeben var entry = db.Commands.Where(c => c.CommandId == CommandId).First(); // Es gibt natürlich nur ein DB Eintrag mit dem Schlüssel CommandId if (record.StatusCode == FeedbackStatusCode.Success) { db.Entry(entry).Entity.CommandStatus = CommandStatus.SUCCESS; } else // Rejected,... { db.Entry(entry).Entity.CommandStatus = CommandStatus.FAILURE; } db.Entry(entry).State = EntityState.Modified; db.SaveChanges(); await signalRHelper.IsmDevicesIndexChangedTask(); } }
private async void UpdateDeviceRecord(FeedbackRecord record, DateTime enqueuDateTime) { Trace.TraceInformation( "{0}{0}*** Processing Feedback Record ***{0}{0}DeviceId: {1}{0}OriginalMessageId: {2}{0}Result: {3}{0}{0}", Console.Out.NewLine, record.DeviceId, record.OriginalMessageId, record.StatusCode); var device = await _deviceLogic.GetDeviceAsync(record.DeviceId); var existingCommand = device?.CommandHistory.FirstOrDefault(x => x.MessageId == record.OriginalMessageId); if (existingCommand == null) { return; } var updatedTime = record.EnqueuedTimeUtc; if (updatedTime == default(DateTime)) { updatedTime = enqueuDateTime == default(DateTime) ? DateTime.UtcNow : enqueuDateTime; } existingCommand.UpdatedTime = updatedTime; existingCommand.Result = record.StatusCode.ToString(); if (record.StatusCode == FeedbackStatusCode.Success) { existingCommand.ErrorMessage = string.Empty; } await _deviceLogic.UpdateDeviceAsync(device); }
private async Task <DialogTurnResult> CallTrainAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var dialogOptions = ObjectPath.GetPathValue <QnAMakerDialogOptions>(stepContext.ActiveDialog.State, Options); var trainResponses = stepContext.Values[ValueProperty.QnAData] as List <QueryResult>; var currentQuery = stepContext.Values[ValueProperty.CurrentQuery] as string; var reply = stepContext.Context.Activity.Text; if (trainResponses.Count > 1) { var qnaResult = trainResponses.FirstOrDefault(kvp => kvp.Questions[0] == reply); if (qnaResult != null) { stepContext.Values[ValueProperty.QnAData] = new List <QueryResult>() { qnaResult }; var records = new FeedbackRecord[] { new FeedbackRecord { UserId = stepContext.Context.Activity.Id, UserQuestion = currentQuery, QnaId = qnaResult.Id, } }; var feedbackRecords = new FeedbackRecords { Records = records }; // Call Active Learning Train API var qnaClient = await GetQnAMakerClientAsync(stepContext).ConfigureAwait(false); await qnaClient.CallTrainAsync(feedbackRecords).ConfigureAwait(false); return(await stepContext.NextAsync(new List <QueryResult>() { qnaResult }, cancellationToken).ConfigureAwait(false)); } else if (reply.Equals(dialogOptions.ResponseOptions.CardNoMatchText, StringComparison.OrdinalIgnoreCase)) { var activity = dialogOptions.ResponseOptions.CardNoMatchResponse; if (activity == null) { await stepContext.Context.SendActivityAsync(DefaultCardNoMatchResponse, cancellationToken : cancellationToken).ConfigureAwait(false); } else { await stepContext.Context.SendActivityAsync(activity, cancellationToken : cancellationToken).ConfigureAwait(false); } return(await stepContext.EndDialogAsync().ConfigureAwait(false)); } else { // restart the waterfall to step 0 return(await RunStepAsync(stepContext, index : 0, reason : DialogReason.BeginCalled, result : null, cancellationToken : cancellationToken).ConfigureAwait(false)); } } return(await stepContext.NextAsync(stepContext.Result, cancellationToken).ConfigureAwait(false)); }
public bool IsCanBePrintByStatus(FeedbackRecord record) { bool result = false; if (record != null && record.ID > 0L) { if (record.DocumentType_PrintStyle == 2) { result = false; } else if (record.DocumentType_PrintStyle == 0) { result = true; } else if (record.DocumentType_PrintStyle == 1 && record.Status == (int)U9.VOB.HBHCommon.U9CommonBE.DocStatusData.Approved) { result = true; } } return result; }
public bool IsCurrentPrintable(FeedbackRecord record) { return record != null && (record.DocumentType_PrintStyle == 0 || (record.Status == (int)U9.VOB.HBHCommon.U9CommonBE.DocStatusData.Approved && record.DocumentType_PrintStyle == 1)); }