diff --git a/defaults.go b/defaults.go index f3e5710..cee3769 100644 --- a/defaults.go +++ b/defaults.go @@ -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) { @@ -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, } diff --git a/slacker.go b/slacker.go index fa83285..f2e3f2a 100644 --- a/slacker.go +++ b/slacker.go @@ -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(