Repository navigation
Telebot V3.4
Changelog
- Bot API 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8
- Telegram Business support
- Payments in Telegram Stars and paid media
- New
APIinterface, implemented by*Bot - New
OnForwardevent - Reactions reworked to match the Bot API
- Lots of minor fixes and improvements
V3.4 only ever got beta tags (v3.4.0-beta to v3.4.2-beta) and somehow never got its release page, so here it is, a little late, for the sake of history. Everything below is part of V4 as well.
Bot API 7.2: Business accounts
Bots can now be connected to Telegram Business accounts and handle the messages of their chats.
// 1. Handle the messages of the connected business accounts
b.Handle(tele.OnBusinessMessage, func(c tele.Context) error {
msg := c.Message()
// 2. Get the connection the message came through
conn, err := c.Bot().BusinessConnection(msg.BusinessConnectionID)
if err != nil {
return err
}
conn.Sender
conn.CanReply
...
})
// 3. Or track the connections themselves
b.Handle(tele.OnBusinessConnection, ...)
b.Handle(tele.OnEditedBusinessMessage, ...)
b.Handle(tele.OnDeletedBusinessMessages, ...)Bot API 7.4, 7.6: Telegram Stars
Digital goods can be paid for in Telegram Stars, no payment provider needed. Use the tele.Stars currency and leave the token empty:
// 1. Send an invoice in Stars
b.Handle("/buy", func(c tele.Context) error {
return c.Send(&tele.Invoice{
Title: "Premium",
Description: "One month of premium",
Payload: "premium-1m",
Currency: tele.Stars,
Prices: []tele.Price{{Label: "Premium", Amount: 100}},
})
})
// 2. Handle the successful payment, and refund it if you need to
b.Handle(tele.OnPayment, func(c tele.Context) error {
payment := c.Payment()
return c.Bot().RefundStars(c.Sender(), payment.TelegramChargeID)
})
// 3. Look through the bot's transactions
txs, err := b.StarTransactions(0, 100)Photos and videos can be sold for Stars too:
b.SendPaid(user, 50, tele.PaidAlbum{
&tele.Photo{File: tele.FromDisk("teaser.jpg"), Caption: "Unlock the full set"},
&tele.Video{File: tele.FromDisk("making-of.mp4")},
})API interface
Every bot method is now described by the tele.API interface, which makes it easy to wrap the bot or replace it with a mock in tests. Context.Bot() returns it as well:
var api tele.API = b
b.Handle("/start", func(c tele.Context) error {
return c.Bot().SetMyName("Telebot", "en")
})Reactions
Reactions now carry their type, which Telegram requires, and custom emoji reactions work as expected. ReactionOptions was folded into Reactions:
// 1. The telebot/react shorthand works as before
b.React(to, msg, react.React(react.ThumbUp, react.Fire))
// 2. Pass the Reactions directly for the special options
b.React(to, msg, tele.Reactions{
Reactions: []tele.Reaction{react.Heart},
Big: true,
})More shorthands
- Handle forwarded messages with the new
OnForwardevent (#697):
b.Handle(tele.OnForward, func(c tele.Context) error {
return c.Reply("Thanks for sharing!")
})- Manage the webhook yourself and keep telebot from calling
setWebhookon start:
b, err := tele.NewBot(tele.Settings{
Token: token,
Poller: &tele.Webhook{
Listen: ":8080",
IgnoreSetWebhook: true,
},
})- Pass a nil user to
SetMenuButtonto change the default menu button for all chats.
Backward incompatible changes
Some of the Bot API updates renamed or removed fields, and we followed them:
b.Reacttakestele.Reactionsinstead of...ReactionOptionsContext.Bot()returnstele.APIinstead of*tele.BotMessageReactionCount.Reactionsis a sliceStickerSet.AnimatedandStickerSet.Videoare removed, since sticker sets can mix formats nowRecipientShared.UserIDis replaced byRecipientShared.UsersMessage.ExternalReplyInfoisMessage.ExternalReply, andMessage.SenderBoostCountisMessage.SenderBoosts- Custom emoji fields end with
IDnow:Sticker.CustomEmojiID,Reaction.CustomEmojiID,MessageEntity.CustomEmojiID,Topic.IconCustomEmojiID,Chat.StatusCustomEmojiID,Chat.BackgroundCustomEmojiIDand others
Fixes
- Spoilers are sent as
has_spoiler(#690) - Inline buttons support
callback_gameandpay(#680) - Reactions carry their required
type(#716) MessageReactionCountis decoded correctly- A photo's caption is kept when unmarshalling
QueryResponseButton.Startis omitted when emptylayout.Newresolves relative paths again