/// <summary> /// Builds a welcome dialog, shown on conversation start /// </summary> /// <param name="dialogs">the dialog collection</param> /// <param name="factory">the factory used to create dialogs</param> /// <param name="dialogName">the name of the dialog</param> /// <param name="nextStep">the next step to go to in the chain</param> /// <returns> /// The <see cref="DialogSet"/>. /// </returns> public static DialogSet WithWelcome( this DialogSet dialogs, IDialogFactory <DialogSet> factory, string dialogName, IDialogStep nextStep) { return(factory.BuildWelcomeDialog(dialogs, dialogName, nextStep)); }
/// <summary> /// Builds a free-text entry prompt /// </summary> /// <param name="dialogs">the dialog collection</param> /// <param name="factory">the factory used to create dialogs</param> /// <param name="dialogName">the name of the prompt</param> /// <param name="prompt">the text to display to a user</param> /// <param name="nextStep">the name of the step to proceed to</param> /// <returns> /// The <see cref="DialogSet"/>. /// </returns> public static DialogSet WithFreeTextEntry( this DialogSet dialogs, IDialogFactory <DialogSet> factory, string dialogName, string prompt, IDialogStep nextStep) { return(factory.BuildFreeTextDialog(dialogs, dialogName, prompt, nextStep)); }
/// <summary> /// Builds a dynamic ending dialog, based on previous dialog score. /// </summary> /// <param name="dialogs">The dialog collection</param> /// <param name="factory">The factory used to create dialogs</param> /// <param name="dialogName">The name of the dialog</param> /// <param name="requiredScore">The score required for a positive ending</param> /// <param name="positiveEnd">The next step in case of a positive ending</param> /// <param name="negativeEnd">The next step in case of a negative ending</param> /// <returns> /// The <see cref="DialogSet"/>. /// </returns> public static DialogSet WithDynamicEnd( this DialogSet dialogs, IDialogFactory <DialogSet> factory, string dialogName, int requiredScore, IDialogStep positiveEnd, IDialogStep negativeEnd) { return(factory.BuildDynamicEndDialog(dialogs, dialogName, requiredScore, positiveEnd, negativeEnd)); }
/// <summary> /// Builds a new branching dialog with binary yes/no answers. /// </summary> /// <param name="dialogs"> The dialogs collection. </param> /// <param name="factory"> The factory used for building dialogs. </param> /// <param name="dialogName"> The name of the dialog to create. </param> /// <param name="prompt"> The prompt used for asking a question. </param> /// <param name="positivePath"> The next step in the event of a positive answer. </param> /// <param name="negativePath"> The next step in the event of a negative answer. </param> /// <returns> The <see cref="DialogSet"/>. </returns> public static DialogSet WithBranch( this DialogSet dialogs, IDialogFactory <DialogSet> factory, string dialogName, string prompt, IDialogStep positivePath, IDialogStep negativePath) { return(factory.BuildBranchingDialog(dialogs, dialogName, prompt, positivePath, negativePath)); }
/// <inheritdoc /> public DialogSet BuildBranchingDialog( DialogSet dialogs, string dialogName, string prompt, IDialogStep positiveBranch, IDialogStep negativeBranch) { dialogs.Add( dialogName, new WaterfallStep[] { async(dc, args, next) => { await dc.Context.AddRealisticTypingDelay(prompt, this.TypingSpeed, this.TypingDelay); await dc.Prompt( "confirmationPrompt", prompt, FormHelper.ConfirmationPromptOptions); }, async(dc, args, next) => { SurveyState state = dc.Context.GetConversationState <SurveyState>(); UserState userState = dc.Context.GetUserState <UserState>(); bool positive = args["Value"] is FoundChoice response && response.Value == "yes"; IDialogStep activeBranch; if (positive) { state.SurveyScore++; activeBranch = positiveBranch; } else { state.SurveyScore--; activeBranch = negativeBranch; } this.logger.LogDebug( $"{userState.UserName} has a survey score of {state.SurveyScore} which has triggered the {(positive ? "positive" : "negative")} conversation tree"); await dc.End(dc.ActiveDialog.State); foreach (var r in activeBranch.Responses) { await dc.Context.SendActivity( r, inputHint: InputHints.IgnoringInput); await dc.Context.AddRealisticTypingDelay(r, this.TypingSpeed, this.TypingDelay); } await dc.Begin(activeBranch.DialogTarget); }, async(dc, args, next) => { await dc.End(); } });
/// <summary> /// Initializes a new instance of the <see cref="ApprenticeFeedbackV3"/> class. /// Creates a simple Apprentice Feedback survey conversation /// </summary> /// <param name="dialogFactory"> the factory to be used for creating dialogs </param> /// <param name="resources"> /// The object to be used for string localization. /// Must match the class name of the <see cref="IApprenticeFeedbackSurvey"/> implementation, and have a corresponding Resources (*.resx) file in the Resources folder. /// </param> public ApprenticeFeedbackV3(IDialogFactory <DialogSet> dialogFactory, IApprenticeFeedbackResources resources) { // Create the steps IDialogStep step1 = FormHelper.BuildConversationPath("daysOfTraining").WithResponse(resources.IntroWelcome) .WithResponse(resources.IntroOptOut); IDialogStep step2Positive = FormHelper.BuildConversationPath("trainerKnowledge") .WithResponse(resources.ResponsesPositive01); IDialogStep step2Negative = FormHelper.BuildConversationPath("trainerKnowledge") .WithResponse(resources.ResponsesNegative01); IDialogStep step3Positive = FormHelper.BuildConversationPath("overallSatisfaction") .WithResponse(resources.ResponsesPositive02); IDialogStep step3Negative = FormHelper.BuildConversationPath("overallSatisfaction") .WithResponse(resources.ResponsesNegative02); IDialogStep step4Positive = FormHelper.BuildConversationPath("finish") .WithResponse(resources.ResponsesItsReallyHelpful); IDialogStep step4Negative = FormHelper.BuildConversationPath("finish") .WithResponse(resources.ResponsesSorryToHearThat); IDialogStep positiveEnd = FormHelper.BuildConversationEndOption().WithResponse(resources.FinishKeepUpTheGoodWork); IDialogStep negativeEnd = FormHelper.BuildConversationEndOption() .WithResponse(resources.FinishSpeakToYourEmployer).WithResponse(resources.FinishFormalComplaint); // Build the conversation, tying the steps together this.Dialogs = dialogFactory.Conversation() .WithChoicePrompt(dialogFactory, "confirmationPrompt", ListStyle.None) .WithWelcome(dialogFactory, "start", step1) .WithBranch( dialogFactory, "daysOfTraining", resources.QuestionsDaysOfTraining, step2Positive, step2Negative) .WithBranch( dialogFactory, "trainerKnowledge", resources.QuestionsTrainerKnowledge, step3Positive, step3Negative) .WithBranch( dialogFactory, "overallSatisfaction", resources.QuestionsOverallSatisfaction, step4Positive, step4Negative).WithDynamicEnd(dialogFactory, "finish", 3, positiveEnd, negativeEnd); }
public RegistrationFarmRoomDialog(ISocketMessageChannel context) : base(context) { Result = new Channel() { Id = Channel.Id, ChannelRole = ChannelRole.Farm }; Steps = new List <IDialogStep>() { new ServerNameStep(), new FractionStep(), new WordPartStep() }; CurrentStep = Steps[0]; SendAnswer().Wait(); }
internal async Task SendAnswer(SocketUserMessage message = null) { if (message != null) { DialogMessages.Add(message); } await ClearChat(); if (message == null) { var rest = await Channel.SendMessageAsync(CurrentStep.Description); DialogMessages.Add(rest); return; } try { CurrentStep.TakeValue(message, Result); } catch (DialogValueException ex) { var rest = await Channel.SendMessageAsync($"{ex.Message}"); DialogMessages.Add(rest); return; } if (IsHaveNextStep()) { CurrentStep = Steps[Steps.IndexOf(CurrentStep) + 1]; var rest = await Channel.SendMessageAsync(CurrentStep.Description); DialogMessages.Add(rest); } else { Finish(); } }
/// <summary> /// Creates a response to a dialog tree answer given by a user /// </summary> /// <param name="option">the dialog step to tie the response to</param> /// <param name="response">the text response to echo to the user</param> /// <returns>See <see cref="IDialogStep"/></returns> public static IDialogStep WithResponse(this IDialogStep option, string response) { option.Responses.Add(response); return(option); }