protected override async Task OnMessageActivityAsync()

in dri/issueNotificationBot/Bot/Bots/SignInBot.cs [48:120]


        protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var handled = false;

            turnContext.Activity.RemoveMentionText(turnContext.Activity.Recipient.Id);

            //If the user sends the Login Command and we don't have their info, send them through the auth dialog
            if (string.Equals(turnContext.Activity.Text, Constants.LoginCommand, StringComparison.InvariantCultureIgnoreCase) ||
                !await UserStorage.HaveUserDetails(turnContext.Activity.From.Id))
            {
                // We don't want to send the OAuth card to a group conversation
                if (turnContext.Activity.Conversation.ConversationType == Constants.PersonalConversationType)
                {
                    Logger.LogInformation($"Running SignInDialog for {turnContext.Activity.From.Name}");

                    await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
                }
                else
                {
                    Logger.LogInformation($"{turnContext.Activity.From.Name} sent the bot a message from a Group channel and we don't have their information.");

                    await turnContext.SendActivityAsync(Constants.NoOAuthInGroupConversationsResponse);
                }

                handled = true;
            }

            // Handle maintainer commands
            if (Maintainer == null)
            {
                Maintainer = await UserStorage.GetTrackedUserFromGitHubUserId(Constants.MaintainerGitHubId);
            }

            // Check if Maintainer name matches incoming. ID seems to change between bots.
            if (!handled && turnContext.Activity.From.Name == Maintainer?.TeamsUserInfo.Name)
            {
                if (string.Equals(turnContext.Activity.Text, Constants.EnableMaintainerNotificationsCommand, StringComparison.InvariantCultureIgnoreCase))
                {
                    Logger.LogInformation("Enabling Maintainer Notifications");
                    NotificationHelper.NotifyMaintainer = true;
                    await turnContext.SendActivityAsync("Maintainer Notifications Enabled");
                }
                else if (string.Equals(turnContext.Activity.Text, Constants.DisableMaintainerNotificationsCommand, StringComparison.InvariantCultureIgnoreCase))
                {
                    Logger.LogInformation("Disabling Maintainer Notifications");
                    NotificationHelper.NotifyMaintainer = false;
                    await turnContext.SendActivityAsync("Maintainer Notifications Disabled");
                }
                else if (string.Equals(turnContext.Activity.Text, Constants.MaintainerTestCards, StringComparison.InvariantCultureIgnoreCase))
                {
                    await SendMaintainerTestCards(turnContext);
                }
                else if (string.Equals(turnContext.Activity.Text, Constants.MaintainerResendGreetings, StringComparison.InvariantCultureIgnoreCase))
                {
                    await ResendGreetings(turnContext, cancellationToken);
                }

                handled = true;
            }

            // Check for and catch Adaptive Card Submit actions
            if (!handled)
            {
                handled = await HandleAdaptiveCardSubmitActions(turnContext, cancellationToken);
            }

            // Bot doesn't know how to handle anything else
            if (!handled)
            {
                Logger.LogInformation($"Unable to handle message: {turnContext.Activity.Text} from: {turnContext.Activity.From.Name}");
                await turnContext.SendActivityAsync(Constants.NoConversationResponse);
            }
        }