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

Add wrap message template for x plugin #1117

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

mszostok
Copy link
Contributor

@mszostok mszostok commented Jul 2, 2023

Description

Changes proposed in this pull request:

  • Add wrap message template for x plugin

demo

Testing

  1. Create k3d cluster

  2. Start plugin server: env PLUGIN_SERVER_HOST=http://host.k3d.internal go run test/helpers/plugin_server.go

  3. Build x plugin: PLUGIN_TARGETS="x" make build-plugins

  4. Install Botkube with such example config:

    config yaml

    communications:
      default-group:
        socketSlack:
          enabled: true
          channels:
            default:
              name: general
              bindings:
                sources: [ ]
                executors:
                  - bins-management
          appToken: "xapp-1"
          botToken: "xoxb-"
    
    executors:
      bins-management:
        botkube/x:
          enabled: true
          context:
            rbac:
              group:
                type: Static
                static:
                  values: [ "system:masters" ]
          config:
            templates:
              - ref: github.com/mszostok/botkube//cmd/executor/x/templates?ref=x-plugin-wrap-tpl
    
    extraEnv:
      - name: LOG_LEVEL_EXECUTOR_LOCAL-REPO_X
        value: "debug"
    
    plugins:
      repositories:
        local-repo:
          url: http://host.k3d.internal:3000/botkube.yaml
    
    settings:
      log:
        level: "debug"
      clusterName: "labs"
      upgradeNotifier: false
    
    analytics:
      disable: true
    
    configWatcher:
      enabled: false

Example Flux

  1. Install Flux CLI

    @Botkube x install github.com/fluxcd/flux2
    
  2. Initialize flux (it takes a while)

  3. Create Source:

    @Botkube x run flux create source git webapp-latest
                   --url=https://github.com/stefanprodan/podinfo
                   --branch=master
                   --interval=3m
    
  4. List sources:

    @Botkube x run flux get sources git
    

Related issue(s)

@mszostok mszostok added the enhancement New feature or request label Jul 2, 2023
@mszostok mszostok force-pushed the x-plugin-wrap-tpl branch 3 times, most recently from 35dcee5 to 1342f14 Compare July 5, 2023 22:33
@mszostok mszostok marked this pull request as ready for review July 5, 2023 22:34
@mszostok mszostok requested review from a team and PrasadG193 as code owners July 5, 2023 22:34
@mszostok mszostok requested review from josefkarasek and huseyinbabal and removed request for josefkarasek July 5, 2023 22:34
@mszostok mszostok marked this pull request as draft July 5, 2023 23:33
@mszostok mszostok marked this pull request as ready for review July 6, 2023 11:50
Copy link
Contributor

@huseyinbabal huseyinbabal left a comment

Choose a reason for hiding this comment

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

Approved with following feedbacks.

  • When I execute a command, it feels my command is not worked, but actually it takes time.
  • We can maybe introduce a progressing bar in another task as a general solution.

I have prepared a demo for progressing.

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/slack-go/slack"
)

func main() {
	api := slack.New("xoxb-")

	channelID := "" // Slack > Channel > More details > scroll down  and copy

	// Start a goroutine to send progressing updates
	sendProgressingUpdates(api, channelID)

}

func sendProgressingUpdates(api *slack.Client, channelID string) {
	progressText := "Operation in progress..."
	var messageTimestamp string

	// Send the initial message
	_, timestamp, _, err := api.SendMessage(channelID, slack.MsgOptionText(progressText, false), slack.MsgOptionAsUser(true))
	if err != nil {
		log.Fatalf("Failed to send message: %v", err)
	}
	messageTimestamp = timestamp

	// Update the message periodically
	for i := 0; i < 100; i++ {
		time.Sleep(1 * time.Second)
		progressText := fmt.Sprintf("Installation progress: %d%%", i)
		_, updatedTimestamp, _, err := api.UpdateMessage(channelID, messageTimestamp, slack.MsgOptionUpdate(messageTimestamp), slack.MsgOptionText(progressText, false))
		if err != nil {
			log.Printf("Failed to update message: %v", err)
		}
		messageTimestamp = updatedTimestamp
	}
}
slack_progress.mov

@mszostok mszostok merged commit 79d5f05 into kubeshop:main Jul 6, 2023
@mszostok mszostok deleted the x-plugin-wrap-tpl branch July 6, 2023 13:23
@mszostok
Copy link
Contributor Author

mszostok commented Jul 6, 2023

Yes, I also like the interactive message, IMO we should do it in the near future. Huge +1 from my side 👍

@mszostok mszostok mentioned this pull request Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants