Documentation
¶
Index ¶
- Constants
- Variables
- type API
- type ApiAction
- type ApiConfig
- type ApiHandler
- type AssetsConfig
- type Bot
- type CallbackReply
- type CallbackTrigger
- type Check
- type Config
- type Context
- type DBConfig
- type Data
- type DataFetch
- type Edit
- type EditMessage
- type FileReply
- type Handler
- type InlineButton
- type Invoice
- type MessageReply
- type MessageTrigger
- type OptBool
- type OptUint64
- type ParseMode
- type PaymentProvider
- type PersistenceConfig
- type PersistenceType
- type PostCheckoutTrigger
- type PreCheckoutAnswer
- type PreCheckoutTrigger
- type Price
- type Reply
- type ReplyMarkup
- type Spec
- type State
- type StateCondition
- type StateUpdateOp
- type StateUpdateOpKind
- type Strings
- type TemplateStyle
- type Trigger
- type Validators
- type Webhook
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 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 OptUint64 `yaml:"chat-id"`
}
type ApiHandler ¶
type AssetsConfig ¶ added in v1.1.0
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 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 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 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 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 ¶
func (*MessageTrigger) UnmarshalYAML ¶
func (t *MessageTrigger) UnmarshalYAML(node *yaml.Node) error
type PaymentProvider ¶ added in v1.2.0
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 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.
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 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.
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"`
State []StateCondition `yaml:"state"`
}
Trigger is a handler trigger whcich configures when the handler should be executed.
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.
Click to show internal directories.
Click to hide internal directories.