Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive Message Response Size Handling #1263

Closed
wants to merge 5 commits into from
Closed
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
35 changes: 27 additions & 8 deletions pkg/bot/slack_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,33 @@ func (b *CloudSlack) send(ctx context.Context, event slackMessage, resp interact
var file *slack.File
var err error
if len(markdown) >= slackMaxMessageSize {
file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp)
if err != nil {
return err
}
resp = interactive.CoreMessage{
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,
},
if strings.Contains(resp.Description, "logs") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is a condition for logs? I might be executing kubectl describe ... and still I will need pods dropdown, and that means , describe also should be included. Could you please take a look at this part again?

Copy link
Contributor Author

@sadath-12 sadath-12 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean describe should also give file instead ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, maybe there is a misunderstanding. The primary motivation is to not send an attachment for the interactive blocks. Those blocks are the interactive dropdown elements e.g. namespace, name, verb . So, once you execute kubectl it will show you interactive elements, so that elements should be limited so there wont be an attachment. More concrete example is, once you select namespace, it will return resources (e.g. pods), if those pods > 100 you will see an attachment in the slack UI, you need to prevent that.

file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp)
if err != nil {
return err
}
resp = interactive.CoreMessage{
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,
},
}
} else {
newBlocks := strings.Split(resp.BaseBody.CodeBlock, "\n")

newBlocks = newBlocks[:MaxListingLimit]

result := strings.Join(newBlocks, "\n")

resp = interactive.CoreMessage{
Description: resp.Description,
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,

BaseBody: api.Body{
CodeBlock: result,
},
},
}
}
}

Expand Down
39 changes: 31 additions & 8 deletions pkg/bot/slack_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import (
// - split to multiple files in a separate package,
// - review all the methods and see if they can be simplified.

const (
MaxListingLimit = 45
)

var _ Bot = &SocketSlack{}

// SocketSlack listens for user's message, execute commands and sends back the response.
Expand Down Expand Up @@ -407,14 +411,33 @@ func (b *SocketSlack) send(ctx context.Context, event slackMessage, resp interac
var file *slack.File
var err error
if len(markdown) >= slackMaxMessageSize {
file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp)
if err != nil {
return err
}
resp = interactive.CoreMessage{
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,
},
if strings.Contains(resp.Description, "logs") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp)
if err != nil {
return err
}
resp = interactive.CoreMessage{
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,
},
}
} else {
newBlocks := strings.Split(resp.BaseBody.CodeBlock, "\n")

newBlocks = newBlocks[:MaxListingLimit]

result := strings.Join(newBlocks, "\n")

resp = interactive.CoreMessage{
Description: resp.Description,
Message: api.Message{
PlaintextInputs: resp.PlaintextInputs,

BaseBody: api.Body{
CodeBlock: result,
},
},
}
}
}

Expand Down
Loading