public static async Task <bool> RelayMessageToAgentIfThereIsAnOpenResearchProject(IDialogContext context) { int?vsoId = await GetResearchVsoIdFromVso(context.Activity.ChannelId, context.Activity.From.Name); if (vsoId == null) { return(false); } var userProfile = await UserProfileHelper.GetUserProfile(context); context.UserData.SetValue(UserProfileHelper.UserProfileKey, userProfile); string agentConversationId = await VsoHelper.GetAgentConversationIdForVso((int)vsoId); if (string.IsNullOrEmpty(agentConversationId)) { return(false); } await context.PostWithRetryAsync("OK, I'll add that to the project."); //await SendAutoReplyIfNeeded(context, vsoId); IMessageActivity messageActivity = (IMessageActivity)context.Activity; if (ActivityHelper.HasAttachment(messageActivity)) { await context.PostWithRetryAsync( $"Sending file attachments is not supported. " + $"Please send it via an accessible link within Microsoft"); } else { await ActivityHelper.SendMessageToAgentAsReplyToConversationInAgentsChannel( messageActivity, messageActivity.Text, agentConversationId, (int)vsoId); } await OnlineStatus.SetMemberActive(context.Activity.From.Name, context.Activity.From.Id, OnlineStatus.EndUserMemberType); return(true); }
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); } }