67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package action
|
|
|
|
import (
|
|
"fmt"
|
|
"houston/pkg/postgres/service/incident"
|
|
"time"
|
|
|
|
"github.com/slack-go/slack"
|
|
"github.com/slack-go/slack/socketmode"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ResolveIncidentAction struct {
|
|
client *socketmode.Client
|
|
logger *zap.Logger
|
|
incidentService *incident.Service
|
|
}
|
|
|
|
func NewIncidentResolveProcessor(client *socketmode.Client, logger *zap.Logger, incidentService *incident.Service) *ResolveIncidentAction {
|
|
return &ResolveIncidentAction{
|
|
client: client,
|
|
logger: logger,
|
|
incidentService: incidentService,
|
|
}
|
|
}
|
|
|
|
func (irp *ResolveIncidentAction) IncidentResolveProcess(callback slack.InteractionCallback, request *socketmode.Request) {
|
|
channelId := callback.Channel.ID
|
|
incidentEntity, err := irp.incidentService.FindIncidentByChannelId(channelId)
|
|
if err != nil {
|
|
irp.logger.Error("incident not found",
|
|
zap.String("channel", channelId),
|
|
zap.String("user_id", callback.User.ID), zap.Error(err))
|
|
}
|
|
|
|
incidentStatusEntity, _ := irp.incidentService.FindIncidentStatusByName(incident.Resolved)
|
|
|
|
now := time.Now()
|
|
incidentEntity.Status = incidentStatusEntity.ID
|
|
incidentEntity.EndTime = &now
|
|
|
|
err = irp.incidentService.UpdateIncident(incidentEntity)
|
|
if err != nil {
|
|
irp.logger.Error("failed to update incident to resolve state",
|
|
zap.String("channel", channelId),
|
|
zap.String("user_id", callback.User.ID), zap.Error(err))
|
|
return
|
|
}
|
|
|
|
irp.logger.Info("successfully resolved the incident",
|
|
zap.String("channel", channelId),
|
|
zap.String("user_id", callback.User.ID))
|
|
|
|
msgOption := slack.MsgOptionText(fmt.Sprintf("<@%s> > set status to %s", callback.User.ID,
|
|
incident.Resolved), false)
|
|
_, _, errMessage := irp.client.PostMessage(callback.Channel.ID, msgOption)
|
|
if errMessage != nil {
|
|
irp.logger.Error("post response failed for ResolveIncident", zap.Error(errMessage))
|
|
return
|
|
}
|
|
|
|
irp.client.ArchiveConversation(channelId)
|
|
|
|
var payload interface{}
|
|
irp.client.Ack(*request, payload)
|
|
}
|