コード例 #1
0
        public async Task LengthCheckPromptTest(ITurnContext context)
        {
            dynamic conversationState = ConversationState <StoreItem> .Get(context);

            TextPrompt askForName = new TextPrompt(MinLengthValidator);

            if (conversationState["topic"] != "textPromptTest")
            {
                conversationState["topic"] = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var textResult = await askForName.Recognize(context);

                if (textResult.Succeeded())
                {
                    await context.SendActivity(textResult.Value);
                }
                else
                {
                    await context.SendActivity(textResult.Status.ToString());
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Every Conversation turn for our Bot will call this method. In here
        /// the bot checks the Activty type to verify it's a message, bumps the
        /// turn conversation 'Turn' count, and then echoes the users typing
        /// back to them.
        /// </summary>
        /// <param name="context">Turn scoped context containing all the data needed
        /// for processing this conversation turn. </param>
        public async Task OnTurn(ITurnContext context)
        {
            // O bot só irá tratar mensagens.
            if (context.Activity.Type == ActivityTypes.Message)
            {
                // Obtenho o estado da conversação.
                BotSimplesState state      = context.GetConversationState <BotSimplesState>();
                TextPrompt      promptNome = new TextPrompt();

                if (!state.PergunteiNome)
                {
                    state.PergunteiNome = true;
                    await promptNome.Prompt(context, "Qual o seu nome ?");
                }
                else
                {
                    TextResult nome = await promptNome.Recognize(context);

                    if (!nome.Succeeded())
                    {
                        await promptNome.Prompt(context, "Desculpe, pode repetir ?");
                    }
                    else
                    {
                        state.PergunteiNome = false;
                        await context.SendActivity($"Oi {nome.Value}, seja bem vindo ao nosso chat de teste.");
                    }
                }
            }
        }
コード例 #3
0
        public async Task LengthCheckPromptTest(IBotContext context)
        {
            dynamic conversationState = ConversationState <StoreItem> .Get(context);

            TextPrompt askForName = new TextPrompt(MinLengthValidator);

            if (conversationState["topic"] != "textPromptTest")
            {
                conversationState["topic"] = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var text = await askForName.Recognize(context);

                if (text != null)
                {
                    context.Reply("Passed");
                    context.Reply(text);
                }
                else
                {
                    context.Reply("Failed");
                }
            }
        }
コード例 #4
0
        public async Task MyTestPrompt(IBotContext context)
        {
            dynamic conversationState = ConversationState <StoreItem> .Get(context);

            TextPrompt askForName = new TextPrompt();

            if (conversationState["topic"] != "textPromptTest")
            {
                conversationState["topic"] = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var textResult = await askForName.Recognize(context);

                if (textResult.Succeeded())
                {
                    context.Reply(textResult.Value);
                }
                else
                {
                    context.Reply(textResult.Status.ToString());
                }
            }
        }
コード例 #5
0
        public async Task MyTestPrompt(ITurnContext context)
        {
            var        conversationState = context.GetConversationState <PromptState>();
            TextPrompt askForName        = new TextPrompt();

            if (conversationState.Topic != "textPromptTest")
            {
                conversationState.Topic = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var textResult = await askForName.Recognize(context);

                if (textResult.Succeeded())
                {
                    await context.SendActivity(textResult.Value);
                }
                else
                {
                    await context.SendActivity(textResult.Status.ToString());
                }
            }
        }
コード例 #6
0
        public async Task OnTurn(ITurnContext context)
        {
            if (context.Activity.Type == ActivityTypes.Message)
            {
                var state = context.GetConversationState <SimplePromptState>();

                // Name prompt
                if (!state.PromptinName && !state.PromptinAge)
                {
                    // Prompt for Name
                    state.PromptinName = true;
                    await namePrompt.Prompt(context, "Hello! What is your name?");
                }
                else if (state.PromptinName)
                {
                    // Attempt to recognize the user name
                    var name = await namePrompt.Recognize(context);

                    if (!name.Succeeded())
                    {
                        // Not recognized, re-prompt
                        await namePrompt.Prompt(context, "Sorry, I didn't get that. What is your name?");
                    }
                    else
                    {
                        // Save name and set next state
                        state.Name         = name.Value;
                        state.PromptinName = false;
                    }
                }

                // Age Prompt
                if (!string.IsNullOrEmpty(state.Name) && state.Age == 0)
                {
                    // Prompt for age
                    if (!state.PromptinAge)
                    {
                        state.PromptinAge = true;
                        await agePrompt.Prompt(context, $"How old are you, {state.Name}?");
                    }
                    else
                    {
                        var age = await agePrompt.Recognize(context);

                        if (!age.Succeeded())
                        {
                            // Not recognized, re-prompt
                            await agePrompt.Prompt(context, "Sorry, that doesn't look right. Ages 13 to 90 only. What is your age?");
                        }
                        else
                        {
                            // Save age and continue
                            state.Age         = age.Value;
                            state.PromptinAge = false;
                        }
                    }
                }

                // Display provided information (if complete)
                if (!string.IsNullOrEmpty(state.Name) && state.Age != 0)
                {
                    await context.SendActivity($"Hello {state.Name}, You are {state.Age}.");

                    // Reset sample by clearing state
                    state.Name = null;
                    state.Age  = 0;
                }
            }
        }