* INFRA-2866 | create incident modal with product * INFRA-2866 | Update product flow * INFRA-2866 | Resolving review comments * INFRA-2866 | Adding default values for product, assigner and responder * INFRA-2866 | bug fix in getting assigner and responder team * INFRA-2866 | bug-fix: users in no team are not getting products * INFRA-2866 | adding log lines * INFRA-2866 | adding assigner team members into incident * INFRA-2866 | updated help command response text * INFRA-2866 | adding assigner team members by severity * INFRA-2866 | updating product list for users with no product * INFRA-2866 | assigner teams = (teamsOfUser ++ teamsOfSelectedProducts) * INFRA-2866 | renamed assigner to reporting team * INFRA-2866 | query to seed product as others for current open incidents without any product
145 lines
4.7 KiB
Go
145 lines
4.7 KiB
Go
package resolver
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/slack-go/slack"
|
|
"github.com/slack-go/slack/socketmode"
|
|
"houston/appcontext"
|
|
"houston/internal"
|
|
"houston/internal/processor"
|
|
"houston/logger"
|
|
"houston/pkg/slackbot"
|
|
"houston/service/orchestration"
|
|
"houston/service/products"
|
|
rcaService "houston/service/rca/impl"
|
|
"strings"
|
|
)
|
|
|
|
type HoustonCommandResolver struct {
|
|
socketModeClient *socketmode.Client
|
|
slackBotClient *slackbot.Client
|
|
rcaService *rcaService.RcaService
|
|
productsService products.ProductService
|
|
incidentOrchestrator orchestration.IncidentOrchestrator
|
|
}
|
|
|
|
func NewHoustonCommandResolver(
|
|
socketModeClient *socketmode.Client,
|
|
slackBotClient *slackbot.Client,
|
|
rcaService *rcaService.RcaService,
|
|
productsService products.ProductService,
|
|
incidentOrchestrator orchestration.IncidentOrchestrator,
|
|
) *HoustonCommandResolver {
|
|
return &HoustonCommandResolver{
|
|
socketModeClient: socketModeClient,
|
|
slackBotClient: slackBotClient,
|
|
rcaService: rcaService,
|
|
productsService: productsService,
|
|
incidentOrchestrator: incidentOrchestrator,
|
|
}
|
|
}
|
|
|
|
const logTag = "[houston_command_resolver]"
|
|
|
|
func (resolver *HoustonCommandResolver) Resolve(evt *socketmode.Event) processor.CommandProcessor {
|
|
cmd, _ := evt.Data.(slack.SlashCommand)
|
|
logger.Info(fmt.Sprintf("%s received slash command [%s] from channel [%s] by user [%s]", logTag, fmt.Sprintf("%s %s", cmd.Command, cmd.Text), cmd.ChannelName, cmd.UserName))
|
|
|
|
params := strings.ToLower(cmd.Text)
|
|
|
|
var commandProcessor processor.CommandProcessor
|
|
|
|
if strings.TrimSpace(params) == "" {
|
|
hcp := processor.NewHoustonCommandProcessor(resolver.socketModeClient, resolver.slackBotClient, resolver.rcaService)
|
|
commandProcessor = hcp
|
|
} else {
|
|
switch {
|
|
case strings.HasPrefix(params, string(internal.StartIncidentParam)):
|
|
commandProcessor = processor.NewStartIncidentCommandProcessor(
|
|
resolver.productsService,
|
|
resolver.incidentOrchestrator,
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.OpenSeverityModalParam):
|
|
commandProcessor = processor.NewOpenSetSeverityViewModalCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.SetSeverityParam):
|
|
commandProcessor = processor.NewSetSeverityCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.OpenTeamModalParam):
|
|
commandProcessor = processor.NewOpenSetTeamViewModalCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
resolver.incidentOrchestrator,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.SetTeamParam):
|
|
commandProcessor = processor.NewSetTeamCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.OpenStatusModalParam):
|
|
commandProcessor = processor.NewOpenSetStatusViewModalCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.SetStatusParam):
|
|
commandProcessor = processor.NewSetStatusCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.OpenDescriptionModalParam):
|
|
commandProcessor = processor.NewOpenSetDescriptionViewModalCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.SetDescriptionParam):
|
|
commandProcessor = processor.NewSetDescriptionCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.ResolveIncidentParam):
|
|
commandProcessor = processor.NewResolveIncidentCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
resolver.rcaService,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.OpenRCAModalParam):
|
|
commandProcessor = processor.NewOpenFillRCAViewModalCommandProcessor(
|
|
resolver.socketModeClient,
|
|
resolver.slackBotClient,
|
|
resolver.rcaService,
|
|
)
|
|
|
|
case strings.HasPrefix(params, internal.HelpParam):
|
|
commandProcessor = processor.NewHelpCommandProcessor(resolver.socketModeClient)
|
|
default:
|
|
message := fmt.Sprintf("`%s %s` is not a valid command", cmd.Command, cmd.Text)
|
|
err := appcontext.GetSlackService().PostEphemeralByChannelID(message, cmd.UserID, false, cmd.ChannelID)
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("%s failed to post ephemeral for invalid slash command param. %+v", logTag, err))
|
|
}
|
|
commandProcessor = processor.NewHelpCommandProcessor(resolver.socketModeClient)
|
|
var payload interface{}
|
|
resolver.socketModeClient.Ack(*evt.Request, payload)
|
|
}
|
|
}
|
|
|
|
return commandProcessor
|
|
|
|
}
|