public static async Task <int?> GetVsoIdFromConversation(IDialogContext endUserDialogContext) { int?vsoId = null; try { string status = "not set"; if (endUserDialogContext.ConversationData.TryGetValue("VsoId", out string vsoIdFromConversation)) { int convertedVsoId = Convert.ToInt32(vsoIdFromConversation); status = await VsoHelper.GetProjectStatus(convertedVsoId); if (!status.ToLower().Contains("closed")) { vsoId = convertedVsoId; } } WebApiConfig.TelemetryClient.TrackEvent("GetVsoIdFromConversation", new Dictionary <string, string> { { "class", "HelloDialog" }, { "function", "GetVsoIdFromConversation" }, { "from", endUserDialogContext.Activity.From.Name }, { "vsoId", vsoId != null ? vsoId.ToString() : "not set" }, { "vsoIdStatus", status }, }); } catch (VssServiceException e) { if (e.Message.Contains("does not exist")) { // we might have deleted this item. WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string> { { "class", "HelloDialog" }, { "function", "GetVsoIdFromConversation" }, { "dialog", "HelloDialog" }, { "from", endUserDialogContext.Activity.From.Name } }); return(null); } } catch (System.Exception e) { WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string> { { "class", "HelloDialog" }, { "function", "GetVsoIdFromConversation" }, { "dialog", "HelloDialog" }, { "from", endUserDialogContext.Activity.From.Name } }); throw; } return(vsoId); }
private static async Task SendAutoReplyIfNeeded(IDialogContext context, int?vsoId) { // Check when was the last time we sent message to agent var timeStampWhenLastMessageWasSentByAgent = await OnlineStatus.GetTimeWhenMemberWasLastActive(OnlineStatus.AgentMemberType); var timeSinceLastMessageWasSentByAgent = DateTime.UtcNow.Subtract((DateTime)timeStampWhenLastMessageWasSentByAgent); bool autoReplyWasSentAWhileBack = DateTime.UtcNow.Subtract(GetAutoReplySentOnTimeStamp(context)) .TotalMinutes > MinutesToWaitBeforeSendingAutoReply; if (timeSinceLastMessageWasSentByAgent.TotalMinutes >= MinutesToWaitForAgentOnlineBeforeSendingAutoReply && autoReplyWasSentAWhileBack) { await context.PostWithRetryAsync($"Hi {UserProfileHelper.GetFriendlyName(context)}, " + $"My experts are working on Project #{vsoId}. " + $"Current status of this project is {await VsoHelper.GetProjectStatus((int)vsoId)}. " + "Either experts are busy or offline at the moment. " + $"They were online {timeSinceLastMessageWasSentByAgent.TimeAgo()}. Please wait. "); SetAutoReplySentOnTimeStamp(context); } }