public virtual async Task ContinueProcess(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            if (string.IsNullOrWhiteSpace(this.Member))
            {
                await this.SelectMemberAsync(context, result);

                return;
            }

            var data = context.UserData.GetValue <UserData>("userData");

            var resultService = await this.workIteService.GetWorkItems(this.Member, data.Account.Value, data.Project.Value, data.User.Token);

            var reply = context.MakeMessage();

            if (resultService.Count == 0)
            {
                reply.Text = string.Format(Labels.NoWorkItems, this.Member);
            }
            else
            {
                reply.Text = string.Join(Environment.NewLine, resultService);
            }

            await context.PostAsync(reply);

            context.Done(reply);

            return;
        }
        /// <summary>
        /// Shows a selection list of accounts to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task SelectAccountAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            var accounts = this.Profiles
                           .SelectMany(a => a.Accounts)
                           .Distinct()
                           .OrderBy(a => a)
                           .ToList();

            reply.Text = Labels.ConnectToAccount;
            await context.PostAsync(reply);

            reply.Text = string.Empty;

            var skip = 0;

            while (skip < accounts.Count)
            {
                reply = context.MakeMessage();
                var local = accounts.Skip(skip).Take(TakeSize).ToList();
                reply.Attachments.Add(new AccountsCard(local));
                await context.PostAsync(reply);

                skip += TakeSize;
            }

            context.Wait(this.AccountReceivedAsync);
        }
Exemple #3
0
        public virtual async Task SelectProjectAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            context.UserData.TryGetValue("userData", out UserData data);

            var resultService = await this.projectService.GetProjects(data.Account.Value, data.User.Token);

            var projects = resultService.ToDictionary(a => a.Id.ToString(), a => a.Name);

            data.User.Projects = projects;

            context.UserData.SetValue("userData", data);

            var reply = context.MakeMessage();

            if (!projects.Any())
            {
                reply.Text = Labels.NoTeamProjects;
                await context.PostAsync(reply);

                context.Done(reply);
                return;
            }

            var projectsCard = new ProjectsCard(projects);

            reply.Text = Labels.ConnectToProject;
            reply.Attachments.Add(projectsCard.ToAttachment());

            await context.PostAsync(reply);

            context.Wait(this.ProjectReceivedAsync);
        }
        public virtual async Task SelectTeamAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            if (!teams.Any())
            {
                reply.Text = Labels.NoTeams;
                await context.PostAsync(reply);

                context.Done(reply);
                return;
            }

            var accountsCard = new TeamsCard(teams);

            reply.Text = Labels.Teams;
            reply.Attachments.Add(accountsCard.ToAttachment());

            await context.PostAsync(reply);

            context.Wait(this.TeamReceivedAsync);
        }
Exemple #5
0
        /// <summary>
        /// Generates a login card and presents it to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task LogOnAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            if (!context.UserData.TryGetValue("userData", out UserData data))
            {
                data = new UserData();
            }

            // Set pin.
            this.Pin = GeneratePin();
            data.Pin = this.Pin;

            context.UserData.SetValue("userData", data);

            var card = new LogOnCard(this.appId, this.appScope, new Uri(this.authorizeUrl), result.ChannelId, result.From.Id);

            var reply = context.MakeMessage();

            reply.Attachments.Add(card);

            await context.PostAsync(reply);

            context.Wait(this.PinReceivedAsync);
        }
        public virtual async Task ContinueProcess(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var data = context.UserData.GetValue <UserData>("userData");

            var resultService = await this.teamService.GetTeams(data.Account.Value, data.Project.Key, data.User.Token);

            teams = resultService.ToDictionary(a => a.Id.ToString(), a => a.Name);

            if (string.IsNullOrWhiteSpace(this.Team))
            {
                await this.SelectTeamAsync(context, result);

                return;
            }

            var team = teams.FirstOrDefault(a => string.Equals(a.Value, this.Team, StringComparison.OrdinalIgnoreCase));

            if (!team.Equals(default(KeyValuePair <string, string>)))
            {
                await this.ShowMembers(context, result);

                return;
            }

            await context.PostAsync(Labels.InvalidTeam);

            context.Done(result);

            return;
        }
        /// <summary>
        /// Shows a selection list of the projects to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task SelectProjectAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            var projects = await this.VstsService.GetProjects(this.Account, this.Profile.Token);

            this.TeamProjects = projects
                                .Select(project => project.Name)
                                .ToList();

            reply.Text = Labels.ConnectToProject;
            await context.PostAsync(reply);

            reply.Text = string.Empty;

            var skip = 0;

            while (skip < this.TeamProjects.Count)
            {
                reply = context.MakeMessage();
                var teamProjects = this.TeamProjects.Skip(skip).Take(TakeSize).ToList();
                reply.Attachments.Add(new ProjectsCard(teamProjects));
                await context.PostAsync(reply);

                skip += TakeSize;
            }

            context.Wait(this.ProjectReceivedAsync);
        }
Exemple #8
0
        /// <summary>
        /// Welcomes a user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task WelcomeAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var message = result as IConversationUpdateActivity;

            if (message == null)
            {
                return;
            }

            if (!message.MembersAdded.Any() || message.MembersAdded.All(m => m.Id.Equals(message.Recipient.Id, StringComparison.OrdinalIgnoreCase)))
            {
                await context.PostAsync(string.Format(Labels.WelcomeUsers, this.licenseUri));
            }

            foreach (var member in message.MembersAdded)
            {
                // Skip if the added member is the bot itself.
                if (string.Equals(member.Id, message.Recipient.Id, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                await context.PostAsync(string.Format(Labels.WelcomeUser, member.Name, this.licenseUri));
            }
        }
        public virtual async Task SelectMemberAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            reply.Text = Labels.Member;

            await context.PostAsync(reply);

            context.Wait(this.MemberReceivedAsync);
        }
Exemple #10
0
        /// <summary>
        /// Continues the process.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task ContinueProcess(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            if (!context.UserData.TryGetValue("userData", out UserData data))
            {
                data = new UserData();
            }

            this.Profile = await this.GetValidatedProfile(context.UserData);

            this.Profiles = data.Profiles;

            var reply = context.MakeMessage();

            // No Profiles, so we have to login.
            if (!this.Profiles.Any() || this.Profile == null)
            {
                await this.LogOnAsync(context, result);

                return;
            }

            // No account, show a list available accounts.
            if (string.IsNullOrWhiteSpace(this.Account))
            {
                await this.SelectAccountAsync(context, result);

                return;
            }

            data.Account = this.Account;

            // No team project, ....
            if (string.IsNullOrWhiteSpace(this.TeamProject))
            {
                await this.SelectProjectAsync(context, result);

                return;
            }

            data.TeamProject = this.TeamProject;

            context.UserData.SetValue("userData", data);

            reply.Text = string.Format(Labels.ConnectedTo, result.From.Name, this.Account, this.TeamProject);
            await context.PostAsync(reply);

            context.Done(reply);
        }
Exemple #11
0
        public virtual async Task WelcomeAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var message = result as IConversationUpdateActivity;

            if (message == null)
            {
                return;
            }

            if (!message.MembersAdded.Any() || message.MembersAdded.All(m => m.Id.Equals(message.Recipient.Id, StringComparison.OrdinalIgnoreCase)))
            {
                await context.PostAsync(Labels.Welcome);
            }
        }
Exemple #12
0
        public virtual async Task ContinueProcess(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            if (!context.UserData.TryGetValue("userData", out UserData data))
            {
                data = new UserData();
            }

            var user = await this.GetValidatedProfile(context.UserData);

            if (user == null)
            {
                await this.LogOnAsync(context, result);

                return;
            }

            var account = data.Account;

            if (account.Equals(default(KeyValuePair <string, string>)))
            {
                await this.SelectAccountAsync(context, result);

                return;
            }

            var project = data.Project;

            if (project.Equals(default(KeyValuePair <string, string>)))
            {
                await this.SelectProjectAsync(context, result);

                return;
            }

            var reply = context.MakeMessage();

            reply.Text = string.Format(Labels.ConnectedTo, data.User.Name, data.Account.Value, data.Project.Value);

            await context.PostAsync(reply);

            context.Done(reply);
        }
        /// <summary>
        /// Continues the process.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task ContinueProcess(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            this.Profile  = context.UserData.GetProfile(this.GetAuthenticationService(result));
            this.Profiles = context.UserData.GetProfiles();

            var reply = context.MakeMessage();

            // No Profiles, so we have to login.
            if (!this.Profiles.Any() || this.Profile == null)
            {
                await this.LogOnAsync(context, result);

                return;
            }

            // No account, show a list available accounts.
            if (string.IsNullOrWhiteSpace(this.Account))
            {
                await this.SelectAccountAsync(context, result);

                return;
            }

            context.UserData.SetAccount(this.Account);

            // No team project, ....
            if (string.IsNullOrWhiteSpace(this.TeamProject))
            {
                await this.SelectProjectAsync(context, result);

                return;
            }

            context.UserData.SetTeamProject(this.TeamProject);

            reply.Text = string.Format(Labels.ConnectedTo, result.From.Name, this.Account, this.TeamProject);
            await context.PostAsync(reply);

            context.Done(reply);
        }
Exemple #14
0
        /// <summary>
        /// Handles any incoming command and route them to the appropriate dialog.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task HandleCommandAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            // Message is coming from a group chat, so skipping if the bot is not explicitly mentioned.
            if (result.Conversation.IsGroup.GetValueOrDefault() && !result.MentionsRecipient())
            {
                context.Wait(this.HandleActivityAsync);
                return;
            }

            var dialog = GlobalConfiguration.Configuration.DependencyResolver.Find(result.RemoveRecipientMention());

            context.UserData.TryGetValue("userData", out UserData data);

            if (dialog == null || (data == null && !(dialog is ConnectDialog)))
            {
                if (data == null)
                {
                    data = new UserData();
                }

                var reply = context.MakeMessage();

                reply.Text = result.Text.Trim().Equals(CommandMatchHelp, StringComparison.OrdinalIgnoreCase)
                    ? Labels.Help
                    : Labels.UnknownCommand;

                reply.Attachments.Add(new MainOptionsCard(!string.IsNullOrEmpty(data.TeamProject)));

                await context.PostAsync(reply);

                context.Wait(this.HandleActivityAsync);
            }
            else
            {
                this.telemetryClient.TrackEvent(result.Text);

                await context.Forward(dialog, this.ResumeAfterChildDialog, result, CancellationToken.None);
            }
        }
        /// <summary>
        /// Shows a selection list of accounts to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task SelectAccountAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            var accounts = this.Profiles
                           .SelectMany(a => a.Accounts)
                           .Distinct()
                           .OrderBy(a => a)
                           .ToList();

            reply.Text = Labels.ConnectToAccount;
            reply.Attachments.Add(new AccountsCard(accounts));

            await context.PostAsync(reply);

            context.Wait(this.AccountReceivedAsync);
        }
        /// <summary>
        /// Shows a selection list of the projects to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task SelectProjectAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var reply = context.MakeMessage();

            var projects = await this.vstsService.GetProjects(this.Account, this.Profile.Token);

            this.TeamProjects = projects
                                .Select(project => project.Name)
                                .ToList();

            reply.Text = Labels.ConnectToProject;
            reply.Attachments.Add(new ProjectsCard(this.TeamProjects));

            await context.PostAsync(reply);

            context.Wait(this.ProjectReceivedAsync);
        }
        /// <summary>
        /// Generates a login card and presents it to the user.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/></param>
        /// <param name="result">A <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task LogOnAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            // Set pin.
            this.Pin = GeneratePin();
            context.UserData.SetPin(this.Pin);

            var vstsApplication = this.VstsApplicationRegistry.GetVstsApplicationRegistration(result.From.Id);

            var card = new LogOnCard(vstsApplication, result.ChannelId, result.From.Id);

            var reply = context.MakeMessage();

            reply.Attachments.Add(card);

            await context.PostAsync(reply);

            context.Wait(this.PinReceivedAsync);
        }
Exemple #18
0
        public virtual async Task HandleCommandAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var text = result.RemoveRecipientMention();

            await context.SendTyping();

            using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, result))
            {
                this.SetLocale(context, result);

                var dialog = scope.Find(text);

                var reply = context.MakeMessage();

                if (dialog == null)
                {
                    reply.Text = Labels.UnknownCommand;

                    await context.PostAsync(reply);

                    context.Wait(this.HandleActivityAsync);
                }
                else if (!(dialog is ConnectDialog) && !IsConnected(context.UserData))
                {
                    reply.Text = Labels.Connect;

                    await context.PostAsync(reply);

                    context.Wait(this.HandleActivityAsync);
                }
                else
                {
                    await context.Forward(dialog, this.ResumeAfterChildDialog, result, CancellationToken.None);
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Handles any incoming command and route them to the appropiate dialog.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task HandleCommandAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            var dialog = GlobalConfiguration.Configuration.DependencyResolver.Find(result.Text);

            if (dialog == null)
            {
                var reply = context.MakeMessage();
                reply.Attachments.Add(new MainOptionsCard());

                await context.PostAsync(reply);

                context.Wait(this.HandleActivityAsync);
            }
            else
            {
                this.telemetryClient.TrackEvent(result.Text);

                await context.Forward(dialog, this.ResumeAfterChildDialog, result, CancellationToken.None);
            }
        }