api

package
v1.16.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageBotNamePlaceholder is a cross-platform placeholder for bot name.
	MessageBotNamePlaceholder = "{{BotName}}"
)

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{

	MagicCookieKey:   "BOTKUBE",
	MagicCookieValue: "52ca7b74-28eb-4fac-ae79-31a9cbda2454",
}

HandshakeConfig is common handshake config between Botkube and its plugins.

Functions

func ConvertDependenciesFromAPI

func ConvertDependenciesFromAPI[T PluginDependencyURLsSetter[P], P any](in map[string]Dependency) map[string]T

ConvertDependenciesFromAPI converts API dependencies to source/executor plugin dependencies.

func ConvertDependenciesToAPI

func ConvertDependenciesToAPI[T PluginDependencyURLsGetter](resp map[string]T) map[string]Dependency

ConvertDependenciesToAPI converts source/executor plugin dependencies to API dependencies.

Types

type Base

type Base struct {
	Header      string `json:"header,omitempty" yaml:"header"`
	Description string `json:"description,omitempty" yaml:"description"`
	Body        Body   `json:"body,omitempty" yaml:"body"`
}

Base holds generic message fields.

func ReplaceBotNameInBase

func ReplaceBotNameInBase(base Base, name string) Base

ReplaceBotNameInBase replaces bot name placeholder with a given name.

type Body

type Body struct {
	CodeBlock string `json:"codeBlock,omitempty" yaml:"codeBlock"`
	Plaintext string `json:"plaintext,omitempty" yaml:"plaintext"`
}

Body holds message body fields.

func ReplaceBotNameInBody

func ReplaceBotNameInBody(body Body, name string) Body

ReplaceBotNameInBody replaces bot name placeholder with a given name.

type BotNameOption

type BotNameOption func(opts *BotNameOptions)

BotNameOption allows modifying ReplaceBotNamePlaceholder related options.

func BotNameWithClusterName

func BotNameWithClusterName(clusterName string) BotNameOption

BotNameWithClusterName sets the cluster name for places where MessageBotNamePlaceholder was also specified.

type BotNameOptions

type BotNameOptions struct {
	ClusterName string
}

BotNameOptions holds options used in ReplaceBotNamePlaceholder func

type BulletList

type BulletList struct {
	Title string   `json:"title,omitempty" yaml:"title"`
	Items []string `json:"items,omitempty" yaml:"items"`
}

BulletList defines a bullet list primitive.

type BulletLists

type BulletLists []BulletList

BulletLists holds the bullet lists.

func (BulletLists) AreItemsDefined

func (l BulletLists) AreItemsDefined() bool

AreItemsDefined returns true if at least one list has items defined.

type Button

type Button struct {
	Description string `json:"description,omitempty" yaml:"description"`

	// DescriptionStyle defines the style of the button description. If not provided, the default style (ButtonDescriptionStyleCode) is used.
	DescriptionStyle ButtonDescriptionStyle `json:"descriptionStyle" yaml:"descriptionStyle"`

	Name    string      `json:"name,omitempty" yaml:"name"`
	Command string      `json:"command,omitempty" yaml:"command"`
	URL     string      `json:"url,omitempty" yaml:"url"`
	Style   ButtonStyle `json:"style,omitempty" yaml:"style"`
}

Button holds definition of action button.

type ButtonBuilder

type ButtonBuilder struct{}

ButtonBuilder provides a simplified way to construct a Button model.

func NewMessageButtonBuilder

func NewMessageButtonBuilder() *ButtonBuilder

func (*ButtonBuilder) DescriptionURL

func (b *ButtonBuilder) DescriptionURL(name, cmd string, url string, style ...ButtonStyle) Button

DescriptionURL returns link button with description.

func (*ButtonBuilder) ForCommand

func (b *ButtonBuilder) ForCommand(name, cmd, desc string, style ...ButtonStyle) Button

ForCommand returns button command with description in adaptive code block.

For displaying description in bold, use ForCommandWithBoldDesc.

func (*ButtonBuilder) ForCommandWithBoldDesc

func (b *ButtonBuilder) ForCommandWithBoldDesc(name, desc, cmd string, style ...ButtonStyle) Button

ForCommandWithBoldDesc returns button command where description and command are different.

func (*ButtonBuilder) ForCommandWithDescCmd

func (b *ButtonBuilder) ForCommandWithDescCmd(name, cmd string, style ...ButtonStyle) Button

ForCommandWithDescCmd returns button command where description and command are the same.

func (*ButtonBuilder) ForCommandWithItalicDesc

func (b *ButtonBuilder) ForCommandWithItalicDesc(name, desc, cmd string, style ...ButtonStyle) Button

ForCommandWithItalicDesc returns button command where description and command are different and the description is italic.

func (*ButtonBuilder) ForCommandWithoutDesc

func (b *ButtonBuilder) ForCommandWithoutDesc(name, cmd string, style ...ButtonStyle) Button

ForCommandWithoutDesc returns button command without description.

func (*ButtonBuilder) ForURL

func (b *ButtonBuilder) ForURL(name, url string, style ...ButtonStyle) Button

ForURL returns link button.

func (*ButtonBuilder) ForURLWithBoldDesc

func (b *ButtonBuilder) ForURLWithBoldDesc(name, desc, url string, style ...ButtonStyle) Button

ForURLWithBoldDesc returns link button with description.

func (*ButtonBuilder) ForURLWithTextDesc

func (b *ButtonBuilder) ForURLWithTextDesc(name, desc, url string, style ...ButtonStyle) Button

ForURLWithBoldDesc returns link button with description.

type ButtonDescriptionStyle

type ButtonDescriptionStyle string

ButtonDescriptionStyle defines the style of the button description.

const (
	// ButtonDescriptionStyleBold defines the bold style for the button description.
	ButtonDescriptionStyleBold ButtonDescriptionStyle = "bold"

	// ButtonDescriptionStyleItalic defines the bold style for the button description.
	ButtonDescriptionStyleItalic ButtonDescriptionStyle = "italic"
	// ButtonDescriptionStyleText defines the plaintext style for the button description.
	ButtonDescriptionStyleText ButtonDescriptionStyle = "text"
	// ButtonDescriptionStyleCode defines the code style for the button description.
	ButtonDescriptionStyleCode ButtonDescriptionStyle = "code"
)

type ButtonStyle

type ButtonStyle string

ButtonStyle is a style of Button element.

const (
	ButtonStyleDefault ButtonStyle = ""
	ButtonStylePrimary ButtonStyle = "primary"
	ButtonStyleDanger  ButtonStyle = "danger"
)

Represents a general button styles.

type Buttons

type Buttons []Button

Buttons holds definition of interactive buttons.

func ReplaceBotNameInButtons

func ReplaceBotNameInButtons(btns Buttons, name string, opts BotNameOptions) Buttons

ReplaceBotNameInButtons replaces bot name placeholder with a given name.

func (*Buttons) GetButtonsWithDescription

func (s *Buttons) GetButtonsWithDescription() Buttons

GetButtonsWithDescription returns all buttons with description.

func (*Buttons) GetButtonsWithoutDescription

func (s *Buttons) GetButtonsWithoutDescription() Buttons

GetButtonsWithoutDescription returns all buttons without description.

type ContextItem

type ContextItem struct {
	Text string `json:"text,omitempty" yaml:"text"`
}

ContextItem holds context item.

type ContextItems

type ContextItems []ContextItem

ContextItems holds context items.

func ReplaceBotNameInContextItems

func ReplaceBotNameInContextItems(items ContextItems, name string) ContextItems

ReplaceBotNameInContextItems replaces bot name placeholder with a given name.

func (ContextItems) IsDefined

func (c ContextItems) IsDefined() bool

IsDefined returns true if there are any context items defined.

type Dependency

type Dependency struct {
	// URLs holds the URLs for a given dependency depending on the platform and architecture.
	URLs URLs `yaml:"urls"`
}

Dependency holds the dependency information.

type DispatchedInputAction

type DispatchedInputAction string

DispatchedInputAction defines when the action should be sent to our backend.

const (
	NoDispatchInputAction          DispatchedInputAction = ""
	DispatchInputActionOnEnter     DispatchedInputAction = "on_enter_pressed"
	DispatchInputActionOnCharacter DispatchedInputAction = "on_character_entered"
)

Defines the possible options to dispatch the input action.

type DividerStyle

type DividerStyle string

DividerStyle is a style of Divider element between section blocks.

const (
	// DividerStyleDefault put a block divider, like an <hr>, to split up different sections inside of a single message.
	// It is the default style for backwards compatibility.
	DividerStyleDefault DividerStyle = ""
	// DividerStyleTopNone
	DividerStyleTopNone DividerStyle = "none"
)

Represents a divider styles.

type ExternalRequestMetadata

type ExternalRequestMetadata struct {
	// Payload contains the external requests payload information.
	Payload ExternalRequestPayload
}

ExternalRequestMetadata contains the metadata for external requests.

type ExternalRequestPayload

type ExternalRequestPayload struct {
	// JSONSchema is a JSON schema for a given incoming webhook payload.
	JSONSchema JSONSchema
}

ExternalRequestPayload contains the incoming webhook payload information.

type JSONSchema

type JSONSchema struct {
	// Value is the JSON schema string.
	Value string
	// RefURL is the remote reference of the schema.
	RefURL string
}

JSONSchema contains the JSON schema or a remote reference where the schema can be found. Value and RefURL are mutually exclusive

type LabelInput

type LabelInput struct {
	Command          string                `json:"command,omitempty" yaml:"command"`
	Text             string                `json:"text,omitempty" yaml:"text"`
	Placeholder      string                `json:"placeholder,omitempty" yaml:"placeholder"`
	DispatchedAction DispatchedInputAction `json:"dispatchedAction,omitempty" yaml:"dispatchedAction"`
}

LabelInput is used to create input elements to use in messages.

type LabelInputs

type LabelInputs []LabelInput

LabelInputs holds the plain text input items.

func ReplaceBotNameInLabels

func ReplaceBotNameInLabels(labels LabelInputs, name string, opts BotNameOptions) LabelInputs

ReplaceBotNameInLabels replaces bot name placeholder with a given name.

type Message

type Message struct {
	Type              MessageType `json:"type,omitempty" yaml:"type"`
	BaseBody          Body        `json:"baseBody,omitempty" yaml:"baseBody"`
	Timestamp         time.Time   `json:"timestamp,omitempty" yaml:"timestamp"`
	Sections          []Section   `json:"sections,omitempty" yaml:"sections"`
	PlaintextInputs   LabelInputs `json:"plaintextInputs,omitempty" yaml:"plaintextInputs"`
	OnlyVisibleForYou bool        `json:"onlyVisibleForYou,omitempty" yaml:"onlyVisibleForYou"`
	ReplaceOriginal   bool        `json:"replaceOriginal,omitempty" yaml:"replaceOriginal"`
	UserHandle        string      `json:"userHandle,omitempty" yaml:"userHandle"`

	// ParentActivityID represents the originating message that started a thread. If set, message will be sent in that thread instead of the default one.
	ParentActivityID string `json:"parentActivityId,omitempty" yaml:"parentActivityId,omitempty"`
}

Message represents a generic message with interactive buttons.

func NewCodeBlockMessage

func NewCodeBlockMessage(msg string, allowBotkubeFilter bool) Message

NewCodeBlockMessage returns message in a Markdown code block format.

func NewPlaintextMessage

func NewPlaintextMessage(msg string, useBotkubeFilter bool) Message

NewPlaintextMessage returns message in a plaintext format.

func (*Message) HasBaseBody

func (msg *Message) HasBaseBody() bool

HasBaseBody returns true if message has base body defined.

func (*Message) HasInputs

func (msg *Message) HasInputs() bool

HasInputs returns true if message has interactive inputs.

func (*Message) HasSections

func (msg *Message) HasSections() bool

HasSections returns true if message has interactive sections.

func (*Message) IsEmpty

func (msg *Message) IsEmpty() bool

func (*Message) ReplaceBotNamePlaceholder

func (msg *Message) ReplaceBotNamePlaceholder(new string, opts ...BotNameOption)

ReplaceBotNamePlaceholder replaces bot name placeholder with a given name.

type MessageType

type MessageType string

MessageType defines the message type.

const (
	// DefaultMessage defines a message that should be displayed in default mode supported by communicator.
	DefaultMessage MessageType = ""
	// BasicCardWithButtonsInSeparateMessage defines a message that should be displayed in plaintext mode supported by the communicator,
	// with the buttons sent in a separate interactive message.
	// This feature is currently available only for the Teams platform.
	BasicCardWithButtonsInSeparateMsg = "basicCardWithButtonsInSeparateMessage"
	// BaseBodyWithFilterMessage defines a message that should be displayed in plaintext mode supported by communicator.
	// In this form the built-in filter is supported.
	// NOTE: only BaseBody is preserved. All other properties are ignored even if set.
	BaseBodyWithFilterMessage MessageType = "baseBodyWithFilter"
	// NonInteractiveSingleSection it is an indicator for non-interactive platforms, that they can render this event
	// even though they have limited capability. As a result, a given message has the following restriction:
	//  - the whole message should have exactly one section
	//  - section interactive elements such as buttons, select, multiselect, and inputs are ignored.
	//  - the base body of the message is ignored
	//  - Timestamp field is optional
	NonInteractiveSingleSection MessageType = "nonInteractiveEventSingleSection"
	// PopupMessage defines a message that should be displayed to the user as popup (if possible).
	PopupMessage MessageType = "form"
	// ThreadMessage defines a message that should be sent in a thread.
	ThreadMessage MessageType = "threadMessage"
	// SkipMessage defines a message that should not be sent to the end user.
	// If not used and message is empty, a special indicator will be sent as the response.
	SkipMessage MessageType = "skipMessage"
)

type MetadataOutput

type MetadataOutput struct {
	// Version is a version of a given plugin. It should follow the SemVer syntax.
	Version string
	// Descriptions is a description of a given plugin.
	Description string
	// URL to plugin documentation.
	DocumentationURL string
	// JSONSchema is a JSON schema for a given plugin configuration.
	JSONSchema JSONSchema

	// ExternalRequest holds the metadata for external requests.
	ExternalRequest ExternalRequestMetadata

	// Dependencies holds the dependencies for a given platform binary.
	Dependencies map[string]Dependency
	// Recommended plugin recommended
	Recommended bool
}

MetadataOutput contains the metadata of a given plugin.

func (MetadataOutput) Validate

func (m MetadataOutput) Validate() error

Validate validate the metadata fields and returns detected issues.

type MultiSelect

type MultiSelect struct {
	Name        string `json:"name,omitempty" yaml:"name"`
	Description Body   `json:"description,omitempty" yaml:"description"`
	Command     string `json:"command,omitempty" yaml:"command"`

	// Options holds all available options
	Options []OptionItem `json:"options,omitempty" yaml:"options"`

	// InitialOptions hold already pre-selected options. MUST be a sub-set of Options.
	InitialOptions []OptionItem `json:"initialOptions,omitempty" yaml:"initialOptions"`
}

MultiSelect holds multi select related fields.

func ReplaceBotNameInMultiSelect

func ReplaceBotNameInMultiSelect(ms MultiSelect, name string, opts BotNameOptions) MultiSelect

ReplaceBotNameInMultiSelect replaces bot name placeholder with a given name.

func (*MultiSelect) AreOptionsDefined

func (m *MultiSelect) AreOptionsDefined() bool

AreOptionsDefined returns true if some options are available.

type OptionGroup

type OptionGroup struct {
	Name    string       `json:"name,omitempty" yaml:"name"`
	Options []OptionItem `json:"options,omitempty" yaml:"options"`
}

OptionGroup holds information about options in the same group.

func ReplaceBotNameInOptionGroups

func ReplaceBotNameInOptionGroups(groups []OptionGroup, name string) []OptionGroup

ReplaceBotNameInOptionGroups replaces bot name placeholder with a given name.

type OptionItem

type OptionItem struct {
	Name  string `json:"name,omitempty" yaml:"name"`
	Value string `json:"value,omitempty" yaml:"value"`
}

OptionItem defines an option model.

func ReplaceBotNameInOptionItem

func ReplaceBotNameInOptionItem(item *OptionItem, name string) *OptionItem

ReplaceBotNameInOptionItem replaces bot name placeholder with a given name.

func ReplaceBotNameInOptions

func ReplaceBotNameInOptions(items []OptionItem, name string) []OptionItem

ReplaceBotNameInOptions replaces bot name placeholder with a given name.

type PluginDependencyURLsGetter

type PluginDependencyURLsGetter interface {
	GetUrls() map[string]string
}

PluginDependencyURLsGetter is an interface for getting plugin dependency URLs.

type PluginDependencyURLsSetter

type PluginDependencyURLsSetter[T any] interface {
	SetUrls(in map[string]string)
	*T // This is needed to ensure we can create an instance of the concrete type as a part of the ConvertDependenciesFromAPI function.
}

PluginDependencyURLsSetter is an interface for setting plugin dependency URLs.

type Section

type Section struct {
	Style SectionStyle `json:"style,omitempty" yaml:"style"`

	Base            `json:",inline" yaml:"base"`
	Buttons         Buttons      `json:"buttons,omitempty" yaml:"buttons"`
	MultiSelect     MultiSelect  `json:"multiSelect,omitempty" yaml:"multiSelect"`
	Selects         Selects      `json:"selects,omitempty" yaml:"selects"`
	PlaintextInputs LabelInputs  `json:"plaintextInputs,omitempty" yaml:"plaintextInputs"`
	TextFields      TextFields   `json:"textFields,omitempty" yaml:"textFields"`
	BulletLists     BulletLists  `json:"bulletLists,omitempty" yaml:"bulletLists"`
	Context         ContextItems `json:"context,omitempty" yaml:"context"`
}

Section holds section related fields.

type SectionStyle

type SectionStyle struct {
	Divider DividerStyle `json:"divider,omitempty" yaml:"dividerStyle"`
}

SectionStyle holds section style.

type Select

type Select struct {
	Type    SelectType `json:"type,omitempty" yaml:"type"`
	Name    string     `json:"name,omitempty" yaml:"name"`
	Command string     `json:"command,omitempty" yaml:"command"`
	// OptionGroups provides a way to group options in a select menu.
	OptionGroups []OptionGroup `json:"optionGroups,omitempty" yaml:"optionGroups"`
	// InitialOption holds already pre-selected options. MUST be a sub-set of OptionGroups.
	InitialOption *OptionItem `json:"initialOption,omitempty" yaml:"initialOption"`
}

Select holds data related to the select drop-down.

type SelectType

type SelectType string

SelectType is a type of Button element.

const (
	StaticSelect   SelectType = "static"
	ExternalSelect SelectType = "external"
)

Represents a select dropdown types.

type Selects

type Selects struct {
	// ID allows to identify a given block when we do the updated.
	ID    string   `json:"id,omitempty" yaml:"id"`
	Items []Select `json:"items,omitempty" yaml:"items"`
}

Selects holds multiple Select objects.

func ReplaceBotNameInSelects

func ReplaceBotNameInSelects(selects Selects, name string, opts BotNameOptions) Selects

ReplaceBotNameInSelects replaces bot name placeholder with a given name.

func (*Selects) AreOptionsDefined

func (s *Selects) AreOptionsDefined() bool

AreOptionsDefined returns true if some options are available.

type TextField

type TextField struct {
	Key   string `json:"key,omitempty" yaml:"key"`
	Value string `json:"value,omitempty" yaml:"value"`
}

TextField holds a text field data.

func (*TextField) IsEmpty

func (t *TextField) IsEmpty() bool

IsEmpty returns true if all fields have zero-value.

type TextFields

type TextFields []TextField

TextFields holds text field items.

func ReplaceBotNameInTextFields

func ReplaceBotNameInTextFields(fields TextFields, name string) TextFields

ReplaceBotNameInTextFields replaces bot name placeholder with a given name.

type URLs

type URLs map[string]string

URLs is a map of URLs for different platform and architecture. The key format is "{os}/{arch}".

func (URLs) For

func (u URLs) For(os, arch string) (string, bool)

For returns the URL for a given platform and architecture.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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