/// <summary>
        /// Gets the email id's of the SME uses who are available for oncallSupport.
        /// </summary>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="onCallSupportDetailSearchService">Provider to search on call support details in Azure Table Storage.</param>
        /// <param name="teamId">Team id to which the message is being sent.</param>
        /// <param name="memoryCache">MemoryCache instance for caching oncallexpert details.</param>
        /// <param name="logger">Sends logs to the Application Insights service.</param>
        /// <returns>string with appended email id's.</returns>
        public static async Task <string> GetOnCallSMEUserListAsync(ITurnContext <IInvokeActivity> turnContext, IOnCallSupportDetailSearchService onCallSupportDetailSearchService, string teamId, IMemoryCache memoryCache, ILogger <RemoteSupportActivityHandler> logger)
        {
            try
            {
                string onCallSMEUsers = string.Empty;

                var onCallSupportDetails = await onCallSupportDetailSearchService?.SearchOnCallSupportTeamAsync(searchQuery : string.Empty, count : 1);

                if (onCallSupportDetails != null && onCallSupportDetails.Any())
                {
                    var onCallSMEDetails = JsonConvert.DeserializeObject <List <OnCallSMEDetail> >(onCallSupportDetails.First().OnCallSMEs);
                    var expertEmailList  = new List <string>();
                    foreach (var onCallSMEDetail in onCallSMEDetails)
                    {
                        var expertDetails = await TeamMemberCacheHelper.GetMemberInfoAsync(memoryCache, turnContext, onCallSMEDetail.ObjectId, teamId, CancellationToken.None);

                        expertEmailList.Add(expertDetails.Email);
                    }

                    onCallSMEUsers = string.Join(", ", expertEmailList);
                }

                return(onCallSMEUsers);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                logger.LogError(ex, "Error in getting the oncallSMEUsers list.");
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Method mentions user in respective channel of which they are part after modifying experts list.
        /// </summary>
        /// <param name="onCallExpertsObjectIds">Collection of on call expert objectIds.</param>
        /// <param name="turnContext">Provides context for a turn of a bot.</param>
        /// <param name="logger">Sends logs to the Application Insights service.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="memoryCache">MemoryCache instance for caching oncallexpert details</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>A task that sends notification in newly created channel and mention its members.</returns>
        internal static async Task <Activity> SendMentionActivityAsync(
            List <string> onCallExpertsObjectIds,
            ITurnContext <IInvokeActivity> turnContext,
            ILogger logger,
            IStringLocalizer <Strings> localizer,
            IMemoryCache memoryCache,
            CancellationToken cancellationToken)
        {
            try
            {
                var mentionText  = new StringBuilder();
                var entities     = new List <Entity>();
                var expertDetail = new OnCallSMEDetail();

                foreach (var expertId in onCallExpertsObjectIds)
                {
                    var onCallExpert = await TeamMemberCacheHelper.GetMemberInfoAsync(memoryCache, turnContext, expertId, null, cancellationToken);

                    expertDetail = new OnCallSMEDetail {
                        Id = onCallExpert.Id, Name = onCallExpert.Name, Email = onCallExpert.Email
                    };

                    var mention = new Mention
                    {
                        Mentioned = new ChannelAccount()
                        {
                            Id   = expertDetail.Id,
                            Name = expertDetail.Name,
                        },
                        Text = $"<at>{HttpUtility.HtmlEncode(expertDetail.Name)}</at>",
                    };
                    entities.Add(mention);
                    mentionText = string.IsNullOrEmpty(mentionText.ToString()) ? mentionText.Append(mention.Text) : mentionText.Append(", ").Append(mention.Text);
                }

                logger.LogInformation("Send message with names mentioned in team channel.");
                var replyActivity = string.IsNullOrEmpty(mentionText.ToString()) ? MessageFactory.Text(localizer.GetString("OnCallListUpdateMessage")) : MessageFactory.Text(localizer.GetString("OnCallExpertMentionText", mentionText.ToString()));
                replyActivity.Entities = entities;
                await turnContext.SendActivityAsync(replyActivity, cancellationToken);

                return(null);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                logger.LogError(ex, $"Error while mentioning channel member in respective channels.");
                return(null);
            }
        }