Пример #1
0
        // Handle conversation update event (in personal scope)
        private async Task HandlePersonalConversationUpdateAsync(Activity activity)
        {
            this.logProvider.LogInfo($"Handling personal conversationUpdate in thread {activity.Conversation.Id}");

            // In personal scope we only handle events with MembersAdded
            var isBotAdded = activity.MembersAdded?.Any(member => member.Id == activity.Recipient.Id);

            if (isBotAdded == true)
            {
                var user = activity.From;
                this.logProvider.LogInfo($"Conversation was created with user {user.Id}");

                var objectId = user.Properties["aadObjectId"].ToString();
                var userInfo = await this.userManagementHelper.GetUserByAadObjectIdAsync(objectId);

                if (userInfo?.InstallationMethod != BotScope.Team)
                {
                    // Only send a welcome message to the users who were not previously seen in team scope
                    var reply = activity.CreateReply();
                    reply.Attachments.Add(CelebrationCard.GetWelcomeCardForInstaller().ToAttachment());
                    await this.connectorClient.Conversations.SendToConversationWithRetriesAsync(reply);
                }
                else
                {
                    this.logProvider.LogInfo($"Welcome message for {user.Id} was already sent in team scope");
                }
            }
        }
        /// <summary>
        /// Send welcome message in general channel.
        /// </summary>
        /// <param name="activity">Activity instance.</param>
        /// <param name="isBotInstalledInTeam">true/false.</param>
        /// <param name="installerName">bot installer name.</param>
        /// <param name="teamName">TeamName</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private async Task SendWelcomeMessageToGeneralChannel(Activity activity, bool isBotInstalledInTeam, string installerName, string teamName)
        {
            this.logProvider.LogInfo("Sending welcome message to general channel.");

            Activity     welcomeActivity = activity.CreateReply();
            AdaptiveCard welcomeCard;

            if (isBotInstalledInTeam)
            {
                welcomeCard = CelebrationCard.GetWelcomeMessageForGeneralChannelAndTeamMembers(installerName, teamName);
            }
            else
            {
                welcomeCard = CelebrationCard.GetWelcomeCardForInstaller();
            }

            this.logProvider.LogInfo($"Welcome card json: {welcomeCard.ToJson()}");

            welcomeActivity.Attachments.Add(welcomeCard.ToAttachment());
            await this.connectorClient.Conversations.ReplyToActivityAsync(welcomeActivity);

            this.logProvider.LogInfo("Welcome message sent to general Chanel.");
        }