spec

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeMarkdown   = ParseMode("Markdown")
	ModeMarkdownV2 = ParseMode("MarkdownV2")
	ModeHTML       = ParseMode("HTML")
)

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 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 *ApiSendMesageAction `yaml:"send-message"`
}

type ApiArg

type ApiArg struct {
	Param string `yaml:"param"`
	Value string `yaml:"value"`
}

type ApiConfig

type ApiConfig struct {
	Address string `yaml:"address"`
}

type ApiHandler

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

type ApiSendMesageAction

type ApiSendMesageAction struct {
	Text *ApiArg `yaml:"text"`
}

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    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 Config

type Config struct {
	Api              *ApiConfig         `yaml:"api"`
	Persistence      *PersistenceConfig `yaml:"persistence"`
	Assets           *AssetsConfig      `yaml:"assets"`
	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 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"`
}

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"`
}

Handler specification declares bot handlers.

type ImageReply added in v1.1.0

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

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       `yaml:"text"`
	ParseMode ParseMode    `yaml:"parseMode"`
	Markup    *ReplyMarkup `yaml:"markup"`
}

type MessageTrigger

type MessageTrigger struct {
	Text    []string
	Command string
}

func (*MessageTrigger) UnmarshalYAML

func (t *MessageTrigger) 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     PersistenceType `yaml:"type"`
	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 int `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       *ImageReply        `yaml:"image"`
	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 []string          `yaml:"delete"`
}

State handler spec.

type Trigger

type Trigger struct {
	Message      *MessageTrigger      `yaml:"message"`
	Callback     *CallbackTrigger     `yaml:"callback"`
	Context      string               `yaml:"context"`
	PreCheckout  *PreCheckoutTrigger  `yaml:"preCheckout"`
	PostCheckout *PostCheckoutTrigger `yaml:"postCheckout"`
}

type Webhook

type Webhook struct {
	URL    *url.URL          `yaml:"url"`
	Method string            `yaml:"method"`
	Body   map[string]string `yaml:"body"`
}

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