Revert "Revert "TP-0000 | restricting incident creation from private channels"" (#63)
* Revert "Revert "TP-0000 | restricting incident creation from private channels (#60)" (#62)"
This reverts commit b3eed5dd63.
* TP-0000 | allow incident creation from channels where houston is invited
* TP-0000 | renaming functions
* TP-0000 | making desc mandatory
This commit is contained in:
committed by
GitHub Enterprise
parent
b3eed5dd63
commit
b135eade9c
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user