public async Task TextPrompt() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var prompt = new TextPrompt(); var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new PromptOptions { PromptString = "Enter some text." }); } else if (dialogCompletion.IsCompleted) { var textResult = (TextResult)dialogCompletion.Result; await turnContext.SendActivity($"Bot received the text '{textResult.Value}'."); } }) .Send("hello") .AssertReply("Enter some text.") .Send("some text") .AssertReply("Bot received the text 'some text'.") .StartTest(); }
public async Task OnTurn(ITurnContext context) { var state = ConversationState <Dictionary <string, object> > .Get(context); var prompt = new TextPrompt(); var options = new PromptOptions { PromptString = "Hello, I'm the demo bot. What is your name?" }; switch (context.Activity.Type) { case ActivityTypes.ConversationUpdate: if (context.Activity.MembersAdded[0].Id != context.Activity.Recipient.Id) { await prompt.Begin(context, state, options); } break; case ActivityTypes.Message: var dialogCompletion = await prompt.Continue(context, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(context, state, options); } else if (dialogCompletion.IsCompleted) { var textResult = (Microsoft.Bot.Builder.Prompts.TextResult)dialogCompletion.Result; await context.SendActivity($"Bot received the text '{textResult.Value}'."); } break; } }
public async Task TextPromptValidator() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); PromptValidator <TextResult> validator = async(ctx, result) => { if (result.Value.Length <= 3) { result.Status = PromptStatus.TooSmall; } await Task.CompletedTask; }; await new TestFlow(adapter, async(turnContext) => { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var prompt = new TextPrompt(validator); var dialogCompletion = await prompt.Continue(turnContext, state); if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted) { await prompt.Begin(turnContext, state, new PromptOptions { PromptString = "Enter some text.", RetryPromptString = "Make sure the text is greater than three characters." }); } else if (dialogCompletion.IsCompleted) { var textResult = (TextResult)dialogCompletion.Result; await turnContext.SendActivity($"Bot received the text '{textResult.Value}'."); } }) .Send("hello") .AssertReply("Enter some text.") .Send("hi") .AssertReply("Make sure the text is greater than three characters.") .Send("hello") .AssertReply("Bot received the text 'hello'.") .StartTest(); }