Ejemplo n.º 1
0
        private async Task <DialogTurnResult> LoopStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var choice = (FoundChoice)stepContext.Result;
            var done   = stepContext.Values.ContainsKey(DoneKey);
            var state  = stepContext.Values[StateKey] as ChatState;

            Debug.Print("Done state is {0}\n", done);

            if (!done)
            {
                Debug.Print("Not done\n");
                QuestionStanza qs = proc.GetStanza(state.CurrentStanzaID) as QuestionStanza;
                for (int i = 0; i < qs.Answers.Length; i += 1)
                {
                    if (choice.Value == proc.GetPhrase(qs.Answers[i]).Internal)
                    {
                        state.CurrentStanzaID = qs.Next[i];
                        break;
                    }
                }
                return(await stepContext.ReplaceDialogAsync(nameof(OcelotDialog), state, cancellationToken));
            }
            else
            {
                Debug.Print("Really done\n");
                stepContext.Values[StateKey] = null;
                return(await stepContext.EndDialogAsync(state, cancellationToken));
            }
        }
Ejemplo n.º 2
0
        private PromptOptions BuildOptions(WaterfallStepContext stepContext, ChatState state)
        {
            Stanza current = null;
            string text    = "";

            while (true)
            {
                current = proc.GetStanza(state.CurrentStanzaID);
                if (text.Length > 0)
                {
                    text += "\n";
                }

                text += proc.GetPhrase(((InstructionStanza)current).Text).Internal;

                if (!current.HasNext || current.StanzaType == "Question" || current.Next[0] == "end")
                {
                    break;
                }
                state.CurrentStanzaID = current.Next[0];
            }

            if (current.StanzaType == "Question")
            {
                QuestionStanza qs = (QuestionStanza)current;

                IList <Choice> choices = new List <Choice>();

                for (int i = 0; i < qs.Answers.Length; i += 1)
                {
                    var choice = new Choice
                    {
                        Value = proc.GetPhrase(qs.Answers[i]).Internal
                    };
                    if (choice.Value.ToLower().StartsWith("yes"))
                    {
                        choice.Synonyms = new List <string> {
                            "yes", "yup", "y"
                        };
                    }
                    else if (choice.Value.ToLower().StartsWith("no"))
                    {
                        choice.Synonyms = new List <string> {
                            "no", "nope", "n"
                        };
                    }
                    choices.Add(choice);
                }

                return(new PromptOptions {
                    Prompt = MessageFactory.Text(text), Choices = choices.ToArray()
                });
            }

            if (!current.HasNext || current.Next[0] == "end")
            {
                stepContext.Values[DoneKey] = true;
            }

            return(new PromptOptions {
                Prompt = MessageFactory.Text(text), Choices = ChoiceFactory.ToChoices(new string[] { "OK" })
            });
        }