Skip to content

Commit

Permalink
feat: Let the slack API URL be set (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpaulisse authored Apr 15, 2023
1 parent 48bf59b commit c38812c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import "github.com/slack-go/slack"
// ClientOption an option for client values
type ClientOption func(*ClientDefaults)

// WithAPIURL sets the API URL (for testing)
func WithAPIURL(url string) ClientOption {
return func(defaults *ClientDefaults) {
defaults.APIURL = url
}
}

// WithDebug sets debug toggle
func WithDebug(debug bool) ClientOption {
return func(defaults *ClientDefaults) {
Expand All @@ -21,12 +28,14 @@ func WithBotInteractionMode(mode BotInteractionMode) ClientOption {

// ClientDefaults configuration
type ClientDefaults struct {
APIURL string
Debug bool
BotMode BotInteractionMode
}

func newClientDefaults(options ...ClientOption) *ClientDefaults {
config := &ClientDefaults{
APIURL: "", // Empty string will not override default from slack package
Debug: false,
BotMode: BotInteractionModeIgnoreAll,
}
Expand Down
12 changes: 10 additions & 2 deletions slacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ func defaultCleanEventInput(msg string) string {
func NewClient(botToken, appToken string, options ...ClientOption) *Slacker {
defaults := newClientDefaults(options...)

api := slack.New(
botToken,
slackOpts := []slack.Option{
slack.OptionDebug(defaults.Debug),
slack.OptionAppLevelToken(appToken),
}

if defaults.APIURL != "" {
slackOpts = append(slackOpts, slack.OptionAPIURL(defaults.APIURL))
}

api := slack.New(
botToken,
slackOpts...,
)

socketModeClient := socketmode.New(
Expand Down

0 comments on commit c38812c

Please sign in to comment.