コード例 #1
0
ファイル: RootDialog.cs プロジェクト: enordberg/msbot
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            var text = message.Text.ToLower();

            if (text.Equals("hi") || text.Equals("hello"))
            {
                await context.Forward(new GreetingDialog(), this.AfterGreeting, message, CancellationToken.None);
            }
            else if (text.Equals("feedback") || text.Equals("rate"))
            {
                await context.PostAsync("Starting feedback form.  Type help - if needed.");

                context.Call(Feedback.BuildFormDialog(FormOptions.PromptInStart), FeedbackComplete);
            }
            else if (text.Equals("credits"))
            {
                await context.PostAsync("created for Code Camp by Eric Nordberg");

                context.Wait(MessageReceivedAsync);
            }
            else if (text.Contains("bots"))
            {
                await context.PostAsync("I'll tell you about other GMI Bots.");

                await context.Forward(new BotsDialog(), this.AfterBots, message, CancellationToken.None);
            }
            else if (text.Contains("thank"))
            {
                await context.PostAsync("You are welcome.");

                context.Wait(MessageReceivedAsync);
            }
            else if (text.Equals("bye"))
            {
                string username = null;
                context.UserData.TryGetValue("Name", out username);
                await context.PostAsync($"see you later {username ?? "alligator"}");

                context.Wait(MessageReceivedAsync);
            }
            else if (text.Equals("help"))
            {
                await context.PostAsync("Try the following commands... hi, feedback, list bots, credits, bye.");

                context.Wait(MessageReceivedAsync);
            }
            else
            {
                await context.PostAsync("I'm sorry.  I don't know what you mean.");

                context.Wait(MessageReceivedAsync);
            }
        }