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

Render plain text for messages sent in attachments and remove the header #773

Merged
merged 21 commits into from
Sep 30, 2022

Conversation

ezodude
Copy link
Contributor

@ezodude ezodude commented Sep 28, 2022

Description

Changes proposed in this pull request:

  • Slack: large executor output is sent as plaintext files with a related message.
  • SlackSocket: large executor output is sent as plaintext files with a related message.
  • Discord: large executor output is sent as plaintext files with a related message.
  • MatterMost: large executor output is sent as plaintext files with a related message.
  • MSTeams: large executor output is sent as plaintext files with a related message.
  • Adde E2E tests to check file uploads and related messages.

Test

  1. Checkout this branch: gh pr checkout 773
  2. Create the cluster: k3d cluster create.
  3. Set up the general channel in a Slack workspace.
  4. Install BotKube with Slack and test:
# /tmp/pr-773.yaml

communications:
  'default-group':
    slack:
      enabled: true
      channels:
        'default':
          name: 'general'
          notification:
            disabled: false
          bindings:
            executors:
              - kubectl-read-only
            sources:
              - k8s-all-events
      token: "xoxb-.."
      notification:
        type: short

settings:
  clusterName: kind
  log:
    level: debug
    disableColors: false

executors:
  'kubectl-read-only':
    kubectl:
      enabled: true

analytics:
  disable: true

On Slack, in the general channel run:

@BotKube logs botkube-xxpod-idxxx -n botkube

This should produce something similar to ...

SLACK
Screenshot 2022-09-29 at 12 09 33

DISCORD
Screenshot 2022-09-29 at 12 09 51

Related issue(s)

Resolves #750

@ezodude ezodude requested review from a team and PrasadG193 as code owners September 28, 2022 11:24
@mszostok mszostok self-assigned this Sep 28, 2022
@mszostok mszostok added the bug Something isn't working label Sep 28, 2022
@ezodude ezodude changed the title Render plain Render plain text for messages sent in attachments and remove the header Sep 28, 2022
@ezodude
Copy link
Contributor Author

ezodude commented Sep 28, 2022

@mszostok FYI, the PR is code complete.

Feel free to review the code while huseyinbabal fixes the build.

pkg/bot/discord.go Outdated Show resolved Hide resolved
pkg/bot/discord.go Outdated Show resolved Hide resolved
pkg/bot/slack.go Outdated Show resolved Hide resolved
pkg/bot/socketslack.go Outdated Show resolved Hide resolved
pkg/bot/interactive/plaintext.go Show resolved Hide resolved
pkg/bot/teams.go Outdated
resp := b.processMessage(turn.Activity)
if len(resp) >= maxMessageSize {
n, resp := b.processMessage(turn.Activity)
if n >= maxMessageSize {
Copy link
Contributor

Choose a reason for hiding this comment

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

were you able to test that successfully?
Screen Shot 2022-09-29 at 11 14 57

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will double check this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the same issue, but it's prob because I don't have OneDrive configured for my account.

Screenshot 2022-09-29 at 16 47 00

BUT, the response is successful ... after the upload, with the file uploaded to Sharepoint correctly.

{
	"type": "invoke",
	"id": "f:xxxxxxx64a-f47d-b6db-52ec44d0e207",
	"timestamp": "2022-09-29T15:38:40.498Z",
	"localTimestamp": "2022-09-29T16:38:40.498+01:00",
	"localTimezone": "Europe/London",
	"serviceUrl": "https://smba.trafficmanager.net/amer/",
	"channelId": "msteams",
	"from": {
		"id": "29:xxxxxxxxxxxxxxx-iFcXUOYkFq2Fu7ihBVx6xraRHlM3qqPn107rY-IyKeeCvi5xh8Wg",
		"name": "Ezo Saleh",
		"aadObjectId": "xxxxxxx-b667-4eca-850a-af4089c10a41"
	},
	"conversation": {
		"conversationType": "personal",
		"tenantId": "xxxxxxxx-4029-49df-bd97-452fc58e7050",
		"id": "a:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-yIBo7kqU6iiRgpy-CETymAFkmTThXZBIll16zAozfEKO"
	},
	"recipient": {
		"id": "28:xxxxxxxx-70dc-4d28-93a0-eee6a4d22aea",
		"name": "BotKube"
	},
	"locale": "en-GB",
	"suggestedActions": {},
	"entities": [
		{
			"type": "clientInfo"
		}
	],
	"channelData": {
		"legacy": {
			"replyToId": "1:1_xxxx_xxxxx_1l4ATURTMHx5-S0SfLALwplUwTlW_zV3E"
		},
		"source": {
			"name": "message"
		},
		"tenant": {
			"id": "xxxxxxx-xxxx-49df-bd97-452fc58e7050"
		}
	},
	"replyToId": "1664465905885",
	"value": {
		"action": "accept",
		"context": {
			"command": "logs pod/botkube-5cf68ff4-xwk62 -n botkube"
		},
		"type": "fileUpload",
		"uploadInfo": {
			"contentUrl": "https://xxxxxxx-my.sharepoint.com/personal/xxxxx_xxxxxx_onmicrosoft_com/Documents/Applications/BotKube/response.txt",
			"fileType": "txt",
			"name": "response.txt",
			"uniqueId": "xxxxxxx-xxxxxf1xxxxxx-xxx-xxxxxxe",
			"uploadUrl": "https://xxxxxxxx-my.sharepoint.com/personal/xxx_xxxxxx_onmicrosoft_com/_api/v2.0/drive/items/01UJSUYGUG7USXG2XP6FBIBSWZBK3WQUTO/uploadSession?guid='xxxxxxx-9f5-b8fa-eca8d1e824d2'\\u0026overwrite=False\\u0026rename=True\\u0026dc=0\\u0026tempauth=xxxxxxxxxxxxxxxxxxxxxxmZjEtY2UwMC0wMDAwMDAwMDAwMDAva3ViZXNob3AyLW15LnNoYXJlcG9pbnQuY29tQDJhM2VkOWY5LTQwMjktNDlkZi1iZDk3LTQ1MmZjNThlNzA1MCIsImlzcyI6IjAwMDAwMDAzLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMxxxxxxxxx2NjQ0NjU4NDQiLCJleHAiOiIxNjY0NTUyMjQ0IiwiZW5kcG9pbnR1cmwiOiJTMEcwN29EeERJeGROZXpIcGRlbzAwNE9SaXlSZVlldWNSdDg0akJsMmFnPSIsImVuZHBvaW50dXJsTGVuZ3RoIjoiMjIyIiwiaXNsb29wYmFjayI6IlRydWUiLCJjaWQiOiJZekJrTjJFNFl6UXRNMlkyT0MwME9Ua3dMV0ZtWkRrdFpUVTRNVFl3WTJOaU16ZzMiLCJ2ZXIiOiJoYXNoZWRwcm9vZnRva2VuIiwic2l0ZWlkIjoiWkdOaFpUVTBPRE10TVdVMU1pMDBORFJqTFdJelpUZ3RZV0poTXpGbE56RmpPRFkzIiwiYXBwX2Rpc3BsYXluYW1lIjoiTWljcm9zb2Z0IFRlYW1zIFNlcnZpY2VzIiwic2lnbmluX3N0YXRlIjoiW1wia21zaVwiXSIsImFwcGlkIjoiY2MxNWZkNTctMmM2Yy00MTE3LWE4OGMtODNiMWQ1NmI0YmJlIiwidGlkIjoiMmEzZWQ5ZjktxxxxxxxxxOTctNDUyZmM1OGU3MDUwIiwidXBuIjoiZXpvQGt1YmVzaG9wMi5vbm1pY3Jvc29mdC5jb20iLCJwdWlkIjoiMTAwMzIwMDIxMUZFQ0JBMyIsImNhY2hla2V5IjoiMGguZnxtZW1iZXJzaGlwfDEwMDMyMDAyMTFmZWNiYTNAbGl2ZS5jb20iLCJzY3AiOiJncm91cC53cml0ZSBhbGxzaXRlcy53cml0ZSBhbGxwcm9maWxlcy53cml0ZSIsInR0IjoiMiIsInVzZVBlcnNpc3RlbnRDb29raWUiOm51bGwsImlwYWRkciI6IjIwLjE5MC4xMzIuMTA1In0.Yi9QRXE2aHk4U0N5T28zaTBtZ2QvSlRwQkZ3WHByVxxxxxxxx"
		}
	},
	"name": "fileConsent/invoke",
	"relatesTo": {
		"user": {},
		"bot": {},
		"conversation": {}
	},
	"expiration": "0001-01-01T00:00:00Z",
	"semanticAction": {}
}

Copy link
Contributor

@mszostok mszostok Sep 30, 2022

Choose a reason for hiding this comment

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

It's still not working for me, however the directory was created on the OneDrive side 🤔

Screen Shot 2022-09-30 at 11 31 02

@ezodude
Copy link
Contributor Author

ezodude commented Sep 29, 2022

@mszostok moving this to draft to adjust implementations. Will ping you when its ready for review.

@ezodude ezodude marked this pull request as draft September 29, 2022 09:45
@ezodude
Copy link
Contributor Author

ezodude commented Sep 29, 2022

Update

Had to merge in the latest from main which delayed a couple of things.

Issue

  • Cannot parse helm/botkube/templates/service.yaml when lifecycleServer is enabled.

Pending

  • minor refactoring based on here
  • Fix the e2e tests to work with latest from main.

@ezodude ezodude marked this pull request as ready for review September 30, 2022 08:54
Copy link
Contributor

@mszostok mszostok left a comment

Choose a reason for hiding this comment

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

Tested Slack, SocketSlack,and Discord, all works like great 👍

I only failed with MS Teams, but this can be investigated later.

Comment on lines 254 to 255
//resp := interactive.RenderMessage(b.mdFormatter, response)
//err := b.send(dm.Event, req, resp)
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove it :)

pkg/bot/teams.go Outdated
resp := b.processMessage(turn.Activity)
if len(resp) >= maxMessageSize {
n, resp := b.processMessage(turn.Activity)
if n >= maxMessageSize {
Copy link
Contributor

@mszostok mszostok Sep 30, 2022

Choose a reason for hiding this comment

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

It's still not working for me, however the directory was created on the OneDrive side 🤔

Screen Shot 2022-09-30 at 11 31 02

@ezodude ezodude merged commit 4629b10 into kubeshop:main Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Render plain text for messages sent in attachments and remove the header
3 participants