diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 862085bb1..954141e02 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -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") { + 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, + }, + }, + } } } diff --git a/pkg/bot/slack_socket.go b/pkg/bot/slack_socket.go index f865f1169..3bd8bfcf5 100644 --- a/pkg/bot/slack_socket.go +++ b/pkg/bot/slack_socket.go @@ -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. @@ -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") { + 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, + }, + }, + } } }