コード例 #1
0
ファイル: MeetingState.cs プロジェクト: tpraveex/MeetingBot
        public async Task UpdateAsync(Activity activity, MeetingData inData)
        {
            using (StateClient stateClient = activity.GetStateClient())
            {
                IBotState chatbotState = stateClient.BotState;
                BotData   chatbotData  = await chatbotState.GetUserDataAsync(
                    activity.ChannelId, activity.From.Id);

                MeetingData meetingData =
                    chatbotData.GetProperty <MeetingData>(MeetingDataProperty);

                if (meetingData == null)
                {
                    meetingData = new MeetingData();
                }

                meetingData.UserChannelID = activity.From.Id;
                meetingData.UserDBID      = inData.UserDBID;
                meetingData.Dialog        = inData.Dialog;
                meetingData.Method        = inData.Method;

                chatbotData.SetProperty(MeetingDataProperty, data: meetingData);
                await chatbotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, chatbotData);
            }
        }
コード例 #2
0
        public async Task <string> GetResponseAsync(ConnectorClient connector, Activity activity)
        {
            MeetingData mtgData = await mtgState.GetAsync(activity);

            string response;

            switch (mtgData?.Method)
            {
            case nameof(HandleNameResponseAsync):
                response = await HandleNameResponseAsync(activity, mtgData);

                break;

            case nameof(HandleEmailResponseAsync):
                response = await HandleEmailResponseAsync(activity, mtgData);

                break;

            default:
                response = StartRegistration(ref mtgData);
                break;
            }

            await mtgState.UpdateAsync(activity, mtgData);

            return(response);
        }
コード例 #3
0
        string StartRegistration(ref MeetingData mtgData)
        {
            if (mtgData == null)
            {
                mtgData = new MeetingData();
            }

            mtgData.Dialog = nameof(RegistrationDialog);
            mtgData.Method = nameof(HandleEmailResponseAsync);

            return("What is your email?");
        }
コード例 #4
0
        public async Task <string> GetResponseAsync(ConnectorClient connector, Activity activity)
        {
            //Activity typingActivity = activity.BuildTypingActivity();
            //await connector.Conversations.ReplyToActivityAsync(typingActivity);
            //await Task.Delay(millisecondsDelay: 10000);

            IDialogResponse dialog;

            MeetingData mtgData = await new MeetingState().GetAsync(activity);

            switch (mtgData?.Dialog)
            {
            case nameof(RegistrationDialog):
            default:
                dialog = new RegistrationDialog();
                break;
            }

            return(await dialog.GetResponseAsync(connector, activity));
        }
コード例 #5
0
        async Task <string> HandleEmailResponseAsync(Activity activity, MeetingData mtgData)
        {
            string userEmail = activity.Text;

            using (var ctx = new MeetingContext())
            {
                User user =
                    await
                        (from usr in ctx.Users
                        where usr.UserID == mtgData.UserDBID ||
                        usr.Email == userEmail
                        select usr)
                    .SingleOrDefaultAsync();

                if (user == null)
                {
                    user = new User
                    {
                        Email = userEmail,
                        Name  = userEmail
                    };
                    ctx.Users.Add(user);
                }
                else
                {
                    user.Email = userEmail;
                }

                await ctx.SaveChangesAsync();

                mtgData.UserChannelID = activity.From.Id;
                mtgData.UserDBID      = user.UserID;
            }

            mtgData.Method = nameof(HandleNameResponseAsync);

            return("What is your name?");
        }
コード例 #6
0
        async Task <string> HandleNameResponseAsync(Activity activity, MeetingData mtgData)
        {
            using (var ctx = new MeetingContext())
            {
                User user =
                    await
                        (from usr in ctx.Users
                        where usr.UserID == mtgData.UserDBID
                        select usr)
                    .SingleOrDefaultAsync();

                if (user == null)
                {
                    user = new User
                    {
                        Email = activity.Text,
                        Name  = activity.Text
                    };
                    ctx.Users.Add(user);
                }
                else
                {
                    user.Name = activity.Text;
                }

                await ctx.SaveChangesAsync();

                mtgData.UserChannelID = activity.From.Id;
                mtgData.UserDBID      = user.UserID;
            }

            mtgData.Dialog = string.Empty;
            mtgData.Method = string.Empty;

            return("Registration succeeded!");
        }