Documentation ¶
Index ¶
- func AddFunc(key string, fn interface{})
- func AddFuncs(fm template.FuncMap)
- type Button
- type Config
- func (c *Config) Bool(k string) bool
- func (c *Config) ChatID(k string) tele.ChatID
- func (c *Config) Duration(k string) time.Duration
- func (c *Config) Each(k string, f func(int, *Config))
- func (c *Config) Float(k string) float64
- func (c *Config) Floats(k string) []float64
- func (c *Config) Get(k string) *Config
- func (c *Config) Index(k string, i int) *Config
- func (c *Config) Int(k string) int
- func (c *Config) Int64(k string) int64
- func (c *Config) Ints(k string) []int
- func (c *Config) Len(k string) int
- func (c *Config) String(k string) string
- func (c *Config) Strings(k string) []string
- func (c *Config) Unmarshal(v interface{}) error
- type Layout
- func (lt *Layout) Button(c tele.Context, k string, args ...interface{}) *tele.Btn
- func (lt *Layout) ButtonLocale(locale, k string, args ...interface{}) *tele.Btn
- func (lt *Layout) Callback(k string) tele.CallbackEndpoint
- func (lt *Layout) Locale(c tele.Context) (string, bool)
- func (lt *Layout) Markup(c tele.Context, k string, args ...interface{}) *tele.ReplyMarkup
- func (lt *Layout) MarkupLocale(locale, k string, args ...interface{}) *tele.ReplyMarkup
- func (lt *Layout) Middleware(defaultLocale string, localeFunc ...LocaleFunc) tele.MiddlewareFunc
- func (lt *Layout) SetLocale(c tele.Context, locale string)
- func (lt *Layout) Settings() tele.Settings
- func (lt *Layout) Text(c tele.Context, k string, args ...interface{}) string
- func (lt *Layout) TextLocale(locale, k string, args ...interface{}) string
- func (lt *Layout) UnmarshalYAML(data []byte) error
- type LocaleFunc
- type Markup
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents typed map interface related to the "config" section in layout.
func (*Config) Duration ¶
Duration returns a field casted to the time.Duration. Accepts number-represented duration or a string in 0nsuµmh format.
func (*Config) Get ¶
Get returns child map field wrapped into Config. If the field isn't a map, returns nil.
func (*Config) Index ¶
Index returns an i element from the array field, wrapped into Config. If the element isn't a map, returns nil. See also: Strings, Ints, Floats.
type Layout ¶
type Layout struct { *Config // contains filtered or unexported fields }
Layout provides an interface to interact with the layout, parsed from the config file and locales.
func (*Layout) Button ¶
Button returns a button, which locale is dependent on the context. The given optional argument will be passed to the template engine.
buttons: item: unique: item callback_data: {{.ID}} text: Item #{{.Number}}
Usage:
btns := make([]tele.Btn, len(items)) for i, item := range items { btns[i] = lt.Button(c, "item", struct { Number int Item Item }{ Number: i, Item: item, }) } m := b.NewMarkup() m.Inline(m.Row(btns...)) // Your generated markup is ready.
func (*Layout) ButtonLocale ¶
ButtonLocale returns a localised button processed with standard template engine. See Button for more details.
func (*Layout) Callback ¶
func (lt *Layout) Callback(k string) tele.CallbackEndpoint
Callback returns casted to CallbackEndpoint button, which mostly useful for handlers registering.
Example:
// Handling settings button b.Handle(lt.Callback("settings"), OnSettings)
func (*Layout) Markup ¶
Markup returns a markup, which locale is dependent on the context. The given optional argument will be passed to the template engine.
buttons: settings: 'Settings' markups: menu: - [settings]
Usage:
func OnStart(c tele.Context) error { return c.Send( lt.Text(c, "start"), lt.Markup(c, "menu")) }
func (*Layout) MarkupLocale ¶
func (lt *Layout) MarkupLocale(locale, k string, args ...interface{}) *tele.ReplyMarkup
MarkupLocale returns a localised markup processed with standard template engine. See Markup for more details.
func (*Layout) Middleware ¶
func (lt *Layout) Middleware(defaultLocale string, localeFunc ...LocaleFunc) tele.MiddlewareFunc
Middleware builds a global middleware to make internationalisation work.
Usage:
b.Use(lt.Middleware("en", func(r tele.Recipient) string { loc, _ := db.UserLocale(r.Recipient()) return loc }))
func (*Layout) Settings ¶
Settings returns built telebot Settings required for bot initialising.
settings: url: (custom url if needed) token: (not recommended) updates: (chan capacity) locales_dir: (optional) token_env: (token env var name, example: TOKEN) parse_mode: (default parse mode) long_poller: (long poller settings) webhook: (or webhook settings)
Usage:
lt, err := layout.New("bot.yml") b, err := tele.NewBot(lt.Settings()) // That's all!
func (*Layout) Text ¶
Text returns a text, which locale is dependent on the context. The given optional argument will be passed to the template engine.
Example of en.yml:
start: Hi, {{.FirstName}}!
Usage:
func OnStart(c tele.Context) error { return c.Send(lt.Text(c, "start", c.Sender())) }
func (*Layout) TextLocale ¶
TextLocale returns a localised text processed with standard template engine. See Text for more details.
func (*Layout) UnmarshalYAML ¶
type LocaleFunc ¶
LocaleFunc is the function used to fetch the locale of the recipient. Returned locale will be remembered and linked to the corresponding context.
type Markup ¶
type Markup struct { ResizeKeyboard *bool `json:"resize_keyboard,omitempty"` // nil == true ForceReply bool `json:"force_reply,omitempty"` OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` RemoveKeyboard bool `json:"remove_keyboard,omitempty"` Selective bool `json:"selective,omitempty"` // contains filtered or unexported fields }
Markup represents layout-specific markup to be parsed.