/
bot.go
85 lines (68 loc) · 1.94 KB
/
bot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package bot
import (
"context"
"github.com/kubeshop/botkube/internal/analytics"
"github.com/kubeshop/botkube/internal/health"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/execute"
"github.com/kubeshop/botkube/pkg/notifier"
)
const (
platformMessageWorkersCount = 10
platformMessageChannelSize = 100
)
// Bot connects to communication channels and reads/sends messages. It is a two-way integration.
type Bot interface {
Start(ctx context.Context) error
GetStatus() health.PlatformStatus
notifier.Bot
}
type Status struct {
Status health.PlatformStatusMsg
Restarts string
Reason health.FailureReasonMsg
}
// ExecutorFactory facilitates creation of execute.Executor instances.
type ExecutorFactory interface {
NewDefault(cfg execute.NewDefaultInput) execute.Executor
}
// AnalyticsReporter defines a reporter that collects analytics data.
type AnalyticsReporter interface {
// ReportBotEnabled reports an enabled bot.
ReportBotEnabled(platform config.CommPlatformIntegration, commGroupIdx int) error
}
// FatalErrorAnalyticsReporter reports a fatal errors.
type FatalErrorAnalyticsReporter interface {
AnalyticsReporter
// ReportFatalError reports a fatal app error.
ReportFatalError(err error) error
// Close cleans up the reporter resources.
Close() error
}
// AnalyticsCommandReporter defines a reporter that collects analytics data.
type AnalyticsCommandReporter interface {
FatalErrorAnalyticsReporter
ReportCommand(in analytics.ReportCommandInput) error
}
type channelConfigByID struct {
config.ChannelBindingsByID
alias string
notify bool
name string
}
type channelConfigByName struct {
config.ChannelBindingsByName
alias string
notify bool
}
type CommGroupMetadata struct {
Name string
Index int
}
func AsNotifiers(bots map[string]Bot) []notifier.Bot {
notifiers := make([]notifier.Bot, 0, len(bots))
for _, bot := range bots {
notifiers = append(notifiers, bot)
}
return notifiers
}