* INFRA-3703 : Houston side changes to accomodate QA use case * INFRA-3703 : UT failure fix * INFRA-3703 : Minor changes * INFRA-3703 : Unique constraint * INFRA-3703 : Edit migration file * INFRA-3703 : PR review comments and UT's * INFRA-3703 : Channel name resolution
150 lines
4.9 KiB
Go
150 lines
4.9 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"
|
|
"houston/service/tagValue"
|
|
"strings"
|
|
)
|
|
|
|
type HoustonCommandResolver struct {
|
|
socketModeClient *socketmode.Client
|
|
slackBotClient *slackbot.Client
|
|
rcaService *rcaService.RcaService
|
|
productsService products.ProductService
|
|
incidentOrchestrator orchestration.IncidentOrchestrator
|
|
tagValueService tagValue.TagValueService
|
|
}
|
|
|
|
func NewHoustonCommandResolver(
|
|
socketModeClient *socketmode.Client,
|
|
slackBotClient *slackbot.Client,
|
|
rcaService *rcaService.RcaService,
|
|
productsService products.ProductService,
|
|
incidentOrchestrator orchestration.IncidentOrchestrator,
|
|
tagValueService tagValue.TagValueService,
|
|
) *HoustonCommandResolver {
|
|
return &HoustonCommandResolver{
|
|
socketModeClient: socketModeClient,
|
|
slackBotClient: slackBotClient,
|
|
rcaService: rcaService,
|
|
productsService: productsService,
|
|
incidentOrchestrator: incidentOrchestrator,
|
|
tagValueService: tagValueService,
|
|
}
|
|
}
|
|
|
|
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,
|
|
resolver.tagValueService,
|
|
)
|
|
|
|
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
|
|
|
|
}
|