/// <inheritdoc/>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            if (dc.Context.Activity.ChannelId != Channels.Msteams)
            {
                throw new InvalidOperationException($"{Kind} works only on the Teams channel.");
            }

            string continuationToken = ContinuationToken.GetValueOrNull(dc.State);
            string teamId            = TeamId.GetValueOrNull(dc.State);
            int?   pageSize          = PageSize.GetValueOrNull(dc.State);

            var result = await TeamsInfo.GetPagedTeamMembersAsync(dc.Context, teamId, continuationToken, pageSize, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (Property != null)
            {
                dc.State.SetValue(Property.GetValue(dc.State), result);
            }

            return(await dc.EndDialogAsync(result, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Get team members.
        /// </summary>
        /// <param name="botAdapter">Bot adapter.</param>
        /// <param name="teamInfo">The team that the bot has been installed to</param>
        /// <returns>List of team members channel accounts</returns>
        public virtual async Task <IList <ChannelAccount> > GetTeamMembers(BotAdapter botAdapter, TeamInstallInfo teamInfo)
        {
            var members = new List <ChannelAccount>();

            await this.ExecuteInNewTurnContext(botAdapter, teamInfo, async (turnContext, cancellationToken) =>
            {
                string continuationToken = null;
                do
                {
                    var pagedResult   = await TeamsInfo.GetPagedTeamMembersAsync(turnContext, teamInfo.TeamId, continuationToken, pageSize: 500);
                    continuationToken = pagedResult.ContinuationToken;
                    if (pagedResult.Members != null)
                    {
                        members.AddRange(pagedResult.Members);
                    }
                }while (continuationToken != null);
            });

            return(members);
        }
示例#3
0
        public async Task <IActionResult> GetTeamMembersAsync()
        {
            try
            {
                var cardConfigurationEntity = await this.cardConfigurationStorageProvider?.GetConfigurationAsync();

                string teamId = (cardConfigurationEntity != null) ? cardConfigurationEntity.TeamId : this.options.Value.TeamId;

                var userClaims = this.GetUserClaims();

                var teamsChannelAccounts  = new List <TeamsChannelAccount>();
                var conversationReference = new ConversationReference
                {
                    ChannelId  = teamId,
                    ServiceUrl = userClaims.ApplicationBasePath,
                };

                await this.botAdapter.ContinueConversationAsync(
                    this.appId,
                    conversationReference,
                    async (context, token) =>
                {
                    string continuationToken = null;
                    do
                    {
                        var currentPage   = await TeamsInfo.GetPagedTeamMembersAsync(context, teamId, continuationToken, pageSize: 500, token);
                        continuationToken = currentPage.ContinuationToken;
                        teamsChannelAccounts.AddRange(currentPage.Members);
                    }while (continuationToken != null);
                }, default);

                this.logger.LogInformation("GET call for fetching team members from team roster is successful.");
                return(this.Ok(teamsChannelAccounts.Select(member => new { content = member.Email, header = member.Name, aadobjectid = member.AadObjectId })));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Error occurred while getting team member list.");
                throw;
            }
        }