예제 #1
0
 private async void OpenFeedbackCard(FeedbackCard card)
 {
     if (!string.IsNullOrWhiteSpace(card.Link))
     {
         await Launcher.LaunchUriAsync(new Uri(card.Link));
     }
 }
예제 #2
0
        /// <summary>
        /// Method to submit new hire feedback to storage.
        /// </summary>
        /// <param name="turnContext">Provides context for a turn of a bot.</param>
        /// <returns>Notification message after successful storing of feedback.</returns>
        public async Task SubmitFeedbackAsync(ITurnContext <IMessageActivity> turnContext)
        {
            var activity = turnContext?.Activity;

            var feedbackText = JObject.Parse(activity.Value.ToString()).Properties().Where(row => row.Name == CardConstants.FeedbackTextInputId).ToList().First()?.Value?.ToString();

            if (string.IsNullOrWhiteSpace(feedbackText))
            {
                IMessageActivity updateCard = MessageFactory.Attachment(FeedbackCard.GetFeedbackCardAttachment(this.localizer, isErrorMessageVisible: true));
                updateCard.Id = activity.ReplyToId;
                await turnContext.UpdateActivityAsync(updateCard);

                return;
            }

            var currentMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.UtcNow.Month);

            FeedbackEntity feedbackEntity = new FeedbackEntity
            {
                NewHireAadObjectId = turnContext.Activity.From.AadObjectId,
                Feedback           = feedbackText,
                Id          = Guid.NewGuid().ToString(),
                BatchId     = $"{currentMonth.Substring(0, 3)}_{DateTime.UtcNow.Year}",
                NewHireName = turnContext.Activity.From.Name,
                SubmittedOn = DateTime.UtcNow,
            };

            await this.feedbackProvider.StoreOrUpdateFeedbackAsync(feedbackEntity);

            this.logger.LogInformation($"Feedback submitted by userId: {turnContext.Activity.From.AadObjectId}");
            await turnContext.SendActivityAsync(this.localizer.GetString("FeedbackSuccessMessageText"));
        }
예제 #3
0
    public static FeedbackCard GenerateFeedbackCard(string feedbackCardData)
    {
        FeedbackCard newFeedbackCard = new FeedbackCard();

        string[] cardInformation = feedbackCardData.Split(',');

        newFeedbackCard.SetValues(cardInformation);

        return(newFeedbackCard);
    }
 /// <summary>
 /// Enable and display a given Tips card
 /// </summary>
 /// <param name="feedbackCard"></param>
 public void DisplayTipsCard(FeedbackCard feedbackCard)
 {
     tipsCardObject.GetComponent <InSceneTipsCard>().SetText(feedbackCard.Text);
     tipsCardObject.SetActive(true);
     Swipe.Instance.SetSwipingAllowed(false);
 }
예제 #5
0
 public static void SetValues(this FeedbackCard feedbackCard, string[] cardData)
 {
     feedbackCard.CardID     = int.Parse(cardData[0]);
     feedbackCard.NextCardID = int.Parse(cardData[1]);
     feedbackCard.Text       = cardData[2];
 }
        /// <summary>
        /// Handle when a message is addressed to the bot.
        /// </summary>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>A Task resolving to either a login card or the adaptive card of the Reddit post.</returns>
        /// <remarks>
        /// For more information on bot messaging in Teams, see the documentation
        /// https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-basics?tabs=dotnet#receive-a-message .
        /// </remarks>
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext));

            this.RecordEvent(nameof(this.OnMessageActivityAsync), turnContext);
            var activity = turnContext.Activity;
            var command  = activity.Text.ToUpperInvariant().Trim();

            await this.SendTypingIndicatorAsync(turnContext);

            if (activity.Conversation.ConversationType == CardConstants.PersonalConversationType)
            {
                var userGraphAccessToken = await this.tokenHelper.GetUserTokenAsync(activity.From.Id);

                if (userGraphAccessToken == null)
                {
                    await this.dialog.RunAsync(turnContext, this.conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);

                    return;
                }

                // Command to send feedback card.
                if (command.Equals(this.localizer.GetString("ShareFeedbackText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var shareFeedbackCardActivity = MessageFactory.Attachment(FeedbackCard.GetFeedbackCardAttachment(this.localizer));
                    await turnContext.SendActivityAsync(shareFeedbackCardActivity, cancellationToken);

                    return;
                }

                // Command to save feedback.
                else if (command.Equals(this.localizer.GetString("SubmitFeedbackCommandText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    await this.activityHelper.SubmitFeedbackAsync(turnContext);

                    return;
                }

                // Command to send on-boarding checklist card.
                else if (command.Equals(this.localizer.GetString("OnBoardingCheckListText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var userDetail = await this.userStorageProvider.GetUserDetailAsync(activity.From.AadObjectId);

                    bool isNewHire = userDetail?.UserRole == (int)UserRole.NewHire;

                    // Learning plan bot command supports only for new hire.
                    if (!isNewHire)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Attachment(OnBoardingCheckListCard.GetCard(this.localizer, this.botOptions.Value.ManifestId)));

                        return;
                    }

                    await this.learningPlanHelper.GetWeeklyLearningPlanCardAsync(turnContext, userDetail.BotInstalledOn);
                }

                // Bot sign-out command.
                else if (command.Equals(this.localizer.GetString("LogoutText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    await this.dialog.RunAsync(turnContext, this.conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);

                    return;
                }

                // Command to send more info card to new hire employee.
                else if (command.Equals(this.localizer.GetString("RequestMoreInfoText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var valuesfromCard = ((JObject)activity.Value).ToObject <AdaptiveSubmitActionData>();
                    await this.activityHelper.RequestMoreInfoActionAsync(turnContext, valuesfromCard, cancellationToken);

                    return;
                }

                // Command to send user tour based on his role.
                else if (command.Equals(this.localizer.GetString("HelpText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var userDetail = await this.userStorageProvider.GetUserDetailAsync(activity.From.AadObjectId);

                    bool isManager = userDetail?.UserRole == (int)UserRole.HiringManager;

                    // Send help cards based on their role.
                    await turnContext.SendActivityAsync(MessageFactory.Carousel(CarouselCard.GetUserHelpCards(
                                                                                    this.botOptions.Value.AppBaseUri,
                                                                                    this.localizer,
                                                                                    this.botOptions.Value.ManifestId,
                                                                                    isManager)));

                    return;
                }

                // Command to send pending review introduction list card.
                else if (command.Equals(this.localizer.GetString("ReviewIntroductionText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var user = await this.userStorageProvider.GetUserDetailAsync(activity.From.AadObjectId);

                    if (user != null && user.UserRole != (int)UserRole.HiringManager)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Attachment(HelpCard.GetCard(this.localizer)));

                        return;
                    }

                    var introductionEntities = await this.introductionStorageProvider.GetFilteredIntroductionsAsync(activity.From.AadObjectId);

                    if (!introductionEntities.Any())
                    {
                        await turnContext.SendActivityAsync(this.localizer.GetString("NoPendingIntroductionText"));

                        return;
                    }

                    var batchCount = (int)Math.Ceiling((double)introductionEntities.Count() / ListCardItemsLimit);
                    for (int batchIndex = 0; batchIndex < batchCount; batchIndex++)
                    {
                        var batchWiseIntroductionEntities = introductionEntities
                                                            .Skip(batchIndex * ListCardItemsLimit)
                                                            .Take(ListCardItemsLimit);

                        var listCardAttachment = await this.introductionCardHelper.GetReviewIntroductionListCardAsync(batchWiseIntroductionEntities, userGraphAccessToken);

                        await turnContext.SendActivityAsync(MessageFactory.Attachment(listCardAttachment));
                    }

                    return;
                }

                // Command to send week wise learning plan cards.
                else if (command.Equals(this.localizer.GetString("ViewLearningText").ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    var userDetail = await this.userStorageProvider.GetUserDetailAsync(activity.From.AadObjectId);

                    await this.learningPlanHelper.GetWeeklyLearningPlanCardAsync(turnContext, userDetail.BotInstalledOn);
                }

                // Command to resume/pause all matches.
                else if (command.Equals(BotCommandConstants.ResumeAllMatches, StringComparison.InvariantCultureIgnoreCase) ||
                         command.Equals(BotCommandConstants.PauseAllMatches, StringComparison.InvariantCultureIgnoreCase))
                {
                    await this.activityHelper.GetUpdatedMatchesStatusAsync(turnContext, command, cancellationToken);
                }
                else
                {
                    // If message is from complete learning plan list item tap event.
                    if (command.StartsWith(this.localizer.GetString("ViewWeeklyLearningPlanCommandText"), StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Get learning plan card selected from complete learning plan list card.
                        var learningCard = await this.learningPlanHelper.GetLearningPlanCardAsync(command);

                        // Send learning plan data card.
                        await turnContext.SendActivityAsync(MessageFactory.Attachment(learningCard));
                    }
                    else if (command.StartsWith(this.localizer.GetString("ReviewIntroductionCommandText"), StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Get all Introductions for given Azure Active directory id.
                        if (command.Split(":").Length != 2 || string.IsNullOrWhiteSpace(command.Split(":")[1]))
                        {
                            await turnContext.SendActivityAsync(this.localizer.GetString("ReviewIntroductionInvalidCommandText"));

                            return;
                        }

                        var result = await this.introductionStorageProvider.GetAllIntroductionsAsync(activity.From.AadObjectId);

                        var introductionEntity = result.Where(entity => entity.NewHireName.ToUpperInvariant() == command.Split(":")[1].ToUpperInvariant()).FirstOrDefault();
                        if (introductionEntity != null && (introductionEntity.ApprovalStatus == (int)IntroductionStatus.Approved))
                        {
                            // Send already approved message to hiring manager.
                            await turnContext.SendActivityAsync(this.localizer.GetString("ManagerApprovalValidationText"));
                        }
                        else
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Attachment(HiringManagerNotificationCard.GetNewEmployeeIntroductionCard(this.botOptions.Value.AppBaseUri, this.localizer, introductionEntity)));
                        }
                    }
                    else
                    {
                        // Send help card for un supported bot command.
                        await turnContext.SendActivityAsync(MessageFactory.Attachment(HelpCard.GetCard(this.localizer)));
                    }

                    return;
                }
            }
            else
            {
                await turnContext.SendActivityAsync(this.localizer.GetString("UnSupportedBotCommand"));
            }
        }
예제 #7
0
        /// <summary>
        /// Generate first feedBackmessage to user1 about meetup with user2
        /// </summary>
        /// <returns>The number of pairups that were made</returns>
        public async Task <int> CreateFeedbackMsgAndNotify()
        {
            this.telemetryClient.TrackTrace("generating feedback msgs");

            var installedTeamsCount = 0;
            var pairsNotifiedCount  = 0;
            var usersNotifiedCount  = 0;

            try
            {
                var teams = await this.dataProvider.InstalledTeamsGet();

                installedTeamsCount = teams.Count;
                this.telemetryClient.TrackTrace($"Generating pairs for {installedTeamsCount} teams");

                foreach (var team in teams)
                {
                    this.telemetryClient.TrackTrace($"Pairing members of team {team.Id}");

                    try
                    {
                        MicrosoftAppCredentials.TrustServiceUrl(team.ServiceUrl);
                        var connectorClient = new ConnectorClient(new Uri(team.ServiceUrl));

                        var allUsers = await connectorClient.Conversations.GetConversationMembersAsync(team.TeamId);

                        var allUsersList = allUsers.Select(x => new { User = x, ChannelAccount = x.AsTeamsChannelAccount() })
                                           .ToList();

                        var startDate  = DateTime.UtcNow.AddDays(-1 * Constants.FeedBackDelayDays);
                        var dbMatchers = await dataProvider.UserMatchInfoSearchByDate(startDate);

                        foreach (var userInfo in allUsersList)
                        {
                            var dbMatch = dbMatchers
                                          .Where(p => p.SenderAadId == userInfo.ChannelAccount.ObjectId)
                                          .OrderByDescending(p => p.Created)
                                          .FirstOrDefault();
                            if (dbMatch != null)
                            {
                                var senderDetails = await dataProvider.UserDetailsGet(dbMatch.SenderAadId);

                                var recipientDetails = await dataProvider.UserDetailsGet(dbMatch.RecipientAadId);

                                var card = FeedbackCard.GetCard(senderDetails?.GivenName, recipientDetails?.GivenName);
                                await NotifyUser(connectorClient, card, userInfo.User, team.TenantId);

                                await dataProvider.BotLastMessageUpdate(
                                    userInfo.ChannelAccount.ObjectId,
                                    userInfo.ChannelAccount.Email,
                                    BotMessageTypes.Fb);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        this.telemetryClient.TrackTrace($"Error pairing up team members: {ex.Message}", SeverityLevel.Warning);
                        this.telemetryClient.TrackException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                this.telemetryClient.TrackTrace($"Error making pairups: {ex.Message}", SeverityLevel.Warning);
                this.telemetryClient.TrackException(ex);
            }

            // Log telemetry about the pairups
            var properties = new Dictionary <string, string>
            {
                { "InstalledTeamsCount", installedTeamsCount.ToString() },
                { "PairsNotifiedCount", pairsNotifiedCount.ToString() },
                { "UsersNotifiedCount", usersNotifiedCount.ToString() },
            };

            this.telemetryClient.TrackEvent("ProcessedPairups", properties);

            this.telemetryClient.TrackTrace($"Made {pairsNotifiedCount} pairups, {usersNotifiedCount} notifications sent");
            return(pairsNotifiedCount);


            return(0);
        }