@@ -11,6 +11,7 @@ import (
11
11
koanfyaml "github.com/knadh/koanf/parsers/yaml"
12
12
"github.com/knadh/koanf/providers/env"
13
13
"github.com/knadh/koanf/providers/rawbytes"
14
+ "github.com/mitchellh/mapstructure"
14
15
"golang.org/x/text/cases"
15
16
"golang.org/x/text/language"
16
17
)
@@ -97,7 +98,7 @@ const (
97
98
// DiscordCommPlatformIntegration defines Discord integration.
98
99
DiscordCommPlatformIntegration CommPlatformIntegration = "discord"
99
100
100
- //ElasticsearchCommPlatformIntegration defines Elasticsearch integration.
101
+ // ElasticsearchCommPlatformIntegration defines Elasticsearch integration.
101
102
ElasticsearchCommPlatformIntegration CommPlatformIntegration = "elasticsearch"
102
103
103
104
// WebhookCommPlatformIntegration defines an outgoing webhook integration.
@@ -195,6 +196,18 @@ type IncomingWebhook struct {
195
196
InClusterBaseURL string `yaml:"inClusterBaseURL"`
196
197
}
197
198
199
+ // CloudSlackChannel contains configuration bindings per channel.
200
+ type CloudSlackChannel struct {
201
+ ChannelBindingsByName `yaml:",inline" mapstructure:",squash"`
202
+
203
+ // ChannelID is the Slack ID of the channel.
204
+ // Currently, it is used for AI plugin as it has ability to fetch the Botkube Agent configuration.
205
+ // Later it can be used for deep linking to a given channel, see: https://api.slack.com/reference/deep-linking#app_channel
206
+ ChannelID string `yaml:"channelID"`
207
+ // Alias is an optional public alias for a private channel.
208
+ Alias * string `yaml:"alias,omitempty"`
209
+ }
210
+
198
211
// ChannelBindingsByName contains configuration bindings per channel.
199
212
type ChannelBindingsByName struct {
200
213
Name string `yaml:"name"`
@@ -498,12 +511,12 @@ type SocketSlack struct {
498
511
499
512
// CloudSlack configuration for multi-slack support
500
513
type CloudSlack struct {
501
- Enabled bool `yaml:"enabled"`
502
- Channels IdentifiableMap [ChannelBindingsByName ] `yaml:"channels" validate:"required_if=Enabled true,dive,omitempty,min=1"`
503
- Token string `yaml:"token"`
504
- BotID string `yaml:"botID,omitempty"`
505
- Server GRPCServer `yaml:"server"`
506
- ExecutionEventStreamingDisabled bool `yaml:"executionEventStreamingDisabled"`
514
+ Enabled bool `yaml:"enabled"`
515
+ Channels IdentifiableMap [CloudSlackChannel ] `yaml:"channels" validate:"required_if=Enabled true,dive,omitempty,min=1"`
516
+ Token string `yaml:"token"`
517
+ BotID string `yaml:"botID,omitempty"`
518
+ Server GRPCServer `yaml:"server"`
519
+ ExecutionEventStreamingDisabled bool `yaml:"executionEventStreamingDisabled"`
507
520
}
508
521
509
522
// GRPCServer config for gRPC server
@@ -715,7 +728,20 @@ func LoadWithDefaults(configs [][]byte) (*Config, LoadWithDefaultsDetails, error
715
728
}
716
729
717
730
var cfg Config
718
- err = k .Unmarshal ("" , & cfg )
731
+ err = k .UnmarshalWithConf ("" , & cfg , koanf.UnmarshalConf {
732
+ DecoderConfig : & mapstructure.DecoderConfig {
733
+ Squash : true , // needed to properly unmarshal CloudSlack channel's ChannelBindingsByName
734
+
735
+ // also use defaults from koanf.UnmarshalWithConf
736
+ DecodeHook : mapstructure .ComposeDecodeHookFunc (
737
+ mapstructure .StringToTimeDurationHookFunc (),
738
+ mapstructure .StringToSliceHookFunc ("," ),
739
+ mapstructure .TextUnmarshallerHookFunc ()),
740
+ Metadata : nil ,
741
+ Result : & cfg ,
742
+ WeaklyTypedInput : true ,
743
+ },
744
+ })
719
745
if err != nil {
720
746
return nil , LoadWithDefaultsDetails {}, err
721
747
}
0 commit comments