From d45ea5cf8049042e24e5eed6a1b4a6a1e7f18316 Mon Sep 17 00:00:00 2001 From: "tsv.titan@gmail.com" Date: Mon, 5 Aug 2024 14:09:53 +0300 Subject: [PATCH 1/4] Added request to interactive handler --- .gitignore | 1 + examples/interaction/main.go | 2 +- executors.go | 6 ++++-- handler.go | 4 +++- slacker.go | 8 ++++---- 5 files changed, 13 insertions(+), 8 deletions(-) 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/slacker.go b/slacker.go index 5284e77..728f413 100644 --- a/slacker.go +++ b/slacker.go @@ -316,7 +316,7 @@ func (s *Slacker) Listen(ctx context.Context) error { // Acknowledge receiving the request s.socketModeClient.Ack(*socketEvent.Request) - go s.handleInteractionEvent(ctx, &callback) + go s.handleInteractionEvent(ctx, &callback, socketEvent.Request) default: if s.unsupportedEventHandler != nil { @@ -440,7 +440,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 +482,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...) } } From d4a7539c17d2ee0cb7b635a59395d19b02471242 Mon Sep 17 00:00:00 2001 From: "tsv.titan@gmail.com" Date: Mon, 5 Aug 2024 15:02:05 +0300 Subject: [PATCH 2/4] Added fixed for InteractionTypeBlockSuggestion --- slacker.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slacker.go b/slacker.go index 728f413..c676897 100644 --- a/slacker.go +++ b/slacker.go @@ -314,7 +314,10 @@ func (s *Slacker) Listen(ctx context.Context) error { } // Acknowledge receiving the request - s.socketModeClient.Ack(*socketEvent.Request) + + if callback.Type != slack.InteractionTypeBlockSuggestion { + s.socketModeClient.Ack(*socketEvent.Request) + } go s.handleInteractionEvent(ctx, &callback, socketEvent.Request) From 22dc3b5a6dc895df6f8ec1852354e874c230ca77 Mon Sep 17 00:00:00 2001 From: "tsv.titan@gmail.com" Date: Mon, 4 Nov 2024 17:51:51 +0200 Subject: [PATCH 3/4] Removed help def by default --- slacker.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slacker.go b/slacker.go index c676897..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 { From 4dfe7d6c4cf0d7f5742d5ff694a82cdd329a09ec Mon Sep 17 00:00:00 2001 From: "tsv.titan@gmail.com" Date: Thu, 23 Oct 2025 14:49:58 +0300 Subject: [PATCH 4/4] Added Icon URL to post --- options.go | 10 ++++++++++ response_writer.go | 5 +++++ 2 files changed, 15 insertions(+) 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,