Files
houston-be/pkg/slack/houston/command/incident_resolve.go

63 lines
1.7 KiB
Go
Raw Normal View History

package command
import (
"fmt"
"houston/entity"
"houston/pkg/postgres/query"
"github.com/slack-go/slack"
"github.com/slack-go/slack/socketmode"
"go.uber.org/zap"
"gorm.io/gorm"
)
type incidentResolveProcessor struct {
client *socketmode.Client
db *gorm.DB
logger *zap.Logger
}
func NewIncidentResolveProcessor(client *socketmode.Client, db *gorm.DB, logger *zap.Logger) *incidentResolveProcessor {
return &incidentResolveProcessor{
client: client,
db: db,
logger: logger,
}
}
func (irp *incidentResolveProcessor) IncidentResolveProcess(callback slack.InteractionCallback, request *socketmode.Request) {
channelId := callback.Channel.ID
incidentEntity, err := query.FindIncidentByChannelId(irp.db, channelId)
if err != nil {
irp.logger.Error("incident not found",
zap.String("channel", channelId),
zap.String("user_id", callback.User.ID), zap.Error(err))
}
incidentEntity.Status = entity.Resolved
err = query.UpdateIncident(irp.db, 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))
}
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, incidentEntity.Status), 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)
}