bot

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WebSocketProtocol stores protocol initials for web socket
	WebSocketProtocol = "ws://"
	// WebSocketSecureProtocol stores protocol initials for web socket
	WebSocketSecureProtocol = "wss://"
)

Variables

This section is empty.

Functions

func AsNotifiers added in v1.0.0

func AsNotifiers(bots map[string]Bot) []notifier.Bot

func IsValidNonInteractiveSingleSection added in v1.0.0

func IsValidNonInteractiveSingleSection(msg interactive.CoreMessage) error

Types

type AnalyticsCommandReporter added in v1.6.0

type AnalyticsCommandReporter interface {
	FatalErrorAnalyticsReporter
	ReportCommand(in analytics.ReportCommandInput) error
}

AnalyticsCommandReporter defines a reporter that collects analytics data.

type AnalyticsReporter added in v0.13.0

type AnalyticsReporter interface {
	// ReportBotEnabled reports an enabled bot.
	ReportBotEnabled(platform config.CommPlatformIntegration, commGroupIdx int) error
}

AnalyticsReporter defines a reporter that collects analytics data.

type Bot

type Bot interface {
	Start(ctx context.Context) error
	GetStatus() health.PlatformStatus
	notifier.Bot
}

Bot connects to communication channels and reads/sends messages. It is a two-way integration.

type CloudSlack added in v1.1.0

type CloudSlack struct {
	// contains filtered or unexported fields
}

CloudSlack listens for user's message, execute commands and sends back the response.

func NewCloudSlack added in v1.1.0

func NewCloudSlack(log logrus.FieldLogger,
	commGroupMetadata CommGroupMetadata,
	cfg config.CloudSlack,
	clusterName string,
	executorFactory ExecutorFactory,
	reporter AnalyticsCommandReporter) (*CloudSlack, error)

func (*CloudSlack) BotName added in v1.1.0

func (b *CloudSlack) BotName() string

func (*CloudSlack) GetStatus added in v1.5.0

func (b *CloudSlack) GetStatus() health.PlatformStatus

GetStatus gets bot status.

func (*CloudSlack) IntegrationName added in v1.1.0

func (b *CloudSlack) IntegrationName() config.CommPlatformIntegration

func (*CloudSlack) NotificationsEnabled added in v1.1.0

func (b *CloudSlack) NotificationsEnabled(channelName string) bool

NotificationsEnabled returns current notification status for a given channel name.

func (*CloudSlack) SendMessage added in v1.1.0

func (b *CloudSlack) SendMessage(ctx context.Context, msg interactive.CoreMessage, sourceBindings []string) error

func (*CloudSlack) SendMessageToAll added in v1.1.0

func (b *CloudSlack) SendMessageToAll(ctx context.Context, msg interactive.CoreMessage) error

func (*CloudSlack) SetNotificationsEnabled added in v1.1.0

func (b *CloudSlack) SetNotificationsEnabled(channelName string, enabled bool) error

SetNotificationsEnabled sets a new notification status for a given channel name.

func (*CloudSlack) Start added in v1.1.0

func (b *CloudSlack) Start(ctx context.Context) error

func (*CloudSlack) Type added in v1.1.0

func (b *CloudSlack) Type() config.IntegrationType

type CloudTeams added in v1.6.0

type CloudTeams struct {
	// contains filtered or unexported fields
}

CloudTeams listens for user's messages, execute commands and sends back the response. It sends also source notifications.

User message (executors) flow:

+-------------+       +-------------+      +-------------+
|   MS Teams' | REST  |   Cloud     | REST |  Pub/Sub    |
|   message   +------>|   router    +----->|  #bot       |
+-------------+       +-------------+      +-------+-----+
                                                   v
+-------------+       +-------------+      +-------------+
|  Pub/Sub    | gRPC  |  Agent      | gRPC |  Cloud      |
|  #agent     |<------+  CloudTeams |<-----+  processor  |
+------+------+       +-------------+      +-------------+
       |
+------v------+       +-------------+
|  Cloud      | REST  |   MS Teams' |
|  processor  |+----->|   channel   |
+-------------+       +-------------+

Notification (sources) flow:

+-------------+       +-------------+      +-------------+
|   Source    | gRPC  |  Agent      | gRPC |  Cloud      |
|   message   +------>|  CloudTeams +----->|  router     |
+-------------+       +-------------+      +-------+-----+
                                                   v
+-------------+       +-------------+      +-------------+
|  MS Teams'  | REST  |  Cloud      | REST |  Pub/Sub    |
|  channel    |<------+  processor  |<-----+  #agent     |
+------+------+       +-------------+      +-------------+

func NewCloudTeams added in v1.6.0

func NewCloudTeams(
	log logrus.FieldLogger,
	commGroupMetadata CommGroupMetadata,
	cfg config.CloudTeams,
	clusterName string,
	executorFactory ExecutorFactory,
	reporter AnalyticsCommandReporter) (*CloudTeams, error)

NewCloudTeams returns a new CloudTeams instance.

func (*CloudTeams) BotName added in v1.6.0

func (b *CloudTeams) BotName() string

BotName returns the Bot name.

func (*CloudTeams) GetStatus added in v1.6.0

func (b *CloudTeams) GetStatus() health.PlatformStatus

GetStatus gets bot status.

func (*CloudTeams) IntegrationName added in v1.6.0

func (b *CloudTeams) IntegrationName() config.CommPlatformIntegration

IntegrationName describes the integration name.

func (*CloudTeams) NotificationsEnabled added in v1.6.0

func (b *CloudTeams) NotificationsEnabled(channelID string) bool

NotificationsEnabled returns current notification status for a given channel ID.

func (*CloudTeams) SendMessage added in v1.6.0

func (b *CloudTeams) SendMessage(ctx context.Context, msg interactive.CoreMessage, sourceBindings []string) error

SendMessage sends the message to MS CloudTeams to selected conversations.

func (*CloudTeams) SendMessageToAll added in v1.6.0

func (b *CloudTeams) SendMessageToAll(ctx context.Context, msg interactive.CoreMessage) error

SendMessageToAll sends the message to MS CloudTeams to all conversations even if notifications are disabled.

func (*CloudTeams) SetNotificationsEnabled added in v1.6.0

func (b *CloudTeams) SetNotificationsEnabled(channelID string, enabled bool) error

SetNotificationsEnabled sets a new notification status for a given channel ID.

func (*CloudTeams) Start added in v1.6.0

func (b *CloudTeams) Start(ctx context.Context) error

Start MS Teams server to serve messages from Teams client

func (*CloudTeams) Type added in v1.6.0

func (b *CloudTeams) Type() config.IntegrationType

Type describes the integration type.

type CommGroupMetadata added in v1.6.0

type CommGroupMetadata struct {
	Name  string
	Index int
}

type Discord added in v0.13.0

type Discord struct {
	// contains filtered or unexported fields
}

Discord listens for user's message, execute commands and sends back the response.

func NewDiscord added in v0.13.0

func NewDiscord(log logrus.FieldLogger, commGroupMetadata CommGroupMetadata, cfg config.Discord, executorFactory ExecutorFactory, reporter AnalyticsReporter) (*Discord, error)

NewDiscord creates a new Discord instance.

func (*Discord) BotName added in v0.14.0

func (b *Discord) BotName() string

BotName returns the Bot name.

func (*Discord) GetStatus added in v1.5.0

func (b *Discord) GetStatus() health.PlatformStatus

GetStatus gets bot status.

func (*Discord) IntegrationName added in v0.13.0

func (b *Discord) IntegrationName() config.CommPlatformIntegration

IntegrationName describes the integration name.

func (*Discord) NotificationsEnabled added in v0.13.0

func (b *Discord) NotificationsEnabled(channelID string) bool

NotificationsEnabled returns current notification status for a given channel ID.

func (*Discord) SendMessage added in v0.13.0

func (b *Discord) SendMessage(_ context.Context, msg interactive.CoreMessage, sourceBindings []string) error

SendMessage sends interactive message to selected Discord channels. Context is not supported by client: See https://github.com/bwmarrin/discordgo/issues/752.

func (*Discord) SendMessageToAll added in v0.16.0

func (b *Discord) SendMessageToAll(_ context.Context, msg interactive.CoreMessage) error

SendMessageToAll sends interactive message to all Discord channels. Context is not supported by client: See https://github.com/bwmarrin/discordgo/issues/752.

func (*Discord) SetNotificationsEnabled added in v0.13.0

func (b *Discord) SetNotificationsEnabled(channelID string, enabled bool) error

SetNotificationsEnabled sets a new notification status for a given channel ID.

func (*Discord) Start added in v0.13.0

func (b *Discord) Start(ctx context.Context) error

func (*Discord) Type added in v0.13.0

func (b *Discord) Type() config.IntegrationType

Type describes the integration type.

type DiscordRenderer added in v1.0.0

type DiscordRenderer struct {
	// contains filtered or unexported fields
}

DiscordRenderer provides functionality to render Discord specific messages from a generic models.

func NewDiscordRenderer added in v1.0.0

func NewDiscordRenderer() *DiscordRenderer

NewDiscordRenderer returns new DiscordRenderer instance.

func (*DiscordRenderer) MessageToMarkdown added in v1.0.0

func (d *DiscordRenderer) MessageToMarkdown(in interactive.CoreMessage) string

MessageToMarkdown renders message in Markdown format.

func (*DiscordRenderer) NonInteractiveSectionToCard added in v1.0.0

func (d *DiscordRenderer) NonInteractiveSectionToCard(msg interactive.CoreMessage) (discordgo.MessageEmbed, error)

NonInteractiveSectionToCard returns MessageEmbed for the given event message. Note: It cannot be used for other messages as we take into account only first message section with limited primitives: - TextFields - BulletLists - Timestamp It should be removed once we will add support for a proper message renderer.

type ExecutorFactory added in v0.13.0

type ExecutorFactory interface {
	NewDefault(cfg execute.NewDefaultInput) execute.Executor
}

ExecutorFactory facilitates creation of execute.Executor instances.

type FatalErrorAnalyticsReporter added in v0.13.0

type FatalErrorAnalyticsReporter interface {
	AnalyticsReporter

	// ReportFatalError reports a fatal app error.
	ReportFatalError(err error) error

	// Close cleans up the reporter resources.
	Close() error
}

FatalErrorAnalyticsReporter reports a fatal errors.

type Mattermost added in v0.13.0

type Mattermost struct {
	// contains filtered or unexported fields
}

Mattermost listens for user's message, execute commands and sends back the response.

func NewMattermost added in v0.13.0

func NewMattermost(ctx context.Context, log logrus.FieldLogger, commGroupMetadata CommGroupMetadata, cfg config.Mattermost, executorFactory ExecutorFactory, reporter AnalyticsReporter) (*Mattermost, error)

NewMattermost creates a new Mattermost instance.

func (*Mattermost) BotName added in v0.14.0

func (b *Mattermost) BotName() string

BotName returns the Bot name.

func (*Mattermost) GetStatus added in v1.5.0

func (b *Mattermost) GetStatus() health.PlatformStatus

GetStatus gets bot status.

func (*Mattermost) IntegrationName added in v0.13.0

func (b *Mattermost) IntegrationName() config.CommPlatformIntegration

IntegrationName describes the notifier integration name.

func (*Mattermost) NotificationsEnabled added in v0.13.0

func (b *Mattermost) NotificationsEnabled(channelID string) bool

NotificationsEnabled returns current notification status for a given channel ID.

func (*Mattermost) SendMessage added in v0.13.0

func (b *Mattermost) SendMessage(ctx context.Context, msg interactive.CoreMessage, sourceBindings []string) error

SendMessage sends message to selected Mattermost channels.

func (*Mattermost) SendMessageToAll added in v0.16.0

func (b *Mattermost) SendMessageToAll(ctx context.Context, msg interactive.CoreMessage) error

SendMessageToAll sends message to all Mattermost channels.

func (*Mattermost) SetNotificationsEnabled added in v0.13.0

func (b *Mattermost) SetNotificationsEnabled(channelID string, enabled bool) error

SetNotificationsEnabled sets a new notification status for a given channel ID.

func (*Mattermost) Start added in v0.13.0

func (b *Mattermost) Start(ctx context.Context) error

func (*Mattermost) Type added in v0.13.0

func (b *Mattermost) Type() config.IntegrationType

Type describes the notifier type.

type MattermostRenderer added in v1.0.0

type MattermostRenderer struct {
	// contains filtered or unexported fields
}

MattermostRenderer provides functionality to render Mattermost specific messages from a generic models.

func NewMattermostRenderer added in v1.0.0

func NewMattermostRenderer() *MattermostRenderer

NewMattermostRenderer returns new MattermostRenderer instance.

func (*MattermostRenderer) MessageToMarkdown added in v1.0.0

func (d *MattermostRenderer) MessageToMarkdown(in interactive.CoreMessage) string

MessageToMarkdown renders message in Markdown format.

func (*MattermostRenderer) NonInteractiveSectionToCard added in v1.0.0

func (d *MattermostRenderer) NonInteractiveSectionToCard(msg interactive.CoreMessage) ([]*model.SlackAttachment, error)

NonInteractiveSectionToCard returns MessageEmbed for the given event message. Note: It cannot be used for other messages as we take into account only first message section with limited primitives: - TextFields - BulletLists - Timestamp It should be removed once we will add support for a proper message renderer.

type SlackMessageStatusTracker added in v1.3.0

type SlackMessageStatusTracker struct {
	// contains filtered or unexported fields
}

SlackMessageStatusTracker marks messages with emoji for easy tracking the status of Slack messages.

func NewSlackMessageStatusTracker added in v1.3.0

func NewSlackMessageStatusTracker(log logrus.FieldLogger, client SlackReactionClient) *SlackMessageStatusTracker

NewSlackMessageStatusTracker creates a new instance of SlackMessageStatusTracker.

func (*SlackMessageStatusTracker) GetMsgRef added in v1.3.0

func (b *SlackMessageStatusTracker) GetMsgRef(event slackMessage) *slack.ItemRef

GetMsgRef retrieves the Slack item reference for a given event. It returns nil if the message doesn't support reactions or lacks necessary information.

func (*SlackMessageStatusTracker) MarkAsProcessed added in v1.3.0

func (b *SlackMessageStatusTracker) MarkAsProcessed(msgRef *slack.ItemRef)

MarkAsProcessed marks a message as processed by removing the "eyes" reaction and adding the "heavy_check_mark" reaction. If msgRef is nil, no action is performed.

func (*SlackMessageStatusTracker) MarkAsProcessedWithCustomEmoji added in v1.6.0

func (b *SlackMessageStatusTracker) MarkAsProcessedWithCustomEmoji(msgRef *slack.ItemRef, emoji string)

func (*SlackMessageStatusTracker) MarkAsReceived added in v1.3.0

func (b *SlackMessageStatusTracker) MarkAsReceived(msgRef *slack.ItemRef)

MarkAsReceived marks a message as received by adding the "eyes" reaction. If msgRef is nil, no action is performed.

type SlackReactionClient added in v1.3.0

type SlackReactionClient interface {
	AddReaction(name string, item slack.ItemRef) error
	RemoveReaction(name string, item slack.ItemRef) error
}

SlackReactionClient defines the interface for managing reactions on Slack messages.

type SlackRenderer added in v0.14.0

type SlackRenderer struct {
	// contains filtered or unexported fields
}

SlackRenderer provides functionality to render Slack specific messages from a generic models.

func NewSlackRenderer added in v0.14.0

func NewSlackRenderer() *SlackRenderer

NewSlackRenderer returns new SlackRenderer instance.

func (*SlackRenderer) MessageToMarkdown added in v1.0.0

func (b *SlackRenderer) MessageToMarkdown(in interactive.CoreMessage) string

MessageToMarkdown renders message in Markdown format.

func (*SlackRenderer) RenderAsSlackBlocks added in v0.14.0

func (b *SlackRenderer) RenderAsSlackBlocks(msg interactive.CoreMessage) []slack.Block

RenderAsSlackBlocks returns the Slack message blocks for a given input message.

func (*SlackRenderer) RenderInteractiveMessage added in v0.14.0

func (b *SlackRenderer) RenderInteractiveMessage(msg interactive.CoreMessage) slack.MsgOption

RenderInteractiveMessage returns Slack message based on the input msg.

func (*SlackRenderer) RenderModal added in v0.14.0

RenderModal returns a modal request view based on a given message.

type SocketSlack added in v0.14.0

type SocketSlack struct {
	// contains filtered or unexported fields
}

SocketSlack listens for user's message, execute commands and sends back the response.

func NewSocketSlack added in v0.14.0

func NewSocketSlack(log logrus.FieldLogger, commGroupMetadata CommGroupMetadata, cfg config.SocketSlack, executorFactory ExecutorFactory, reporter socketSlackAnalyticsReporter) (*SocketSlack, error)

NewSocketSlack creates a new SocketSlack instance.

func (*SocketSlack) BotName added in v0.14.0

func (b *SocketSlack) BotName() string

BotName returns the Bot name.

func (*SocketSlack) GetStatus added in v1.5.0

func (b *SocketSlack) GetStatus() health.PlatformStatus

func (*SocketSlack) IntegrationName added in v0.14.0

func (b *SocketSlack) IntegrationName() config.CommPlatformIntegration

IntegrationName describes the notifier integration name.

func (*SocketSlack) NotificationsEnabled added in v0.14.0

func (b *SocketSlack) NotificationsEnabled(channelName string) bool

NotificationsEnabled returns current notification status for a given channel name.

func (*SocketSlack) SendMessage added in v0.14.0

func (b *SocketSlack) SendMessage(ctx context.Context, msg interactive.CoreMessage, sourceBindings []string) error

SendMessage sends message with interactive sections to selected Slack channels.

func (*SocketSlack) SendMessageToAll added in v0.16.0

func (b *SocketSlack) SendMessageToAll(ctx context.Context, msg interactive.CoreMessage) error

SendMessageToAll sends message with interactive sections to all Slack channels.

func (*SocketSlack) SetNotificationsEnabled added in v0.14.0

func (b *SocketSlack) SetNotificationsEnabled(channelName string, enabled bool) error

SetNotificationsEnabled sets a new notification status for a given channel name.

func (*SocketSlack) Start added in v0.14.0

func (b *SocketSlack) Start(ctx context.Context) error

Start starts the Slack WebSocket connection and listens for messages

func (*SocketSlack) Type added in v0.14.0

Type describes the notifier type.

type Status added in v1.5.0

type Status struct {
	Status   health.PlatformStatusMsg
	Restarts string
	Reason   health.FailureReasonMsg
}

type TeamsRenderer added in v1.0.0

type TeamsRenderer struct {
	// contains filtered or unexported fields
}

TeamsRenderer provides functionality to render MS Teams specific messages from a generic models.

func NewTeamsRenderer added in v1.0.0

func NewTeamsRenderer() *TeamsRenderer

NewTeamsRenderer return a new TeamsRenderer instance.

func (*TeamsRenderer) MessageToMarkdown added in v1.0.0

func (r *TeamsRenderer) MessageToMarkdown(in interactive.CoreMessage) string

MessageToMarkdown renders message in Markdown format.

func (*TeamsRenderer) NonInteractiveSectionToCard added in v1.0.0

func (r *TeamsRenderer) NonInteractiveSectionToCard(msg interactive.CoreMessage) (*cards.Card, error)

NonInteractiveSectionToCard returns AdaptiveCard for the given message. Note: It cannot be used for other messages as we take into account only first message section with limited primitives: - TextFields - BulletLists - Timestamp It should be removed once we will add support for a proper message renderer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL