diff --git a/pkg/slack/app.go b/pkg/slack/app.go index 4cd9b9b..231e795 100644 --- a/pkg/slack/app.go +++ b/pkg/slack/app.go @@ -19,10 +19,11 @@ import ( var repoRegex = regexp.MustCompile("[a-zA-Z0-9-]+(/[a-zA-Z0-9-]+)?") type App struct { - logger *zap.Logger - disabled bool - api *slack.Client - store kv.Store + logger *zap.Logger + disabled bool + api *slack.Client + store kv.Store + commandName string } type ChannelInfo struct { @@ -40,7 +41,8 @@ func NewApp(logger *zap.Logger, config *Config, store kv.Store) *App { slack.OptionLog(zap.NewStdLog(logger)), slack.OptionAppLevelToken(config.AppToken), ), - store: store, + store: store, + commandName: config.GetCommandName(), } } @@ -194,7 +196,7 @@ func (a *App) messageLoop(ctx context.Context, client *socketmode.Client) { zap.String("text", data.Text), ) - if data.Command != "/gha" { + if data.Command != "/"+a.commandName { client.Ack(*e.Request, map[string]interface{}{ "text": fmt.Sprintf("Unknown command '%s'\n", data.Command)}) return diff --git a/pkg/slack/config.go b/pkg/slack/config.go index 6914c5b..9d57b30 100644 --- a/pkg/slack/config.go +++ b/pkg/slack/config.go @@ -1,11 +1,19 @@ package slack -import "github.com/oursky/github-actions-manager/pkg/kv" +import ( + "github.com/oursky/github-actions-manager/pkg/kv" + "github.com/oursky/github-actions-manager/pkg/utils/defaults" +) type Config struct { - Disabled bool - BotToken string `validate:"required_if=Disabled false"` - AppToken string `validate:"required_if=Disabled false"` + Disabled bool + BotToken string `validate:"required_if=Disabled false"` + AppToken string `validate:"required_if=Disabled false"` + CommandName *string +} + +func (c *Config) GetCommandName() string { + return defaults.Value(c.CommandName, "gha") } var kvNamespace = kv.RegisterNamespace("slack-subscriptions")