Sending team incident channel name, adding support to add slack userId in team (#68)

* TP-0000 | adding with userIds and sending channel name

* TP-0000 | updating topic of incidents updated by cron
This commit is contained in:
Shubham Kirve
2023-05-17 11:42:21 +05:30
committed by GitHub Enterprise
parent 5b07d98fc3
commit 67e3bf8d5e
5 changed files with 34 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import (
"houston/model/severity"
"houston/model/shedlock"
"houston/model/team"
"houston/pkg/slackbot"
"github.com/slack-go/slack"
"github.com/slack-go/slack/socketmode"
@@ -109,10 +110,20 @@ func updatingSevForEachInc(logger *zap.Logger, incidents []incident.IncidentEnti
//UPDATING MESSAGE
s := action.NewIncidentChannelMessageUpdateAction(socketModeClient, logger, incidentService, teamService, severityService)
slackbotClient := slackbot.NewSlackClient(logger, socketModeClient)
team, err := teamService.FindTeamById(incidents[i].TeamId)
if err != nil {
logger.Error("error in fetching team by id", zap.Uint("teamId", incidents[i].TeamId), zap.Error(err), zap.String("s", severityString))
}
incidentSeverityEntity, err := severityService.FindSeverityById(incidents[i].SeverityId)
if err != nil {
logger.Error("error in finding severity entity", zap.Error(err), zap.Uint("severityId", incidents[i].SeverityId))
}
s.ProcessAction(incidents[i].SlackChannel)
msgOption := slack.MsgOptionText(fmt.Sprintf("houston escalated incident to %s", severityString), false)
_, _, errMessage := socketModeClient.PostMessage(incidents[i].SlackChannel, msgOption)
topic := fmt.Sprintf("%s-%s(%s) Incident-%d | %s", team.Name, incidentSeverityEntity.Name, incidentSeverityEntity.Description, incidents[i].ID, incidents[i].Title)
slackbotClient.SetChannelTopic(incidents[i].SlackChannel, topic)
if errMessage != nil {
logger.Error("PostMessage failed for cronJob ", zap.Error(errMessage), zap.Int("incidentId", int(incidents[i].ID)))
}

View File

@@ -4,4 +4,5 @@ type UpdateTeamRequest struct {
Id uint `json:"id"`
WorkEmailIds []string `json:"workEmailIds,omitempty"`
WebhookSlackChannel string `json:"webhook_slack_channel,omitempty"`
SlackUserIds []string `json:"slackUserIds,omitempty"`
}

View File

@@ -8,20 +8,19 @@ import (
)
type TeamResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
SlackUserIds pq.StringArray `json:"slackUserIds"`
Participants []UserResponse `json:"participants,omitempty"`
UpdatedAt time.Time `json:"lastUpdatedAt,omitempty"`
WebhookSlackChannel string `gorm:"column:webhook_slack_channel"`
ID uint `json:"id"`
Name string `json:"name"`
SlackUserIds pq.StringArray `json:"slackUserIds"`
Participants []UserResponse `json:"participants,omitempty"`
UpdatedAt time.Time `json:"lastUpdatedAt,omitempty"`
WebhookSlackChannelName string `gorm:"column:webhook_slack_channel_name"`
}
func ConvertToTeamResponse(teamEntity team.TeamEntity) TeamResponse {
return TeamResponse{
ID: teamEntity.ID,
Name: teamEntity.Name,
SlackUserIds: teamEntity.SlackUserIds,
UpdatedAt: teamEntity.Model.UpdatedAt,
WebhookSlackChannel: teamEntity.WebhookSlackChannel,
ID: teamEntity.ID,
Name: teamEntity.Name,
SlackUserIds: teamEntity.SlackUserIds,
UpdatedAt: teamEntity.Model.UpdatedAt,
}
}

View File

@@ -66,7 +66,14 @@ func (t *teamService) GetTeams(c *gin.Context) {
Image: users[0].Profile.Image32,
})
}
channel, err := t.client.GetConversationInfo(team.WebhookSlackChannel)
teamResponse := service.ConvertToTeamResponse(*team)
if err != nil {
t.logger.Error("error in getting channel info", zap.String("channelId", team.WebhookSlackChannel), zap.Error(err))
teamResponse.WebhookSlackChannelName = "not found"
} else {
teamResponse.WebhookSlackChannelName = channel.Name
}
teamResponse.Participants = userResponses
c.JSON(http.StatusOK, common.SuccessResponse(teamResponse, http.StatusOK))
return
@@ -117,7 +124,7 @@ func (t *teamService) UpdateTeam(c *gin.Context) {
t.logger.Error("error in fetching team by id", zap.Uint("TeamId", updateTeamRequest.Id), zap.Error(err))
}
slackUserIds := []string{}
slackUserIds := updateTeamRequest.SlackUserIds
for _, ind := range updateTeamRequest.WorkEmailIds {
slackUser, err := t.client.GetUserByEmail(ind)
if err != nil {

View File

@@ -53,6 +53,9 @@ func ValidateUpdateTeamRequest(request service.UpdateTeamRequest) error {
if request.WorkEmailIds == nil || len(request.WorkEmailIds) == 0 {
request.WorkEmailIds = []string{}
}
if request.SlackUserIds == nil || len(request.SlackUserIds) == 0 {
request.SlackUserIds = []string{}
}
return nil
}