Telebot V3.1
Changelog
- Bot API 6.0, 6.1, 6.2
telebot/layout
improvements- Changed panic-recovering behavior
- Source restructure and refactoring
- Other minor fixes and improvements
Web apps support
Use the new OnWebApp
event along with the WebApp
buttons field to interact with the new stunning web app functionality.
webApp := &tele.WebApp{
URL: "https://mywebapp.com",
}
b.Handle("/start", func(c tele.Context) error {
markup := b.NewMarkup()
markup.Inline(markup.WebApp("Open", webApp))
return c.Send("Open this app!", markup)
})
b.Handle(tele.OnWebApp, func(c tele.Context) error {
webapp := c.Message().WebAppData
// Use the data fields:
// webapp.Data
// webapp.Text
}
New Recover
middleware
Be careful with allowing panics inside your handlers after the v3.0.1
release, since panics' recovering by default was removed. Instead, make sure you've added the Recover
middleware in case you really need it:
b.Use(middleware.Recover())
b.Use(middleware.Logger())
// ...
telebot/layout
improvements
- Use new
tele.M
alias in your layout calls instead ofmap[string]any
declaration:
lt.Text(c, "start", tele.M{...})
- The new
CommandsLocale
function for localized commands:
# bot.yml
commands:
/help: '{{ text `cmd_help` }}'
# en.yml
cmd_help: Show the help message
# fr.yml
cmd_help: Afficher le message d'aide
for _, locale := range lt.Locales() {
b.SetCommands(locale, lt.CommandsLocale(locale))
}
layout.Config
is now usingviper
under the hood
config:
tiers:
default: standard
all:
- name: standard
limit: 5
delay: 10m
- name: premium
limit: 50
delay: 1h
// Instead of an old sequential method,
defaultTier := lt.Get("tiers").String("default")
// you can use viper's dot notation:
defaultTier := lt.String("tiers.default")
// Some clumsy methods were removed,
// so instead of lt.Each and lt.Index use:
for _, tier := range lt.Slice("tiers.all") {
dur := tier.Duration("delay")
}
// You can also unmarshal any key directly:
var tiers []struct {
Name string
Limit int
Delay time.Duration
}
lt.UnmarshalKey("tiers.all", &tiers)
Backward incompatible changes
Unfortunately, some of them had a place in the v3.1.0
release and we can't guarantee compatibility through all the minor versions after this. The main reason for it is the fact that Telegram itself allows the breaking changes to appear in their API, however in some cases you can't help it, and breaking becomes inevitable. We break the contract beforehand so that you're previously ready for the future breaking Bot API update.
Some of the changes you should be aware of:
Bot.OnError
field won't be exposed, useSettings.OnError
instead once at initialization- Aforementioned panic-recovering behavior is optional
File.FileSize
changed theint
type to theint64
voice_chat_*
fields renamed tovideo_chat_*
*ChatJoinRequest
functions renamed to*JoinRequest
Fixes
- One minute is the default HTTP client timeout now (#478)
- Handled video response from
sendDocument
(#481) Message.Media()
includes missedSticker
type (#520)- Cancel
Raw()
execution on bot stop (#532) DeleteCommands
function is fixed (#533)- Fixed the order in which layout template's
Funcs
are applied (#546)