private async Task SendNotes(NeuralLinkModel curLink, ITurnContext turnContext) { foreach (var note in curLink.Notes) { await turnContext.SendActivityAsync(curLink.ApplyFormat(note)); } }
private void SetExpressionType(NeuralLinkModel node) { if (node.NeuralExp != null) { var type = node.NeuralExp.GetType(); cbxExpressionTypes.SelectedItem = type.Name; } else { cbxExpressionTypes.SelectedItem = ExpressionNone; } }
/// <summary> /// Get suggestion from Hint property. /// </summary> /// <param name="curLink"></param> /// <param name="appendCommonActions"></param> /// <returns></returns> public static SuggestedActions GetHintSuggestionActions(this NeuralLinkModel curLink, bool appendCommonActions = true) { var result = new SuggestedActions() { Actions = ParseActionsFromColonFormatString(curLink.NeuralExp.Hint) }; if (appendCommonActions) { result.AppendActions(ParseActionsFromColonFormatString(CommonActionOptions)); } return(result); }
/// <summary> /// Get children nodes suggestion based on ranking. /// </summary> /// <param name="curLink"></param> /// <param name="appendCommonActions"></param> /// <returns></returns> public static SuggestedActions GetChildSuggestionActions(this NeuralLinkModel curLink, bool appendCommonActions = true) { curLink.CildrenRank.Sort((x, y) => y.Value.CompareTo(x.Value)); var result = new SuggestedActions() { Actions = curLink.CildrenRank.Select(id => { var name = DbLinkCollection.GetFieldValue(id.Key, x => x.Name).Result; return(new CardAction { Title = name, Value = id.Key, Type = ActionTypes.PostBack }); }).ToList() }; if (appendCommonActions) { result.AppendActions(ParseActionsFromColonFormatString(CommonActionOptions)); } return(result); }
public static string GetNodeImage(this NeuralLinkModel link) { return(link.CildrenRank.Count > 0 || link.NeuralExp != null ? ValidAction : NoAction); }
private async Task <ResponseType> TakeAction(ITurnContext turnContext, RequestState requestState) { var ret = ResponseType.Continue; var text = turnContext.Activity.Text; var curLink = requestState.CurrentLink; switch (requestState.CurrentState) { case ChatStateType.Start: { await SendResponseForCurrentNode(turnContext, requestState); } break; case ChatStateType.AdvanceChat: { if (string.IsNullOrWhiteSpace(text)) { await SendReply(turnContext, StringsProvider.TryGet(BotResourceKeyConstants.InvalidInput), SuggestionExtension.GetCommonSuggestionActions()); } else { string nextNodeId = null; try { nextNodeId = requestState.PredictNode(text); var nextLink = await DbLinkCollection.FindOneById(nextNodeId); if (nextLink != null) { requestState.StepForward(nextLink); await SendResponseForCurrentNode(turnContext, requestState); } else { await SendReply(turnContext, StringsProvider.TryGet(BotResourceKeyConstants.NoMatchFound), SuggestionExtension.GetCommonSuggestionActions()); } } catch (Exception e) { await SendReply(turnContext, $"ML prediction returned an error: '{e.Message}'. please report this issue to the bot administrator.", SuggestionExtension.GetCommonSuggestionActions("Exit:exit")); } } } break; case ChatStateType.PickNode: { var nextLink = await DbLinkCollection.FindOneById(text); if (nextLink == null) { await turnContext.SendActivityAsync(StringsProvider.TryGet(BotResourceKeyConstants.InvalidInput)); await SendResponseForCurrentNode(turnContext, requestState); } else { curLink = nextLink; requestState.StepForward(curLink); await SendResponseForCurrentNode(turnContext, requestState); } } break; case ChatStateType.RecordFeedback: { switch (text.ToLower()) { case "yes": { var childLink = curLink; NeuralLinkModel parentLink = null; while (requestState.LinkHistory.TryPop(out parentLink)) { await DbLinkCollection.UpdateNeuralRankById(parentLink._id, childLink._id); childLink = parentLink; } ret = ResponseType.End; } break; case "no": ret = ResponseType.End; break; default: await turnContext.SendActivityAsync(StringsProvider.TryGet(BotResourceKeyConstants.InvalidInput)); await SendReply(turnContext, StringsProvider.TryGet(BotResourceKeyConstants.Feedback), SuggestionExtension.GetFeedbackSuggestionActions()); break; } if (ret == ResponseType.End) { await turnContext.SendActivityAsync(StringsProvider.TryGet(BotResourceKeyConstants.ThankYouFeedback)); } } break; case ChatStateType.InvalidInput: case ChatStateType.ExpInput: { await EvaluateExpressionInput(turnContext, requestState); } break; default: break; } return(ret); }