Skip to content

Commit

Permalink
Support channel-based group mapping for Cloud Teams
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Dec 1, 2023
1 parent 871c9f3 commit 9734796
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
39 changes: 25 additions & 14 deletions pkg/api/cloudteams/cloud_teams.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/bot/teams_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ func (b *CloudTeams) handleStreamMessage(ctx context.Context, data *pb.CloudActi
}
switch act.Type {
case schema.Message, schema.Invoke:
b.log.WithField("message", formatx.StructDumper().Sdump(act)).Debug("Processing Cloud message...")
b.log.WithFields(logrus.Fields{
"message": formatx.StructDumper().Sdump(act),
"conversationDisplayName": data.ConversationDisplayName,
}).Debug("Processing Cloud message...")
channel, exists, err := b.getChannelForActivity(act)
if err != nil {
b.log.WithError(err).Error("cannot extract message channel id, processing with empty...")
}

msg := b.processMessage(ctx, act, channel, exists)
msg := b.processMessage(ctx, act, channel, data.ConversationDisplayName, exists)
if msg.IsEmpty() {
b.log.WithField("activityID", act.ID).Debug("Empty message... Skipping sending response")
return nil, nil
Expand All @@ -287,7 +289,7 @@ func (b *CloudTeams) handleStreamMessage(ctx context.Context, data *pb.CloudActi
}
}

func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, channel teamsCloudChannelConfigByID, exists bool) interactive.CoreMessage {
func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, channel teamsCloudChannelConfigByID, channelDisplayName string, exists bool) interactive.CoreMessage {
trimmedMsg := b.trimBotMention(act.Text)

e := b.executorFactory.NewDefault(execute.NewDefaultInput{
Expand All @@ -301,6 +303,7 @@ func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, ch
ExecutorBindings: channel.Bindings.Executors,
SourceBindings: channel.Bindings.Sources,
CommandOrigin: command.TypedOrigin,
DisplayName: channelDisplayName,
},
Message: trimmedMsg,
User: execute.UserInput{
Expand Down
9 changes: 8 additions & 1 deletion pkg/execute/plugin_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ func (e *PluginExecutor) Execute(ctx context.Context, bindings []string, slackSt
return interactive.CoreMessage{}, fmt.Errorf("while collecting configs: %w", err)
}

channel := cmdCtx.Conversation.DisplayName
if channel == "" {
channel = cmdCtx.Conversation.ID
}

input := plugin.KubeConfigInput{
Channel: cmdCtx.Conversation.DisplayName,
Channel: channel,
}
e.log.WithField("input", input).Debug("Generating Kubeconfig...")

kubeconfig, err := plugin.GenerateKubeConfig(e.restCfg, e.cfg.Settings.ClusterName, plugins[0].Context, input)
if err != nil {
return interactive.CoreMessage{}, fmt.Errorf("while generating kube config: %w", err)
Expand Down
1 change: 1 addition & 0 deletions proto/cloud_teams.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ message Message {

message CloudActivity {
bytes event = 1;
string conversationDisplayName = 2;
}

service CloudTeams {
Expand Down

0 comments on commit 9734796

Please sign in to comment.