From 7e3276f55f773e201c1cda59e305bb9d6d1f72ff Mon Sep 17 00:00:00 2001 From: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> Date: Mon, 18 Sep 2023 10:20:57 +0000 Subject: [PATCH 1/5] Add: Interactive Message Response Size Handling Signed-off-by: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> --- pkg/bot/slack_cloud.go | 38 ++++++++++++++++++++++++++++++-------- pkg/bot/slack_socket.go | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 862085bb1..0ee1f8732 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -519,14 +519,36 @@ 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[:45] + + result := strings.Join(newBlocks, "\n") + + fmt.Println("result is",result) + + 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..85da36704 100644 --- a/pkg/bot/slack_socket.go +++ b/pkg/bot/slack_socket.go @@ -407,14 +407,36 @@ 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[:45] + + result := strings.Join(newBlocks, "\n") + + fmt.Println("result is",result) + + resp = interactive.CoreMessage{ + Description: resp.Description, + Message: api.Message{ + PlaintextInputs: resp.PlaintextInputs, + + BaseBody: api.Body{ + CodeBlock: result, + }, + }, + } } } From 6c0a1b4bd428c24bb9f0fec1783dccbcdffac2e7 Mon Sep 17 00:00:00 2001 From: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> Date: Mon, 18 Sep 2023 10:23:18 +0000 Subject: [PATCH 2/5] Add: Interactive Message Response Size Handling Signed-off-by: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> --- pkg/bot/slack_cloud.go | 3 ++- pkg/bot/slack_socket.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 0ee1f8732..9a092686e 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -42,6 +42,7 @@ const ( maxRetries = 30 successIntervalDuration = 3 * time.Minute quotaExceededMsg = "Quota exceeded detected. Stopping reconnecting to Botkube Cloud gRPC API..." + MaxListingLimit = 45 ) var _ Bot = &CloudSlack{} @@ -533,7 +534,7 @@ func (b *CloudSlack) send(ctx context.Context, event slackMessage, resp interact } else { newBlocks := strings.Split(resp.BaseBody.CodeBlock, "\n") - newBlocks = newBlocks[:45] + newBlocks = newBlocks[:MaxListingLimit] result := strings.Join(newBlocks, "\n") diff --git a/pkg/bot/slack_socket.go b/pkg/bot/slack_socket.go index 85da36704..b357841d6 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. @@ -421,7 +425,7 @@ func (b *SocketSlack) send(ctx context.Context, event slackMessage, resp interac } else { newBlocks := strings.Split(resp.BaseBody.CodeBlock, "\n") - newBlocks = newBlocks[:45] + newBlocks = newBlocks[:MaxListingLimit] result := strings.Join(newBlocks, "\n") From 84ff20451067816e81987e6cdef7f38b0e98b400 Mon Sep 17 00:00:00 2001 From: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:59:24 +0000 Subject: [PATCH 3/5] Fix: removed redeclared of variable Signed-off-by: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> --- pkg/bot/slack_cloud.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 9a092686e..082f2476f 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -42,7 +42,6 @@ const ( maxRetries = 30 successIntervalDuration = 3 * time.Minute quotaExceededMsg = "Quota exceeded detected. Stopping reconnecting to Botkube Cloud gRPC API..." - MaxListingLimit = 45 ) var _ Bot = &CloudSlack{} From a470bf459cdef7d42be53c2669cef6cdb44b88e0 Mon Sep 17 00:00:00 2001 From: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:13:43 +0000 Subject: [PATCH 4/5] Fix: go linting Signed-off-by: syedsadath-17 <90619459+sadath-12@users.noreply.github.com> --- pkg/bot/slack_cloud.go | 2 -- pkg/bot/slack_socket.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 082f2476f..7b8e5faf9 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -537,8 +537,6 @@ func (b *CloudSlack) send(ctx context.Context, event slackMessage, resp interact result := strings.Join(newBlocks, "\n") - fmt.Println("result is",result) - resp = interactive.CoreMessage{ Description: resp.Description, Message: api.Message{ diff --git a/pkg/bot/slack_socket.go b/pkg/bot/slack_socket.go index b357841d6..ad1d5cc77 100644 --- a/pkg/bot/slack_socket.go +++ b/pkg/bot/slack_socket.go @@ -429,8 +429,6 @@ func (b *SocketSlack) send(ctx context.Context, event slackMessage, resp interac result := strings.Join(newBlocks, "\n") - fmt.Println("result is",result) - resp = interactive.CoreMessage{ Description: resp.Description, Message: api.Message{ From b9a2242c02e0f971b640580c860cf0b308d7bb47 Mon Sep 17 00:00:00 2001 From: sadath-12 Date: Mon, 18 Sep 2023 18:28:45 +0530 Subject: [PATCH 5/5] go lint fix Signed-off-by: sadath-12 --- pkg/bot/slack_cloud.go | 1 - pkg/bot/slack_socket.go | 1 - 2 files changed, 2 deletions(-) diff --git a/pkg/bot/slack_cloud.go b/pkg/bot/slack_cloud.go index 7b8e5faf9..954141e02 100644 --- a/pkg/bot/slack_cloud.go +++ b/pkg/bot/slack_cloud.go @@ -520,7 +520,6 @@ func (b *CloudSlack) send(ctx context.Context, event slackMessage, resp interact var err error if len(markdown) >= slackMaxMessageSize { if strings.Contains(resp.Description, "logs") { - file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp) if err != nil { return err diff --git a/pkg/bot/slack_socket.go b/pkg/bot/slack_socket.go index ad1d5cc77..3bd8bfcf5 100644 --- a/pkg/bot/slack_socket.go +++ b/pkg/bot/slack_socket.go @@ -412,7 +412,6 @@ func (b *SocketSlack) send(ctx context.Context, event slackMessage, resp interac var err error if len(markdown) >= slackMaxMessageSize { if strings.Contains(resp.Description, "logs") { - file, err = uploadFileToSlack(ctx, event.Channel, resp, b.client, event.ThreadTimeStamp) if err != nil { return err