Skip to content

Commit

Permalink
Merge pull request #301 from Promact/RedmineSlashIntegration
Browse files Browse the repository at this point in the history
Redmine slash integration
  • Loading branch information
Ankit Bhanvadia committed Mar 21, 2017
2 parents 28ed7dd + 2021315 commit d5382ee
Show file tree
Hide file tree
Showing 43 changed files with 2,470 additions and 264 deletions.
8 changes: 4 additions & 4 deletions Slack.Automation/Promact.Core.Repository/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task UpdateMessageAsync(string responseUrl, string replyText)
_logger.Debug("UpdateMessageAsync method");
var slashResponseText = new SlashResponse() { Text = replyText };
var slashResponseJsonText = JsonConvert.SerializeObject(slashResponseText);
await _httpClientService.PostAsync(responseUrl, slashResponseJsonText, _stringConstant.JsonContentString);
await _httpClientService.PostAsync(responseUrl, slashResponseJsonText, _stringConstant.JsonContentString, null, null);
_logger.Debug("UpdateMessageAsync method post method done successfully");
}

Expand All @@ -84,7 +84,7 @@ public async Task SendMessageAsync(string responseUrl, string replyText)
_logger.Debug("SendMessageAsync method");
var slashResponseText = new SlashResponse() { ResponseType = _stringConstant.ResponseTypeEphemeral, Text = replyText };
var slashResponseJsonText = JsonConvert.SerializeObject(slashResponseText);
await _httpClientService.PostAsync(responseUrl, slashResponseJsonText, _stringConstant.JsonContentString);
await _httpClientService.PostAsync(responseUrl, slashResponseJsonText, _stringConstant.JsonContentString, null, null);
_logger.Debug("SendMessageAsync method post method done sucessfully");
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task SendSickLeaveMessageToUserIncomingWebhookAsync(LeaveRequest le
var slashIncomingWebhookText = new SlashIncomingWebhook() { Channel = _stringConstant.AtTheRate + slackUser.Name, Username = _stringConstant.LeaveBot, Attachments = attachment };
var slashIncomingWebhookJsonText = JsonConvert.SerializeObject(slashIncomingWebhookText);
if (incomingWebHook != null)
await _httpClientService.PostAsync(incomingWebHook.IncomingWebHookUrl, slashIncomingWebhookJsonText, _stringConstant.JsonContentString);
await _httpClientService.PostAsync(incomingWebHook.IncomingWebHookUrl, slashIncomingWebhookJsonText, _stringConstant.JsonContentString, null, null);
}
EmailApplication email = new EmailApplication();
email.To = new List<string>();
Expand Down Expand Up @@ -200,7 +200,7 @@ private async Task GetAttachmentAndSendToTLAndManagementAsync(string userId, Lea
var slashIncomingWebhookText = new SlashIncomingWebhook() { Channel = _stringConstant.AtTheRate + slackUser.Name, Username = _stringConstant.LeaveBot, Attachments = attachment };
var slashIncomingWebhookJsonText = JsonConvert.SerializeObject(slashIncomingWebhookText);
if (incomingWebHook != null)
await _httpClientService.PostAsync(incomingWebHook.IncomingWebHookUrl, slashIncomingWebhookJsonText, _stringConstant.JsonContentString);
await _httpClientService.PostAsync(incomingWebHook.IncomingWebHookUrl, slashIncomingWebhookJsonText, _stringConstant.JsonContentString, null, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public OAuthApplication ExternalLoginInformation(string refreshToken)
public async Task AddSlackUserInformationAsync(string code)
{
string slackOAuthRequest = string.Format(_stringConstant.SlackOauthRequestUrl, _envVariableRepository.SlackOAuthClientId, _envVariableRepository.SlackOAuthClientSecret, code);
string slackOAuthResponse = await _httpClientService.GetAsync(_stringConstant.OAuthAcessUrl, slackOAuthRequest, null);
string slackOAuthResponse = await _httpClientService.GetAsync(_stringConstant.OAuthAcessUrl, slackOAuthRequest, null, _stringConstant.Bearer);
SlackOAuthResponse slackOAuth = JsonConvert.DeserializeObject<SlackOAuthResponse>(slackOAuthResponse);
_logger.Info("slackOAuth UserID" + slackOAuth.UserId);
bool checkUserIncomingWebHookExist = _incomingWebHookRepository.Any(x => x.UserId == slackOAuth.UserId);
Expand All @@ -121,7 +121,7 @@ public async Task AddSlackUserInformationAsync(string code)

string detailsRequest = string.Format(_stringConstant.SlackUserDetailsUrl, slackOAuth.AccessToken);
//get all the slack users of the team
string userDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackUserListUrl, detailsRequest, null);
string userDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackUserListUrl, detailsRequest, null, _stringConstant.Bearer);
SlackUserResponse slackUsers = JsonConvert.DeserializeObject<SlackUserResponse>(userDetailsResponse);
if (slackUsers.Ok)
{
Expand All @@ -147,7 +147,7 @@ public async Task AddSlackUserInformationAsync(string code)
await _slackUserRepository.AddSlackUserAsync(slackUserDetails);
_logger.Debug("Add Slack User Id Done");
//the public channels' details
string channelDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackChannelListUrl, detailsRequest, null);
string channelDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackChannelListUrl, detailsRequest, null, _stringConstant.Bearer);
SlackChannelResponse channels = JsonConvert.DeserializeObject<SlackChannelResponse>(channelDetailsResponse);
if (channels.Ok)
{
Expand All @@ -162,7 +162,7 @@ public async Task AddSlackUserInformationAsync(string code)
throw new SlackAuthorizeException(_stringConstant.SlackAuthError + channels.ErrorMessage);
_logger.Info("Slack User Id : " + (await _userManager.FindByEmailAsync(applicationUser.Email)).SlackUserId);
//the public groups' details
string groupDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackGroupListUrl, detailsRequest, null);
string groupDetailsResponse = await _httpClientService.GetAsync(_stringConstant.SlackGroupListUrl, detailsRequest, null, _stringConstant.Bearer);
SlackGroupDetails groups = JsonConvert.DeserializeObject<SlackGroupDetails>(groupDetailsResponse);
_logger.Info("Groups:" + groups.ErrorMessage);
_logger.Debug("Slack User Id : " + (await _userManager.FindByEmailAsync(applicationUser.Email)).SlackUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<User> GetUserByEmployeeIdAsync(string employeeId)
var accessToken = await GetCurrentUserAcceesToken();
User userDetails = new User();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, employeeId, _stringConstant.UserDetailUrl);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
userDetails = JsonConvert.DeserializeObject<User>(response);
Expand All @@ -67,7 +67,7 @@ public async Task<List<User>> GetProjectUsersByTeamLeaderIdAsync(string teamLead
var accessToken = await GetCurrentUserAcceesToken();
List<User> projectUsers = new List<User>();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, teamLeaderId, _stringConstant.ProjectUsersByTeamLeaderId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
projectUsers = JsonConvert.DeserializeObject<List<User>>(response);
Expand All @@ -85,7 +85,7 @@ public async Task<List<ProjectAc>> GetAllProjectsAsync()
var accessToken = await GetCurrentUserAcceesToken();
List<ProjectAc> projects = new List<ProjectAc>();
var requestUrl = _stringConstant.AllProjectUrl;
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
projects = JsonConvert.DeserializeObject<List<ProjectAc>>(response);
Expand All @@ -104,7 +104,7 @@ public async Task<ProjectAc> GetProjectDetailsAsync(int projectId)
var accessToken = await GetCurrentUserAcceesToken();
ProjectAc project = new ProjectAc();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, projectId, _stringConstant.GetProjectDetails);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
project = JsonConvert.DeserializeObject<ProjectAc>(response);
Expand All @@ -126,7 +126,7 @@ public async Task<List<UserRoleAc>> GetUserRoleAsync(string userId)
_logger.Info("basedUrl :" + _stringConstant.UserUrl);
_logger.Info("requestUrl :" + requestUrl);
_logger.Info("accessToken :" + accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken, _stringConstant.Bearer);
var userRoleListAc = JsonConvert.DeserializeObject<List<UserRoleAc>>(response);
return userRoleListAc;
}
Expand All @@ -141,7 +141,7 @@ public async Task<List<UserRoleAc>> GetListOfEmployeeAsync(string userId)
{
var accessToken = await GetCurrentUserAcceesToken();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, userId, _stringConstant.TeamMembersUrl);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken, _stringConstant.Bearer);
var userRoleListAc = JsonConvert.DeserializeObject<List<UserRoleAc>>(response);
return userRoleListAc;
}
Expand All @@ -155,7 +155,7 @@ public async Task<bool> CurrentUserIsAdminAsync()
var accessToken = await GetCurrentUserAcceesToken();
bool result = false;
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.UserIsAdmin, (await GetCurrentUserDetails()).Id);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
result = JsonConvert.DeserializeObject<bool>(response);
Expand All @@ -171,7 +171,7 @@ public async Task<UserEmailListAc> GetUserEmailListBasedOnRoleAsync()
{
var accessToken = await GetCurrentUserAcceesToken();
UserEmailListAc userEmailListAc = new UserEmailListAc();
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, _stringConstant.Email, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, _stringConstant.Email, accessToken, _stringConstant.Bearer);
if (response != null)
userEmailListAc = JsonConvert.DeserializeObject<UserEmailListAc>(response);
return userEmailListAc;
Expand All @@ -187,7 +187,7 @@ public async Task<List<ProjectAc>> GetListOfProjectsEnrollmentOfUserByUserIdAsyn
var accessToken = await GetCurrentUserAcceesToken();
List<ProjectAc> projects = new List<ProjectAc>();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.DetailsAndSlashForUrl, userId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
projects = JsonConvert.DeserializeObject<List<ProjectAc>>(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<User> GetUserByUserIdAsync(string userId, string accessToken)
{
User userDetails = new User();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.DetailsAndSlashForUrl, userId);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
userDetails = JsonConvert.DeserializeObject<User>(response);
Expand All @@ -60,7 +60,7 @@ public async Task<List<User>> GetTeamLeaderUserIdAsync(string userId, string acc
{
List<User> teamLeader = new List<User>();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.TeamLeaderDetailsUrl, userId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
teamLeader = JsonConvert.DeserializeObject<List<User>>(response);
Expand All @@ -77,7 +77,7 @@ public async Task<List<User>> GetTeamLeaderUserIdAsync(string userId, string acc
public async Task<List<User>> GetManagementUserNameAsync(string accessToken)
{
List<User> management = new List<User>();
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, _stringConstant.ManagementDetailsUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, _stringConstant.ManagementDetailsUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
management = JsonConvert.DeserializeObject<List<User>>(response);
Expand All @@ -94,7 +94,7 @@ public async Task<List<User>> GetManagementUserNameAsync(string accessToken)
public async Task<ProjectAc> GetProjectDetailsAsync(int projectId, string accessToken)
{
string requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.ProjectDetailUrl, projectId.ToString());
string response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
string response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
ProjectAc project = new ProjectAc();
if (!string.IsNullOrEmpty(response))
{
Expand All @@ -114,7 +114,7 @@ public async Task<LeaveAllowed> AllowedLeave(string userId, string accessToken)
{
LeaveAllowed allowedLeave = new LeaveAllowed();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.CasualLeaveUrl, userId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
allowedLeave = JsonConvert.DeserializeObject<LeaveAllowed>(response);
Expand All @@ -133,7 +133,7 @@ public async Task<bool> UserIsAdminAsync(string userId, string accessToken)
{
bool result = false;
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.UserIsAdmin, userId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if (response != null)
{
result = JsonConvert.DeserializeObject<bool>(response);
Expand All @@ -151,8 +151,8 @@ public async Task<List<ProjectAc>> GetListOfProjectsEnrollmentOfUserByUserIdAsyn
{
List<ProjectAc> projects = new List<ProjectAc>();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.DetailsAndSlashForUrl, userId);
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken);
if (response != null)
var response = await _httpClientService.GetAsync(_stringConstant.ProjectUrl, requestUrl, accessToken, _stringConstant.Bearer);
if(response != null)
{
projects = JsonConvert.DeserializeObject<List<ProjectAc>>(response);
}
Expand All @@ -169,7 +169,7 @@ public async Task<List<User>> GetAllTeamMemberByProjectIdAsync(int projectId, st
{
List<User> teamMembers = new List<User>();
var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.DetailsAndSlashForUrl, projectId);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken);
var response = await _httpClientService.GetAsync(_stringConstant.UserUrl, requestUrl, accessToken, _stringConstant.Bearer);
if(response != null)
{
teamMembers = JsonConvert.DeserializeObject<List<User>>(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
<Compile Include="OauthCallsRepository\OauthCallHttpContextRespository.cs" />
<Compile Include="OauthCallsRepository\OauthCallsRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RedmineRepository\IRedmineRepository.cs" />
<Compile Include="RedmineRepository\RedmineRepository.cs" />
<Compile Include="ScrumReportRepository\IScrumReportRepository.cs" />
<Compile Include="ScrumReportRepository\ScrumReportRepository.cs" />
<Compile Include="ScrumRepository\IScrumBotRepository.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Promact.Erp.DomainModel.ApplicationClass.SlackRequestAndResponse;
using System.Threading.Tasks;

namespace Promact.Core.Repository.RedmineRepository
{
public interface IRedmineRepository
{
/// <summary>
/// Method to handle Redmine Slash command
/// </summary>
/// <param name="slashCommand">slash command</param>
/// <returns>reply message</returns>
Task SlackRequestAsync(SlashCommand slashCommand);
}
}
Loading

0 comments on commit d5382ee

Please sign in to comment.