Skip to content

Commit

Permalink
Added logs for Scrum bot. Updated code so that team leaders can inter…
Browse files Browse the repository at this point in the history
…act with bot. Updated string constants. Fixes#166
  • Loading branch information
julie authored and julie committed Feb 24, 2017
1 parent a898a34 commit bfbd8e4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 47 deletions.
Expand Up @@ -179,12 +179,14 @@ public async Task<string> ProcessMessagesAsync(string slackUserId, string slackC
}
else //when command would be like "leave <@>"
{
replyText = await AddScrumAnswerAsync(slackUserDetail.Name, message, slackChannelId, slackChannelDetail.Name, slackUserDetail.UserId);
replyText = await AddScrumAnswerAsync(slackUserDetail.Name,
message, slackChannelId, slackChannelDetail.Name, slackUserDetail.UserId);
}
}
else //all other texts
{
replyText = await AddScrumAnswerAsync(slackUserDetail.Name, message, slackChannelId, slackChannelDetail.Name, slackUserDetail.UserId);
replyText = await AddScrumAnswerAsync(slackUserDetail.Name, message,
slackChannelId, slackChannelDetail.Name, slackUserDetail.UserId);
}
}
else //channel is not registered in the database
Expand Down Expand Up @@ -259,22 +261,6 @@ public async Task AddTemporaryScrumDetailsAsync(int scrumId, string slackUserId,
#region Private Methods


private bool IsScrumBot(string scrumBotId, string message)
{
//"<@".Length is 2
int fromIndex = message.IndexOf("<@", StringComparison.Ordinal) + 2;
int toIndex = message.LastIndexOf(">", StringComparison.Ordinal);
if (toIndex > 0 && fromIndex > 1)
{
//the slack userId is fetched
string applicantId = message.Substring(fromIndex, toIndex - fromIndex);
if (String.Compare(applicantId, scrumBotId, StringComparison.Ordinal) == 0)
return true;
}
return false;
}


#region Temporary Scrum Details


Expand Down Expand Up @@ -360,6 +346,51 @@ private async Task UpdateTemporaryScrumDetailsAsync(string slackUserId, int scru
#endregion


/// <summary>
/// Check whether the user with the given slack id is ative or not - JJ
/// </summary>
/// <param name="slackUserId"></param>
/// <param name="users"></param>
/// <param name="teamLeaderId"></param>
/// <returns>true if active else false</returns>
private async Task<bool> CheckUserAsync(string slackUserId, List<User> users, string teamLeaderId)
{
User user = users.FirstOrDefault(x => x.SlackUserId == slackUserId);
if (user == null)
{
ApplicationUser teamLeader = await _applicationUser.FirstOrDefaultAsync(x => x.Id == teamLeaderId && x.SlackUserId == slackUserId);
if (teamLeader != null)
return true;
}
if (user != null && user.IsActive)
return true;

return false;
}


/// <summary>
/// checks whether the applicant is scrum bot - JJ
/// </summary>
/// <param name="scrumBotId"></param>
/// <param name="message"></param>
/// <returns>true if it is scrum bot else false</returns>
private bool IsScrumBot(string scrumBotId, string message)
{
//"<@".Length is 2
int indexFrom = message.IndexOf("<@", StringComparison.Ordinal) + 2;
int indexTo = message.LastIndexOf(">", StringComparison.Ordinal);
if (indexTo > 0 && indexFrom > 1)
{
//the slack userId is fetched
string applicantId = message.Substring(indexFrom, indexTo - indexFrom);
if (String.Compare(applicantId, scrumBotId, StringComparison.Ordinal) == 0)
return true;
}
return false;
}


/// <summary>
/// Fetch today's scrum - JJ
/// </summary>
Expand Down Expand Up @@ -484,8 +515,7 @@ private async Task<string> ScrumAsync(string slackChannelId, string slackChannel
ProjectAc project = await _oauthCallsRepository.GetProjectDetailsAsync(slackChannelName, accessToken);
ScrumStatus scrumStatus = await FetchScrumStatusAsync(project, users, null, slackChannelId);

User user = users.FirstOrDefault(x => x.SlackUserId == slackUserId);
if (user != null && user.IsActive)
if (await CheckUserAsync(slackUserId, users, project.TeamLeaderId))
{
switch (scrumCommand)
{
Expand Down Expand Up @@ -573,8 +603,7 @@ private async Task<string> LeaveAsync(string slackChannelId, string slackChannel
ScrumStatus scrumStatus = await FetchScrumStatusAsync(project, users, questions, slackChannelId);
if (scrumStatus == ScrumStatus.OnGoing)
{
User user = users.FirstOrDefault(x => x.SlackUserId == slackUserId);
if (user != null && user.IsActive)
if (await CheckUserAsync(slackUserId, users, project.TeamLeaderId))
returnMsg = await MarkLeaveAsync(users, scrum.Id, applicant, questions, scrum.ProjectId, slackUserId, applicantId);
else
//when the applicant is not in OAuth or not user of the project or is in-active inOAuth
Expand Down Expand Up @@ -753,6 +782,7 @@ private async Task<string> StartScrumAsync(string slackChannelId, List<User> use
else if (!prevUserAc.IsActive)
//reply to the user to whom the last question was asked. but this user is in active now
replyMessage = string.Format(_stringConstant.InActiveInOAuth, prevUserAc.Name);

}
//if scrum meeting was interrupted. "scrum time" is written to resume scrum meeting. So next question is fetched.
replyMessage += await GetQuestionAsync(scrum.Id, questionList, users, project.Id);
Expand Down
9 changes: 5 additions & 4 deletions Slack.Automation/Promact.Erp.Core/Controllers/Bot.cs
Expand Up @@ -45,7 +45,7 @@ public class Bot
/// </summary>
public void TaskMailBot()
{
_logger.Info("TaskMailAccessToken : " +_environmentVariableRepository.TaskmailAccessToken);
_logger.Info("TaskMailAccessToken : " + _environmentVariableRepository.TaskmailAccessToken);
SlackSocketClient client = new SlackSocketClient(_environmentVariableRepository.TaskmailAccessToken);
// assigning bot token on Slack Socket Client
// Creating a Action<MessageReceived> for Slack Socket Client to get connect. No use in task mail bot
Expand All @@ -71,7 +71,7 @@ public void TaskMailBot()
{
_logger.Info("Task Mail process start - StartTaskMailAsync");
replyText = _taskMailRepository.StartTaskMailAsync(user.UserId).Result;
_logger.Info("Task Mail process done : "+ replyText);
_logger.Info("Task Mail process done : " + replyText);
}
else
{
Expand Down Expand Up @@ -123,15 +123,16 @@ public void Scrum()
_logger.Info("Scrum bot got message :" + message);
try
{
_logger.Info("Scrum bot got message, inside try");
_logger.Info("Scrum bot got message : " + message.text + " From user : " + message.user + " Of channel : " + message.channel);
string replyText = string.Empty;
Task.Run(async () =>
{
replyText = await _scrumBotRepository.ProcessMessagesAsync(message.user, message.channel, message.text, _scrumBotId);
_logger.Info("Scrum bot got reply : " + replyText + " To user : " + message.user + " Of channel : " + message.channel);
}).GetAwaiter().GetResult();
if (!String.IsNullOrEmpty(replyText))
{
_logger.Info("Scrum bot got reply");
_logger.Info("Scrum bot sending reply");
client.SendMessage(showMethod, message.channel, replyText);
}
}
Expand Down
Expand Up @@ -141,14 +141,14 @@ public string SlackHelpMessage
get
{
return string.Format(
"To apply casual leave: /leaves apply cl [Reason(for long reason write in \" \")] [FromDate] [EndDate] [RejoinDate]"+
"{0}To apply sick leave: /leaves apply sl [Reason] [FromDate]"+
"To apply casual leave: /leaves apply cl [Reason(for long reason write in \" \")] [FromDate] [EndDate] [RejoinDate]" +
"{0}To apply sick leave: /leaves apply sl [Reason] [FromDate]" +
"{0}To apply sick leave by admin for other: /leaves apply sl [Reason] [FromDate] [username]" +
"{0}For leaves list of yours : /leaves list" +
"{0}For leaves list of others : /leaves list [username]"+
"{0}For leaves list of others : /leaves list [username]" +
"{0}For leave cancel : /leaves cancel [leave Id number]" +
"{0}For sick leave update(only by admin): / leaves update [leave id] [EndDate] [RejoinDate]" +
"{0}For leave status of yours : /leaves status"+
"{0}For leave status of yours : /leaves status" +
"{0}For leave status of others : /leaves status [username]" +
"{0}For leaves balance: /leaves balance", Environment.NewLine);
}
Expand All @@ -157,7 +157,7 @@ public string SlackErrorMessage
{
get
{
return "I didn't quite get that. I'm easily confused. Perhaps try the words in a different order."+
return "I didn't quite get that. I'm easily confused. Perhaps try the words in a different order." +
" For help : /leaves help";
}
}
Expand Down Expand Up @@ -710,7 +710,7 @@ public string NoSlackDetails
{
get
{
return string.Format("Sorry we do not have your slack details."+
return string.Format("Sorry we do not have your slack details." +
" Click here {0}", AppSettingUtil.PromactErpUrl);
}
}
Expand Down Expand Up @@ -1240,7 +1240,7 @@ public string SlashCommandLeaveStatusErrorMessage
{
get
{
return string.Format("Either leave doesn't exist for that user or enter a valid slack username."+
return string.Format("Either leave doesn't exist for that user or enter a valid slack username." +
" {0}Example :-{0}/leaves status username - for other user{0}/leaves status - for own", Environment.NewLine);
}
}
Expand Down Expand Up @@ -1486,8 +1486,8 @@ public string SorryYouCannotApplyLeave
{
get
{
return string.Format("Sorry you cannot use leave slash command."+
" Either user is not in Promact OAuth or yet u haven't login in promact-slack server."+
return string.Format("Sorry you cannot use leave slash command." +
" Either user is not in Promact OAuth or yet u haven't login in promact-slack server." +
" Click here {0}", AppSettingUtil.PromactErpUrl);
}
}
Expand Down Expand Up @@ -1544,7 +1544,7 @@ public string UserNotInProject
{
get
{
return "<@{0}> is not included in the project(of this group in OAuth)\n";
return "<@{0}> is not included as a member in the project(of this group in OAuth)\n";
}
}
public string Admin
Expand Down Expand Up @@ -1698,7 +1698,7 @@ public string YouAreNotInExistInOAuthServer
{
get
{
return string.Format("Either you are not in Promact OAuth or you haven't logged in with Promact OAuth."+
return string.Format("Either you are not in Promact OAuth or you haven't logged in with Promact OAuth." +
" Click here {0}", AppSettingUtil.PromactErpUrl);
}
}
Expand Down Expand Up @@ -1860,15 +1860,15 @@ public string SlashCommandTextCasual
{
get
{
return string.Format("apply cl Testing {0} {0} {1}", DateTime.UtcNow.ToShortDateString(),
return string.Format("apply cl Testing {0} {0} {1}", DateTime.UtcNow.ToShortDateString(),
DateTime.UtcNow.AddDays(1).ToShortDateString());
}
}
public string SlashCommandUpdate
{
get
{
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.ToShortDateString(),
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.ToShortDateString(),
DateTime.UtcNow.AddDays(1).ToShortDateString());
}
}
Expand All @@ -1883,7 +1883,7 @@ public string SlashCommandUpdateWrongId
{
get
{
return string.Format("update {0} {1} {2}", 10, DateTime.UtcNow.ToShortDateString(),
return string.Format("update {0} {1} {2}", 10, DateTime.UtcNow.ToShortDateString(),
DateTime.UtcNow.AddDays(1).ToShortDateString());
}
}
Expand Down Expand Up @@ -1919,7 +1919,7 @@ public string AdminErrorMessageApplySickLeave
{
get
{
return "You are not authorize to apply leave. Only Admin can apply sick leave for other."+
return "You are not authorize to apply leave. Only Admin can apply sick leave for other." +
" You are not admin. Else ";
}
}
Expand Down Expand Up @@ -2380,7 +2380,7 @@ public string InActiveInOAuth
{
get
{
return "<@{0}> is marked as In-active,not added as a user in the project(in OAuth server) or not in OAuth server. Please contact your system administrator.\n ";
return "<@{0}> is marked as In-active,not added as a member in the project(in OAuth server) or not in OAuth server. Please contact your system administrator.\n ";
}
}
public string TeamLeaderLogin
Expand Down Expand Up @@ -2500,7 +2500,7 @@ public string InValidDateErrorMessage
{
get
{
return "Please check end date and re-join date. End date cannot beyond start date and"+
return "Please check end date and re-join date. End date cannot beyond start date and" +
" rejoin date cannot beyond and same as end date";
}
}
Expand All @@ -2515,7 +2515,7 @@ public string LeaveWrongCommandForBeyondDateFirstExample
{
get
{
return string.Format("apply cl Testing {0} {1} {2}", DateTime.UtcNow.ToShortDateString(),
return string.Format("apply cl Testing {0} {1} {2}", DateTime.UtcNow.ToShortDateString(),
DateTime.UtcNow.AddDays(-3).ToShortDateString(), DateTime.UtcNow.AddDays(1).ToShortDateString());
}
}
Expand All @@ -2538,7 +2538,7 @@ public string SlashCommandUpdateForBeyondStartDateFirstExample
{
get
{
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.AddDays(-5).ToShortDateString(),
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.AddDays(-5).ToShortDateString(),
DateTime.UtcNow.AddDays(1).ToShortDateString());
}
}
Expand All @@ -2547,7 +2547,7 @@ public string SlashCommandUpdateForBeyondStartDateSecondExample
{
get
{
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.ToShortDateString(),
return string.Format("update {0} {1} {2}", 1, DateTime.UtcNow.ToShortDateString(),
DateTime.UtcNow.AddDays(-3).ToShortDateString());
}
}
Expand Down Expand Up @@ -2864,7 +2864,7 @@ public string RequestToAddSlackApp
{
get
{
return string.Format("Please add our slack app to your slack slackbot channel. Click here {0}",
return string.Format("Please add our slack app to your slack slackbot channel. Click here {0}",
AppSettingUtil.PromactErpUrl);
}
}
Expand Down

0 comments on commit bfbd8e4

Please sign in to comment.