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 TriggerType
- type Uints64
- type Validators
- type Webhook
Constants ¶
const ( ModeMarkdown = ParseMode("Markdown") ModeMarkdownV2 = ParseMode("MarkdownV2") ModeHTML = ParseMode("HTML") )
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 ¶
var ( ErrInvalidSpec = errors.New("invalid configuration") ErrNoHandlersConfig = errors.New("no handlers configured") )
var DefaultConfig = &Config{ Persistence: &PersistenceConfig{ Type: MemoryPersistence, }, Assets: &AssetsConfig{ Provider: "fs", }, }
var ErrEmptyTrigger = errors.New("empty trigger")
ErrEmptyTrigger is returned when no triggers are specified.
var ErrInvalidTriggerCombination = errors.New("invalid trigger combination")
ErrInvalidTriggerCombination is returned when trigger combination is invalid.
var ErrMultipleFallbacks = errors.New("multiple fallback handlers")
var ErrNoTriggerConfig = errors.New("no trigger configuration")
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 AssetsConfig ¶ added in v1.1.0
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 CallbackTrigger ¶
type CallbackTrigger struct {
Data string
}
func (*CallbackTrigger) UnmarshalYAML ¶
func (ct *CallbackTrigger) UnmarshalYAML(node *yaml.Node) error
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 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 OptBool ¶ added in v1.9.0
func (*OptBool) UnmarshalYAML ¶ added in v1.9.0
type OptUint64 ¶ added in v1.8.1
OptUint64 is a uint64 that can be omitted in YAML.
func (*OptUint64) UnmarshalYAML ¶ added in v1.8.1
type PaymentProvider ¶ added in v1.2.0
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 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.
func (*Strings) UnmarshalYAML ¶ added in v1.10.0
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
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
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.