/// <summary>
        /// Updates team installation status in store. If the bot is installed, the info is saved, otherwise info for the team is deleted.
        /// </summary>
        /// <param name="team">The team installation info</param>
        /// <param name="installed">Value that indicates if bot is installed</param>
        /// <returns>Tracking task</returns>
        public async Task UpdateTeamInstallStatusAsync(TeamInstallInfo team, bool installed)
        {
            await this.EnsureInitializedAsync();

            if (installed)
            {
                var response = await this.documentClient.UpsertDocumentAsync(this.teamsCollection.SelfLink, team);
            }
            else
            {
                var documentUri = UriFactory.CreateDocumentUri(this.database.Id, this.teamsCollection.Id, team.Id);
                var response    = await this.documentClient.DeleteDocumentAsync(documentUri, new RequestOptions { PartitionKey = new PartitionKey(team.Id) });
            }
        }
Example #2
0
        /// <summary>
        /// Create a new turn context and execute callback parameter to do desired function
        /// </summary>
        /// <param name="botAdapter">Bot adapter.</param>
        /// <param name="teamInfo">The team that the bot has been installed to</param>
        /// <param name="callback">The method to call for the resulting bot turn.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        private async Task ExecuteInNewTurnContext(BotAdapter botAdapter, TeamInstallInfo teamInfo, BotCallbackHandler callback)
        {
            var conversationReference = new ConversationReference
            {
                ServiceUrl   = teamInfo.ServiceUrl,
                Conversation = new ConversationAccount
                {
                    Id = teamInfo.TeamId,
                },
            };

            await botAdapter.ContinueConversationAsync(
                this.botId,
                conversationReference,
                callback,
                default(CancellationToken)).ConfigureAwait(false);
        }
        /// <summary>
        /// Update the team install info
        /// </summary>
        /// <param name="team">team info to update</param>
        /// <returns>Whether the update was successful</returns>
        public async Task <bool> UpdateTeamInstallInfoAsync(TeamInstallInfo team)
        {
            await this.EnsureInitializedAsync();

            try
            {
                var result = await this.documentClient.UpsertDocumentAsync(this.teamsCollection.SelfLink, team);

                return(true);
            }
            catch (Exception ex)
            {
                this.telemetryClient.TrackTrace($"Error updating team install info for {team.TeamId}", SeverityLevel.Error);
                this.telemetryClient.TrackException(ex.InnerException);
            }

            return(false);
        }
Example #4
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);
        }
Example #5
0
        /// <summary>
        /// Get the name of a team.
        /// </summary>
        /// <param name="botAdapter">Bot adapter.</param>
        /// <param name="teamInfo">DB team model info.</param>
        /// <returns>The name of the team</returns>
        public virtual async Task <string> GetTeamNameByIdAsync(BotAdapter botAdapter, TeamInstallInfo teamInfo)
        {
            TeamDetails teamDetails = null;

            await this.ExecuteInNewTurnContext(botAdapter, teamInfo, async (newTurnContext, newCancellationToken) =>
            {
                teamDetails = await this.GetTeamDetailsAsync(newTurnContext, teamInfo.TeamId, newCancellationToken);
            });

            return(teamDetails?.Name);
        }