github tucnak/telebot v3.3.6
Telebot V3.3

20 days ago

Changelog

  • Bot API 6.6, 6.7, 6.8, 6.9, 7.0, 7.1
  • Implemented Boosts API support
  • Improved Stickers API support
  • Improved Album interaction
  • More of handy Context helpers
  • New telebot/react package with reaction bindings
  • Embedded FS support for telebot/layout
  • Lots of minor fixes and improvements

Bot API 6.6: Stickers

Unfortunately, due to breaking the Stickers API update on the Telegram side, we had to break the backward compatibility with previous versions of Telebot as well. However, this allowed us to rework the API and make it feel better and clearer to use.

// 1. UploadSticker now accepts the StickerSetFormat and File
b.UploadSticker(to, tele.StickerStatic, tele.FromDisk("telebot.png"))

// 2. CreateStickerSet now works with multiple stickers
b.CreateStickerSet(to, &tele.StickerInput{
  // ...
  Input: []tele.InputSticker{
    {File: tele.FromDisk("telebot1.png")},
    {File: tele.FromDisk("telebot2.png")},
  },
})

// 3. AddSticker is now called AddStickerToSet and accepts name and the InputSticker
b.AddStickerToSet(to, tele.InputSticker{
  File: tele.FromDisk("telebot.png"),
})

Bot API 7.0, 7.1

Boosts

// 1. Get a list of user boosts for a particular chat
boosts, err := b.UserBoosts(chat, user)
if err != nil {
  return err
}

// 2. Use boost fields
for _, boost := range boosts {
  boost.ID
  boost.AddDate()
  boost.ExpirationDate()
  ...
}

// 3. Handle boost-related events
b.Handle(tele.OnBoost, func(c tele.Context) error {
  boost := c.Boost()
  boost.Chat
  boost.Boost
  ...
})

Reactions

import (
  tele "gopkg.in/telebot.v3"
  "gopkg.in/telebot.v3/react"
)

// 1. Use a telebot/react package for the React shorthand
b.React(to, msg, react.React(react.ThumbUp, react.Fire))

// 2. Use ReactionOptions to add special options
b.React(to, msg, tele.ReactionOptions{
  Reactions: []tele.Reaction{react.Heart},
  Big:       true,
})

Multiple Message Actions

b.ForwardMany(to, msgs)
b.CopyMany(to, msgs)
b.DeleteMany(to, msgs)

Other Features

Check out the whole diff: #658

More shorthands

  • Use a new Trigger bot function to trigger the specific handler:
b.Handle("/start", func (c tele.Context) error {
  return c.Send("Hello, World!")
})

b.Handle("/help", func (c tele.Context) error {
  return b.Trigger("/start", c)
})
  • Finally, a SetCaption function to add a caption to the first media of the album:
var album tele.Album
// Populate album dynamically...
album.SetCaption("Hey, hey, hey!")

msgs, err := b.SendAlbum(user, album)
if err != nil {
  return err
}
  • Handy Context helpers to remove CallbackResponse from your code:
b.Handle(callback, func(c tele.Context) error {
  return c.RespondText("This is a pop-up!")
  // or ...
  return c.RespondAlert("This is an alert!")
})
  • Initialize a telebot/layout from the embedded FS:
import (
  "embed"

  tele "gopkg.in/telebot.v3"
  "gopkg.in/telebot.v3/layout"
)

//go:embed layout
var fs embed.FS

func main() {
  lt, err := layout.NewFromFS(fs, "bot.yml")
  if err != nil {
    panic(err)
  }

  b, err := tele.NewBot(lt.Settings())
  if err != nil {
    panic(err)
  }

 // Done!
}

Fixes and Improvements

  • New ErrIs function to check if the given description matches the error (71ac299)
  • Fixed stop channel race (#641)
  • Improved Context.Args parsing (#651)
  • Added missed types and fields (#647, #648)
  • Added more errors (#659)
  • Some *Chat arguments changed to Recipient (#568)
  • middleware.RecoverFunc now accepts the Context (a26ba9f)
  • !! Renamings (0d0d5e7, 32b47a4, 435ad60)

Discussion

Discuss on Telegram

Don't miss a new telebot release

NewReleases is sending notifications on new releases.