interactive

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const RunCommandName = "Run command"

RunCommandName defines the button name for the run commands.

Variables

This section is empty.

Functions

func MdHeaderFormatter

func MdHeaderFormatter(msg string) string

MdHeaderFormatter adds Markdown header formatting.

func MessageToPlaintext

func MessageToPlaintext(msg Message, newlineFormatter func(in string) string) string

MessageToPlaintext returns interactive message as a plaintext.

func NewlineFormatter

func NewlineFormatter(msg string) string

NewlineFormatter adds new line formatting.

func NoFormatting

func NoFormatting(msg string) string

NoFormatting does not apply any formatting.

func RenderMessage

func RenderMessage(mdFormatter MDFormatter, msg Message) string

RenderMessage returns interactive message as a plaintext with Markdown syntax.

Types

type Base

type Base struct {
	Header      string
	Description string
	Body        Body
}

Base holds generic message fields.

type Body

type Body struct {
	CodeBlock string
	Plaintext string
}

Body holds message body fields.

type Button

type Button struct {
	Description string
	Name        string
	Command     string
	URL         string
	Style       ButtonStyle
}

Button holds definition of action button.

type ButtonBuilder added in v0.15.0

type ButtonBuilder struct {
	BotName string
}

ButtonBuilder provides a simplified way to construct a Button model.

func (*ButtonBuilder) DescriptionURL added in v0.15.0

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

DescriptionURL returns link button with description.

func (*ButtonBuilder) ForCommand added in v0.15.0

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

ForCommand returns button command.

func (*ButtonBuilder) ForCommandWithDescCmd added in v0.15.0

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

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

func (*ButtonBuilder) ForCommandWithoutDesc added in v0.15.0

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

ForCommandWithoutDesc returns button command without description.

func (*ButtonBuilder) ForURL added in v0.15.0

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

ForURL returns link button.

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 (*Buttons) AtLeastOneButtonHasDescription

func (s *Buttons) AtLeastOneButtonHasDescription() bool

AtLeastOneButtonHasDescription returns true if there is at least one button with description associated with it.

func (*Buttons) ReplaceBotNameInCommands added in v0.16.0

func (s *Buttons) ReplaceBotNameInCommands(old, new string)

ReplaceBotNameInCommands replaces bot name in commands.

type ContextItem added in v0.15.0

type ContextItem struct {
	Text string
}

ContextItem holds context item.

type ContextItems added in v0.15.0

type ContextItems []ContextItem

ContextItems holds context items.

func (ContextItems) IsDefined added in v0.15.0

func (c ContextItems) IsDefined() bool

IsDefined returns true if there are any context items defined.

type DispatchedInputAction added in v0.15.0

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 GenericMessage added in v0.16.0

type GenericMessage interface {
	ForBot(botName string) Message
}

GenericMessage returns a message which has customized content. For example, it returns a message with customized commands based on bot name.

type HelpMessage added in v0.15.0

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

HelpMessage provides an option to build the Help message depending on a given platform.

func NewHelpMessage added in v0.15.0

func NewHelpMessage(platform config.CommPlatformIntegration, clusterName, botName string) *HelpMessage

NewHelpMessage return a new instance of HelpMessage.

func (*HelpMessage) Build added in v0.15.0

func (h *HelpMessage) Build() Message

Build returns help message with interactive sections.

type LabelInput added in v0.15.0

type LabelInput struct {
	Command          string
	Text             string
	Placeholder      string
	DispatchedAction DispatchedInputAction
}

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

type LabelInputs added in v0.15.0

type LabelInputs []LabelInput

LabelInputs holds the plain text input items.

func (*LabelInputs) ReplaceBotNameInCommands added in v0.16.0

func (l *LabelInputs) ReplaceBotNameInCommands(old, new string)

ReplaceBotNameInCommands replaces bot name in commands.

type MDFormatter

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

MDFormatter represents the capability of Markdown Formatter

func DefaultMDFormatter

func DefaultMDFormatter() MDFormatter

DefaultMDFormatter is for initializing built-in Markdown formatter

func NewMDFormatter

func NewMDFormatter(newlineFormatter, headerFormatter func(msg string) string) MDFormatter

NewMDFormatter is for initializing custom Markdown formatter

type Message

type Message struct {
	Type MessageType
	Base
	Sections          []Section
	PlaintextInputs   LabelInputs
	OnlyVisibleForYou bool
	ReplaceOriginal   bool
}

Message represents a generic message with interactive buttons.

func Feedback

func Feedback() Message

Feedback generates Message structure.

func (*Message) HasInputs added in v0.15.0

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) ReplaceBotNameInCommands added in v0.16.0

func (msg *Message) ReplaceBotNameInCommands(old, new string)

ReplaceBotNameInCommands replaces bot name in commands.

type MessageType

type MessageType string

MessageType defines the message type.

const (
	// Default defines a message that should be displayed in default mode supported by communicator.
	Default MessageType = ""
	// Popup defines a message that should be displayed to the user as popup (if possible).
	Popup MessageType = "form"
)

type MultiSelect

type MultiSelect struct {
	Name        string
	Description Body
	Command     string

	// Options holds all available options
	Options []OptionItem

	// InitialOptions hold already pre-selected options. MUST be a sub-set of Options.
	InitialOptions []OptionItem
}

MultiSelect holds multi select related fields.

func (*MultiSelect) AreOptionsDefined

func (m *MultiSelect) AreOptionsDefined() bool

AreOptionsDefined returns true if some options are available.

func (*MultiSelect) ReplaceBotNameInCommands added in v0.16.0

func (m *MultiSelect) ReplaceBotNameInCommands(old, new string)

ReplaceBotNameInCommands replaces bot name in commands.

type OptionGroup added in v0.15.0

type OptionGroup struct {
	Name    string
	Options []OptionItem
}

OptionGroup holds information about options in the same group.

type OptionItem

type OptionItem struct {
	Name  string
	Value string
}

OptionItem defines an option model.

type Section

type Section struct {
	Base
	Buttons         Buttons
	MultiSelect     MultiSelect
	Selects         Selects
	PlaintextInputs LabelInputs
	TextFields      TextFields
	Context         ContextItems
}

Section holds section related fields.

func EventCommandsSection added in v0.15.0

func EventCommandsSection(cmdPrefix string, optionItems []OptionItem) Section

EventCommandsSection defines a structure of commands for a given event.

type Select added in v0.15.0

type Select struct {
	Type    SelectType
	Name    string
	Command string
	// OptionGroups provides a way to group options in a select menu.
	OptionGroups []OptionGroup
	// InitialOption holds already pre-selected options. MUST be a sub-set of OptionGroups.
	InitialOption *OptionItem
}

Select holds data related to the select drop-down.

type SelectType added in v0.15.0

type SelectType string

SelectType is a type of Button element.

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

Represents a select dropdown types.

type Selects added in v0.15.0

type Selects struct {
	// ID allows to identify a given block when we do the updated.
	ID    string
	Items []Select
}

Selects holds multiple Select objects.

func (*Selects) AreOptionsDefined added in v0.15.0

func (s *Selects) AreOptionsDefined() bool

AreOptionsDefined returns true if some options are available.

func (*Selects) ReplaceBotNameInCommands added in v0.16.0

func (s *Selects) ReplaceBotNameInCommands(old, new string)

ReplaceBotNameInCommands replaces bot name in commands.

type TextField added in v0.15.0

type TextField struct {
	Text string
}

TextField holds a text field data.

type TextFields added in v0.15.0

type TextFields []TextField

TextFields holds text field items.

Jump to

Keyboard shortcuts

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