Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.vscode/
dist/
vscode.sh
2 changes: 1 addition & 1 deletion examples/interaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions executors.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,23 @@ 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
ReplaceMessageTS string
EphemeralUserID string
ScheduleTime *time.Time
UnfurlLinks *bool
// tsv
IconURL string
}

// newPostOptions builds our PostOptions from zero or more PostOption.
Expand Down
5 changes: 5 additions & 0 deletions response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions slacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)

Expand Down Expand Up @@ -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...)
}
}

Expand Down
Loading