spec

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeMarkdown   = ParseMode("Markdown")
	ModeMarkdownV2 = ParseMode("MarkdownV2")
	ModeHTML       = ParseMode("HTML")
)
View Source
const (
	// TemplateDefault is default template style, uses interpolation of state variables.
	TemplateDefault = TemplateStyle("default")
	// TemplateGo uses go template engine.
	TemplateGo = TemplateStyle("go")
	// TemplateNo uses no template engine.
	TemplateNo = TemplateStyle("no")
)

Variables

View Source
var (
	ErrInvalidSpec      = errors.New("invalid configuration")
	ErrNoHandlersConfig = errors.New("no handlers configured")
)
View Source
var DefaultConfig = &Config{
	Persistence: &PersistenceConfig{
		Type: MemoryPersistence,
	},
	Assets: &AssetsConfig{
		Provider: "fs",
	},
}
View Source
var ErrEmptyTrigger = errors.New("empty trigger")

ErrEmptyTrigger is returned when no triggers are specified.

View Source
var ErrInvalidTriggerCombination = errors.New("invalid trigger combination")

ErrInvalidTriggerCombination is returned when trigger combination is invalid.

View Source
var ErrMultipleFallbacks = errors.New("multiple fallback handlers")
View Source
var ErrNoTriggerConfig = errors.New("no trigger configuration")
View Source
var ErrWebhookInvalidURL = errors.New("invalid URL")

Functions

This section is empty.

Types

type API

type API struct {
	Handlers []*ApiHandler `yaml:"handlers"`
}

type ApiAction

type ApiAction struct {
	SendMessage *MessageReply `yaml:"send-message"`
	ChatID      Uints64       `yaml:"chat-id"`
}

type ApiConfig

type ApiConfig struct {
	// Address is the address to listen on.
	Address string `yaml:"address"`
}

type ApiHandler

type ApiHandler struct {
	ID      string       `yaml:"id"`
	Actions []*ApiAction `yaml:"actions"`
}

type AssetsConfig added in v1.1.0

type AssetsConfig struct {
	Provider string            `yaml:"provider"`
	Params   map[string]string `yaml:"params"`
}

type Bot

type Bot struct {
	// Token is a Telegram bot token.
	Token    string            `yaml:"token" env:"BOT_TOKEN"`
	Config   *Config           `yaml:"config"`
	State    map[string]string `yaml:"state"`
	Debug    bool              `yaml:"debug"`
	Handlers []*Handler        `yaml:"handlers"`
	Api      *API              `yaml:"api"`
}

Bot spec includes bot configuration and handlers.

type CallbackReply

type CallbackReply struct {
	Text  string `yaml:"text"`
	Alert bool   `yaml:"alert"`
}

type CallbackTrigger

type CallbackTrigger struct {
	Data string
}

func (*CallbackTrigger) UnmarshalYAML

func (ct *CallbackTrigger) UnmarshalYAML(node *yaml.Node) error

type Check added in v1.10.0

type Check string

Check is a type for validator checks.

const (
	CheckNotEmpty Check = "not_empty"
	CheckIsInt    Check = "is_int"
	CheckIsFloat  Check = "is_float"
	CheckIsBool   Check = "is_bool"
)

type Config

type Config struct {
	// Api configuration specify API server parameters.
	Api *ApiConfig `yaml:"api"`
	// Persistence configuration specify persistence type and its parameters.
	Persistence *PersistenceConfig `yaml:"persistence"`
	// Assets configuration specify assets providers and its parameters.
	Assets *AssetsConfig `yaml:"assets"`
	// PaymentProviders is for payment providers tokens and parameters.
	PaymentProviders []PaymentProvider `yaml:"paymentProviders"`
}

type Context

type Context struct {
	Set    string `yaml:"set"`
	Delete string `yaml:"delete"`
}

type DBConfig

type DBConfig struct {
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Database string `yaml:"database"`
	NoSSL    bool   `yaml:"no_ssl"`
}

type Data added in v1.6.0

type Data struct {
	Fetch *DataFetch `yaml:"fetch"`
}

type DataFetch added in v1.6.0

type DataFetch struct {
	Method  string            `yaml:"method"`
	URL     string            `yaml:"url"`
	Headers map[string]string `yaml:"headers"`
}

type Edit added in v1.1.0

type Edit struct {
	Message *EditMessage `yaml:"message"`
}

type EditMessage added in v1.1.0

type EditMessage struct {
	Caption        string           `yaml:"caption"`
	Text           string           `yaml:"text"`
	InlineKeyboard [][]InlineButton `yaml:"inlineKeyboard"`
	Template       TemplateStyle    `yaml:"template"`
}

type FileReply added in v1.3.0

type FileReply struct {
	Name string `yaml:"name"`
	Key  string `yaml:"key"`
}

type Handler

type Handler struct {
	Trigger  *Trigger    `yaml:"on"`
	Replies  []*Reply    `yaml:"reply"`
	Webhook  *Webhook    `yaml:"webhook"`
	State    *State      `yaml:"state"`
	Context  *Context    `yaml:"context"`
	Data     *Data       `yaml:"data"`
	Validate *Validators `yaml:"validate"`
}

Handler specification declares bot handlers.

type InlineButton

type InlineButton struct {
	Text     string `yaml:"text"`
	URL      string `yaml:"url"`
	Callback string `yaml:"callback"`
}

type Invoice added in v1.2.0

type Invoice struct {
	// Provider is a payment provider name.
	Provider string `yaml:"provider"`
	// Title of the product
	Title string `yaml:"title"`
	// Description of the product
	Description string `yaml:"description"`
	// Unique bot deep-linking parameter that can be used to generate this invoice
	Payload string `yaml:"payload"`
	// Three-letter ISO 4217 currency code
	Currency string `yaml:"currency"`
	// Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
	Prices []Price `yaml:"prices"`
}

Invoice is a payment invoice.

type MessageReply

type MessageReply struct {
	Text      string
	ParseMode ParseMode
	Markup    *ReplyMarkup
	Template  TemplateStyle
}

func (*MessageReply) UnmarshalYAML added in v1.9.0

func (r *MessageReply) UnmarshalYAML(node *yaml.Node) error

type MessageTrigger

type MessageTrigger struct {
	Text    []string
	Command string
}

func (*MessageTrigger) UnmarshalYAML

func (t *MessageTrigger) UnmarshalYAML(node *yaml.Node) error

type OptBool added in v1.9.0

type OptBool struct {
	Value bool
	Valid bool
}

func (*OptBool) UnmarshalYAML added in v1.9.0

func (o *OptBool) UnmarshalYAML(node *yaml.Node) error

type OptUint64 added in v1.8.1

type OptUint64 struct {
	Value uint64
	Valid bool
}

OptUint64 is a uint64 that can be omitted in YAML.

func (*OptUint64) UnmarshalYAML added in v1.8.1

func (o *OptUint64) UnmarshalYAML(node *yaml.Node) error

type ParseMode

type ParseMode string

ParseMode of message reply

type PaymentProvider added in v1.2.0

type PaymentProvider struct {
	Name  string `yaml:"name"`
	Token string `yaml:"token"`
}

type PersistenceConfig

type PersistenceConfig struct {
	// Type is the type of persistence to use.
	Type PersistenceType `yaml:"type"`
	// DBConfig is the configuration for database persistence.
	DBConfig *DBConfig `yaml:"db_config"`
}

type PersistenceType

type PersistenceType string
const (
	MemoryPersistence   PersistenceType = "memory"
	DatabasePersistence PersistenceType = "database"
)

type PostCheckoutTrigger added in v1.2.0

type PostCheckoutTrigger struct {
	InvoicePayload string `yaml:"invoicePayload"`
}

type PreCheckoutAnswer added in v1.2.0

type PreCheckoutAnswer struct {
	Ok           bool   `yaml:"ok"`
	ErrorMessage string `yaml:"errorMessage"`
}

type PreCheckoutTrigger added in v1.2.0

type PreCheckoutTrigger struct {
	InvoicePayload string `yaml:"invoicePayload"`
}

type Price added in v1.2.0

type Price struct {
	// Label of the price
	Label string `yaml:"label"`
	// Price in the smallest units of the currency (integer, not float/double).
	Amount string `yaml:"amount"`
}

Price of the product

type Reply

type Reply struct {
	Message     *MessageReply      `yaml:"message"`
	Callback    *CallbackReply     `yaml:"callback"`
	Edit        *Edit              `yaml:"edit"`
	Delete      bool               `yaml:"delete"`
	Image       *FileReply         `yaml:"image"`
	Document    *FileReply         `yaml:"document"`
	Invoice     *Invoice           `yaml:"invoice"`
	PreCheckout *PreCheckoutAnswer `yaml:"preCheckout"`
}

type ReplyMarkup

type ReplyMarkup struct {
	Keyboard       [][]string       `yaml:"keyboard"`
	InlineKeyboard [][]InlineButton `yaml:"inlineKeyboard"`
}

type Spec

type Spec struct {
	Bot *Bot `yaml:"bot"`
}

Spec is a base struct for a bot specification file.

func ParseYaml

func ParseYaml(r io.Reader) (*Spec, error)

ParseYaml decodes YAML input into a Spec struct.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate specification.

type State

type State struct {
	Set    map[string]string `yaml:"set"`
	Delete Strings           `yaml:"delete"`
	Ops    []StateUpdateOp   `yaml:"ops"`
}

State handler spec.

type StateCondition added in v1.9.0

type StateCondition struct {
	Key     string  `yaml:"key"`
	Present OptBool `yaml:"present"`
	Eq      string  `yaml:"eq"`
	NEq     string  `yaml:"neq"`
}

type StateUpdateOp added in v1.10.0

type StateUpdateOp struct {
	Kind  StateUpdateOpKind `yaml:"kind"`
	Key   string            `yaml:"key"`
	Value string            `yaml:"value"`
}

StateUpdateOp is a state update operation.

type StateUpdateOpKind added in v1.10.0

type StateUpdateOpKind string

StateUpdateOpKind is a kind of state update operation.

const (
	StateUpdateOpKindSet    StateUpdateOpKind = "set"
	StateUpdateOpKindDelete StateUpdateOpKind = "delete"
	StateUpdateOpKindAdd    StateUpdateOpKind = "add"
	StateUpdateOpKindSub    StateUpdateOpKind = "sub"
	StateUpdateOpKindMul    StateUpdateOpKind = "mul"
	StateUpdateOpKindDiv    StateUpdateOpKind = "div"
)

type Strings added in v1.10.0

type Strings []string

Strings is a slice of strings that can be unmarshalled from YAML scalars or sequences.

func (*Strings) UnmarshalYAML added in v1.10.0

func (s *Strings) UnmarshalYAML(node *yaml.Node) error

type TemplateStyle added in v1.6.0

type TemplateStyle string

TemplateStyle of message text.

type Trigger

type Trigger struct {
	Message      *MessageTrigger
	Callback     *CallbackTrigger
	Context      string
	PreCheckout  *PreCheckoutTrigger
	PostCheckout *PostCheckoutTrigger
	State        []StateCondition
	Fallback     bool
}

Trigger is a handler trigger whcich configures when the handler should be executed.

func (*Trigger) Types added in v1.14.0

func (t *Trigger) Types() []TriggerType

Types returns a list of trigger types.

func (*Trigger) UnmarshalYAML added in v1.14.0

func (t *Trigger) UnmarshalYAML(node *yaml.Node) error

type TriggerType added in v1.14.0

type TriggerType int

TriggerType is a type of trigger.

const (
	TriggerTypeMessage TriggerType = 1 + iota
	TriggerTypeCallback
	TriggerTypeContext
	TriggerTypePreCheckout
	TriggerTypePostCheckout
	TriggerTypeState
	TriggerTypeFallback
)

Trigger types.

func (TriggerType) String added in v1.14.0

func (i TriggerType) String() string

type Uints64 added in v1.11.0

type Uints64 []uint64

Uints64 is a slice of uint64s that can be unmarshalled from YAML scalars or sequences.

func (*Uints64) UnmarshalYAML added in v1.11.0

func (u *Uints64) UnmarshalYAML(node *yaml.Node) error

type Validators added in v1.10.0

type Validators struct {
	// ErrorMessage is a message to send if validation fails.
	ErrorMessage string `yaml:"error_message"`
	// Checks is a list of checks to perform.
	Checks []Check `yaml:"checks"`
}

Validators is a struct for validator configuration.

type Webhook

type Webhook struct {
	URL     *url.URL          `yaml:"url"`
	Method  string            `yaml:"method"`
	Headers map[string]string `yaml:"headers"`
	Data    map[string]string `yaml:"data"`
}

func (*Webhook) UnmarshalYAML

func (ch *Webhook) UnmarshalYAML(node *yaml.Node) error

Jump to

Keyboard shortcuts

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