diff --git a/cmd/app/handler/slack_handler.go b/cmd/app/handler/slack_handler.go index 249e303..a45f2de 100644 --- a/cmd/app/handler/slack_handler.go +++ b/cmd/app/handler/slack_handler.go @@ -40,7 +40,7 @@ func NewSlackHandler(logger *zap.Logger, gormClient *gorm.DB, socketModeClient * return &slackHandler{ logger: logger, socketModeClient: socketModeClient, - slashCommandProcessor: processor.NewSlashCommandProcessor(logger, socketModeClient, incidentService), + slashCommandProcessor: processor.NewSlashCommandProcessor(logger, socketModeClient, incidentService, slackbotClient), memberJoinCallbackProcessor: processor.NewMemberJoinedCallbackEventProcessor(logger, socketModeClient, incidentService, teamService, severityService), blockActionProcessor: processor.NewBlockActionProcessor(logger, socketModeClient, incidentService, teamService, severityService, tagService, slackbotClient), viewSubmissionProcessor: processor.NewViewSubmissionProcessor(logger, socketModeClient, incidentService, teamService, severityService, tagService, slackbotClient), diff --git a/internal/processor/action/slash_command_action.go b/internal/processor/action/slash_command_action.go index fa60fcb..8a92c31 100644 --- a/internal/processor/action/slash_command_action.go +++ b/internal/processor/action/slash_command_action.go @@ -3,6 +3,7 @@ package action import ( "houston/internal/processor/action/view" "houston/model/incident" + "houston/pkg/slackbot" "github.com/slack-go/slack" "github.com/slack-go/slack/socketmode" @@ -13,13 +14,15 @@ type SlashCommandAction struct { incidentService *incident.Repository logger *zap.Logger socketModeClient *socketmode.Client + slackBot *slackbot.Client } -func NewSlashCommandAction(service *incident.Repository, logger *zap.Logger, socketModeClient *socketmode.Client) *SlashCommandAction { +func NewSlashCommandAction(service *incident.Repository, logger *zap.Logger, socketModeClient *socketmode.Client, slackBot *slackbot.Client) *SlashCommandAction { return &SlashCommandAction{ incidentService: service, logger: logger, socketModeClient: socketModeClient, + slackBot: slackBot, } } @@ -44,7 +47,12 @@ func (sca *SlashCommandAction) PerformAction(evt *socketmode.Event) { payload := view.ExistingIncidentOptionsBlock() sca.socketModeClient.Ack(*evt.Request, payload) } - - payload := view.NewIncidentBlock() + _, err = sca.slackBot.GetConversationInfo(cmd.ChannelID) + var payload map[string]interface{} + if err != nil && err.Error() == "channel_not_found" { + payload = view.IntegrateHoustonInChannelBlock() + } else { + payload = view.NewIncidentBlock() + } sca.socketModeClient.Ack(*evt.Request, payload) } diff --git a/internal/processor/action/view/create_incident_modal.go b/internal/processor/action/view/create_incident_modal.go index 35171bf..e7fa39a 100644 --- a/internal/processor/action/view/create_incident_modal.go +++ b/internal/processor/action/view/create_incident_modal.go @@ -46,7 +46,7 @@ func GenerateModalRequest(teams []team.TeamEntity, severities []severity.Severit incidentDescriptionElement := slack.NewPlainTextInputBlockElement(incidentDescriptionPlaceholder, "description") incidentDescriptionElement.Multiline = true incidentDescription := slack.NewInputBlock("Incident description", incidentDescriptionText, nil, incidentDescriptionElement) - incidentDescription.Optional = true + incidentDescription.Optional = false blocks := slack.Blocks{ BlockSet: []slack.Block{ diff --git a/internal/processor/action/view/incident_section.go b/internal/processor/action/view/incident_section.go index 234c2e4..8ab422b 100644 --- a/internal/processor/action/view/incident_section.go +++ b/internal/processor/action/view/incident_section.go @@ -1,8 +1,9 @@ package view import ( - "github.com/slack-go/slack" "houston/common/util" + + "github.com/slack-go/slack" ) func NewIncidentBlock() map[string]interface{} { @@ -47,6 +48,18 @@ func NewIncidentBlock() map[string]interface{} { return payload } +func IntegrateHoustonInChannelBlock() map[string]interface{} { + fields := []*slack.TextBlockObject{ + slack.NewTextBlockObject("mrkdwn", "*please integrate houston in the channel*", false, false), + } + block := slack.NewSectionBlock(nil, fields, nil) + return map[string]interface{}{ + "blocks": []slack.Block{ + block, + }, + } +} + func ExistingIncidentOptionsBlock() map[string]interface{} { return map[string]interface{}{ "blocks": []slack.Block{ diff --git a/internal/processor/slash_command_processor.go b/internal/processor/slash_command_processor.go index 38d9ce6..7b248a8 100644 --- a/internal/processor/slash_command_processor.go +++ b/internal/processor/slash_command_processor.go @@ -4,6 +4,7 @@ import ( "fmt" "houston/internal/processor/action" "houston/model/incident" + "houston/pkg/slackbot" "github.com/slack-go/slack/socketmode" "go.uber.org/zap" @@ -15,11 +16,11 @@ type SlashCommandProcessor struct { slashCommandAction *action.SlashCommandAction } -func NewSlashCommandProcessor(logger *zap.Logger, socketModeClient *socketmode.Client, incidentService *incident.Repository) *SlashCommandProcessor { +func NewSlashCommandProcessor(logger *zap.Logger, socketModeClient *socketmode.Client, incidentService *incident.Repository, slackBot *slackbot.Client) *SlashCommandProcessor { return &SlashCommandProcessor{ logger: logger, socketModeClient: socketModeClient, - slashCommandAction: action.NewSlashCommandAction(incidentService, logger, socketModeClient), + slashCommandAction: action.NewSlashCommandAction(incidentService, logger, socketModeClient, slackBot), } } diff --git a/pkg/slackbot/channel.go b/pkg/slackbot/channel.go index 5928971..48fc0a9 100644 --- a/pkg/slackbot/channel.go +++ b/pkg/slackbot/channel.go @@ -58,3 +58,14 @@ func (c *Client) InviteUsersToConversation(channelId string, userId ...string) { c.logger.Info("successfully invite users to conversation", zap.String("channel_id", channelId), zap.Any("user_ids", userId)) } + +func (c *Client) GetConversationInfo(channelId string) (*slack.Channel, error) { + channel, err := c.socketModeClient.GetConversationInfo(&slack.GetConversationInfoInput{ + ChannelID: channelId, + }) + if err != nil { + c.logger.Info("failed while fetching conversation info", zap.Error(err)) + return nil, err + } + return channel, nil +}