Use Reply and Inline Keyboards
v4Telebot supports Telegram's two keyboard types: Reply Keyboards (replacing the user's keyboard) and Inline Keyboards (attached to specific messages). Buttons can be used as endpoints for Handle() to trigger specific logic when pressed.
Reply Keyboards
Use tele.ReplyMarkup{ResizeKeyboard: true} to create a menu. You can add buttons using menu.Text(), menu.Contact(), menu.Location(), or menu.Poll().
Inline Keyboards
Use tele.ReplyMarkup{} (without ResizeKeyboard) for inline buttons. Common methods include:
Data(text, data, ...): Sends a callback to the bot. Ensure thedatais unique for routing.URL(text, url): Opens a web link.Query(text, query): Starts an inline query.QueryChat(text, query): Starts an inline query for a specific chat.Login(text, &tele.Login{...}): Initiates Telegram login.
Buttons can be organized into rows using menu.Row() or selector.Row().
var (
menu = &tele.ReplyMarkup{ResizeKeyboard: true}
selector = &tele.ReplyMarkup{}
// Reply buttons
btnHelp = menu.Text("ℹ Help")
btnSettings = menu.Text("⚙ Settings")
// Inline buttons
btnPrev = selector.Data("⬅", "prev")
btnNext = selector.Data("➡", "next")
)
// Construct the layouts
menu.Reply(
menu.Row(btnHelp),
menu.Row(btnSettings),
)
selector.Inline(
selector.Row(btnPrev, btnNext),
)
// Handling interactions
b.Handle("/start", func(c tele.Context) error {
return c.Send("Hello!", menu)
})
// On reply button pressed (message)
b.Handle(&btnHelp, func(c tele.Context) error {
return c.Edit("Here is some help: ...")
})
// On inline button pressed (callback)
b.Handle(&btnPrev, func(c tele.Context) error {
return c.Respond()
})