templates

package
v0.9.3-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCommand is a template used to format the outputs from successfully
	// executed commands.
	DefaultCommand = `{{ text | monospace true }}{{ .Response.Out }}{{ endtext }}`

	// DefaultCommandError is a template used to format the error messages
	// produced by commands that return with a non-zero status.
	DefaultCommandError = `` /* 351-byte string literal not displayed */

	// DefaultMessage is a template used to format standard informative
	// (non-error) messages from the Gort system (not commands).
	DefaultMessage = `{{ text }}{{ .Response.Out }}{{ endtext }}`

	// DefaultMessageError is a template used to format error messages from the
	// Gort system (not commands).
	DefaultMessageError = `{{ header | color "#FF0000" | title .Response.Title }}
{{ text }}{{ .Response.Out }}{{ endtext }}`
)

Variables

This section is empty.

Functions

func FunctionMap

func FunctionMap() template.FuncMap

func Get

func Get(cmd data.BundleCommand, bundle data.Bundle, tt data.TemplateType) (string, error)

Get returns the first defined template found in the following sequence: 1. Command 2. Bundle 3. Config 4. Default

func Transform

func Transform(tmpl string, envelope data.CommandResponseEnvelope) (string, error)

Transforms template text + envelope, resulting in intermediate text that can be encoded into an OutputElements value.

Types

type Alt

type Alt struct {
	Tag
	Text string
}

Alt provides alternative text to be shown if other elements in a message cannot be rendered. Only the first instance of Alt will be shown.

func (*Alt) Alt

func (o *Alt) Alt() string

func (*Alt) String

func (o *Alt) String() string

type Divider

type Divider struct {
	Tag
}

func (*Divider) Alt

func (o *Divider) Alt() string

func (*Divider) String

func (o *Divider) String() string

type Functions

type Functions struct{}

func (*Functions) AltFunction

func (f *Functions) AltFunction(content string) *Alt

func (*Functions) DividerFunction

func (f *Functions) DividerFunction() *Divider

func (*Functions) HeaderColorFunction

func (f *Functions) HeaderColorFunction(s string, t *Header) (*Header, error)

func (*Functions) HeaderFunction

func (f *Functions) HeaderFunction() *Header

func (*Functions) ImageFunction

func (f *Functions) ImageFunction(url string) *Image

func (*Functions) ImageThumbnailunction

func (f *Functions) ImageThumbnailunction(b bool, i *Image) *Image

func (*Functions) MultipleTitleFunction

func (f *Functions) MultipleTitleFunction(s string, i interface{}) (interface{}, error)

func (*Functions) SectionEndFunction

func (f *Functions) SectionEndFunction() *SectionEnd

func (*Functions) SectionFunction

func (f *Functions) SectionFunction() *Section

func (*Functions) TextEmojiFunction

func (f *Functions) TextEmojiFunction(b bool, t *Text) *Text

func (*Functions) TextEndFunction

func (f *Functions) TextEndFunction() *TextEnd

func (*Functions) TextFunction

func (f *Functions) TextFunction() *Text

func (*Functions) TextInlineFunction

func (f *Functions) TextInlineFunction(b bool, t *Text) *Text

func (*Functions) TextMarkdownFunction

func (f *Functions) TextMarkdownFunction(b bool, t *Text) *Text

func (*Functions) TextMonospaceFunction

func (f *Functions) TextMonospaceFunction(b bool, t *Text) *Text

func (*Functions) UnimplementedFunction

func (f *Functions) UnimplementedFunction() *Unimplemented
type Header struct {
	Tag

	// Color must be expressed in RGB hex as "#123456"
	Color string `json:",omitempty"`

	Title string `json:",omitempty"`
}

func (*Header) Alt

func (o *Header) Alt() string

func (*Header) String

func (o *Header) String() string

type Image

type Image struct {
	Tag
	Height    int    `json:",omitempty"`
	Width     int    `json:",omitempty"`
	URL       string `json:",omitempty"`
	Thumbnail bool   `json:",omitempty"`
}

func (*Image) Alt

func (o *Image) Alt() string

func (*Image) String

func (o *Image) String() string

type OutputElement

type OutputElement interface {
	First() int
	Last() int
	String() string
}

type OutputElements

type OutputElements struct {
	// Color is the representation of the RGB color hex code. If defined, it
	// MUST adhere to the format "#RRGGBB". Optional.
	Color string

	// Title is the title of the message, if set. Optional.
	Title string

	// Elements includes the various message construction elements.
	Elements []OutputElement
}

func EncodeElements

func EncodeElements(text string) (OutputElements, error)

Encodes intermediate text generated by Transform into an OutputElements value that can be passed to an adapter.

func TransformAndEncode

func TransformAndEncode(tmpl string, envelope data.CommandResponseEnvelope) (OutputElements, error)

func (*OutputElements) Alt

func (o *OutputElements) Alt() string

Alt returns simplified text for this output. It will either return a concatenation of the text form for each element, separated by newlines, or the first Alt element.

type Section

type Section struct {
	Tag
	Text   *Text           `json:",omitempty"`
	Fields []OutputElement `json:",omitempty"`
}

func (*Section) Alt

func (o *Section) Alt() string

func (*Section) String

func (o *Section) String() string

type SectionEnd

type SectionEnd struct {
	Tag
}

func (*SectionEnd) Alt

func (o *SectionEnd) Alt() string

func (*SectionEnd) String

func (o *SectionEnd) String() string

type Tag

type Tag struct {
	FirstIndex int `json:"-"`
	LastIndex  int `json:"-"`
}

func (*Tag) First

func (t *Tag) First() int

func (*Tag) Last

func (t *Tag) Last() int

type Text

type Text struct {
	Tag
	Emoji     bool   `json:",omitempty"`
	Inline    bool   `json:",omitempty"`
	Markdown  bool   `json:",omitempty"`
	Monospace bool   `json:",omitempty"`
	Title     string `json:",omitempty"`
	Text      string `json:",omitempty"`
}

func (*Text) Alt

func (o *Text) Alt() string

func (*Text) String

func (o *Text) String() string

type TextEnd

type TextEnd struct {
	Tag
}

func (*TextEnd) Alt

func (o *TextEnd) Alt() string

func (*TextEnd) String

func (o *TextEnd) String() string

type Unimplemented

type Unimplemented struct {
	Tag
}

Unimplemented is an OutputElement that should not be implemented by any chat adapters. It may be used when testing to force a fallback to alt text.

func (*Unimplemented) String

func (o *Unimplemented) String() string

type WithAlt

type WithAlt interface {
	Alt() string
}

Jump to

Keyboard shortcuts

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