diff --git a/.gitignore b/.gitignore index 61d2566..10b01a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ .vscode/ dist/ +vscode.sh \ No newline at end of file diff --git a/examples/interaction/main.go b/examples/interaction/main.go index bc892bb..104a842 100644 --- a/examples/interaction/main.go +++ b/examples/interaction/main.go @@ -5,8 +5,8 @@ import ( "log" "os" - "github.com/slack-io/slacker" "github.com/slack-go/slack" + "github.com/slack-io/slacker" ) // Implements a basic interactive command. diff --git a/executors.go b/executors.go index e9899ef..6c7d169 100644 --- a/executors.go +++ b/executors.go @@ -1,5 +1,7 @@ package slacker +import "github.com/slack-go/slack/socketmode" + func executeCommand(ctx *CommandContext, handler CommandHandler, middlewares ...CommandMiddlewareHandler) { if handler == nil { return @@ -12,7 +14,7 @@ func executeCommand(ctx *CommandContext, handler CommandHandler, middlewares ... handler(ctx) } -func executeInteraction(ctx *InteractionContext, handler InteractionHandler, middlewares ...InteractionMiddlewareHandler) { +func executeInteraction(ctx *InteractionContext, handler InteractionHandler, request *socketmode.Request, middlewares ...InteractionMiddlewareHandler) { if handler == nil { return } @@ -21,7 +23,7 @@ func executeInteraction(ctx *InteractionContext, handler InteractionHandler, mid handler = middlewares[i](handler) } - handler(ctx) + handler(ctx, request) } func executeJob(ctx *JobContext, handler JobHandler, middlewares ...JobMiddlewareHandler) func() { diff --git a/handler.go b/handler.go index 0b56486..b275ef4 100644 --- a/handler.go +++ b/handler.go @@ -1,5 +1,7 @@ package slacker +import "github.com/slack-go/slack/socketmode" + // CommandMiddlewareHandler represents the command middleware handler function type CommandMiddlewareHandler func(CommandHandler) CommandHandler @@ -10,7 +12,7 @@ type CommandHandler func(*CommandContext) type InteractionMiddlewareHandler func(InteractionHandler) InteractionHandler // InteractionHandler represents the interaction handler function -type InteractionHandler func(*InteractionContext) +type InteractionHandler func(*InteractionContext, *socketmode.Request) // JobMiddlewareHandler represents the job middleware handler function type JobMiddlewareHandler func(JobHandler) JobHandler diff --git a/options.go b/options.go index b3cd724..62e05f4 100644 --- a/options.go +++ b/options.go @@ -182,6 +182,14 @@ func SetUnfurlLinks(unfurlLinks bool) PostOption { } } +// tsv +// SetIconURL sets the icon URL option +func SetIconURL(iconURL string) PostOption { + return func(defaults *postOptions) { + defaults.IconURL = iconURL + } +} + type postOptions struct { Attachments []slack.Attachment ThreadTS string @@ -189,6 +197,8 @@ type postOptions struct { EphemeralUserID string ScheduleTime *time.Time UnfurlLinks *bool + // tsv + IconURL string } // newPostOptions builds our PostOptions from zero or more PostOption. diff --git a/response_writer.go b/response_writer.go index 74dfd88..be64c04 100644 --- a/response_writer.go +++ b/response_writer.go @@ -84,6 +84,11 @@ func (r *Writer) post(channel string, message string, blocks []slack.Block, opti } } + // tsv + if postOptions.IconURL != "" { + opts = append(opts, slack.MsgOptionIconURL(postOptions.IconURL)) + } + _, timestamp, err := r.slackClient.PostMessageContext( r.ctx, channel, diff --git a/slacker.go b/slacker.go index 5284e77..a3eb3bc 100644 --- a/slacker.go +++ b/slacker.go @@ -209,7 +209,9 @@ func (s *Slacker) AddJobMiddleware(middleware JobMiddlewareHandler) { // Listen receives events from Slack and each is handled as needed func (s *Slacker) Listen(ctx context.Context) error { - s.prependHelpHandle() + + // no need at all to handle help command if there are no commands + //s.prependHelpHandle() go func() { for { @@ -314,9 +316,12 @@ func (s *Slacker) Listen(ctx context.Context) error { } // Acknowledge receiving the request - s.socketModeClient.Ack(*socketEvent.Request) - go s.handleInteractionEvent(ctx, &callback) + if callback.Type != slack.InteractionTypeBlockSuggestion { + s.socketModeClient.Ack(*socketEvent.Request) + } + + go s.handleInteractionEvent(ctx, &callback, socketEvent.Request) default: if s.unsupportedEventHandler != nil { @@ -440,7 +445,7 @@ func (s *Slacker) startCronJobs(ctx context.Context) { s.cronClient.Start() } -func (s *Slacker) handleInteractionEvent(ctx context.Context, callback *slack.InteractionCallback) { +func (s *Slacker) handleInteractionEvent(ctx context.Context, callback *slack.InteractionCallback, request *socketmode.Request) { middlewares := make([]InteractionMiddlewareHandler, 0) middlewares = append(middlewares, s.interactionMiddlewares...) @@ -482,14 +487,14 @@ func (s *Slacker) handleInteractionEvent(ctx context.Context, callback *slack.In if interaction != nil { interactionCtx := newInteractionContext(ctx, s.logger, s.slackClient, callback, definition) middlewares = append(middlewares, definition.Middlewares...) - executeInteraction(interactionCtx, definition.Handler, middlewares...) + executeInteraction(interactionCtx, definition.Handler, request, middlewares...) return } s.logger.Debug("unsupported interaction type", "type", callback.Type) if s.unsupportedInteractionHandler != nil { interactionCtx := newInteractionContext(ctx, s.logger, s.slackClient, callback, nil) - executeInteraction(interactionCtx, s.unsupportedInteractionHandler, middlewares...) + executeInteraction(interactionCtx, s.unsupportedInteractionHandler, request, middlewares...) } }