-
Notifications
You must be signed in to change notification settings - Fork 513
Description
Go is very sensitive to boilerplate, especially when it comes to big initializations.
In telebot, we've long relied on helper functions and sendable structures to even out the boilerplate across the code and make it easy on the eyes. Unfortunately, none of them made it to the library... yet.
I propose we add a series of constructors (builders) for commonly used components, such as the inline and reply keyboards.
resp := bot.NewMarkup()
resp.Inline(resp.Row(
tele.Btn{Unique: "unique_1", Text: "Title", URL: url},
tele.Btn{Unique: "unique_2", Text: "Title 2", Data: uniqueData},
) /*, tele.Row... */)
// OR
resp.Reply(resp.Row(
tele.Btn{Text: "Title"},
tele.Btn{Text: "Title 2"},
tele.Btn{Text: "Title 3"},
) /*, resp.Row... */)
bot.Send(recipient, message, resp)Btn struct will implement all the methods of both InlineButton and ReplyButton.
Maybe, some further optimization could be done w.r.t. different button types and copies of the existent inline buttons with customized data. Reply markup could do the heavy-lifting here:
resp := bot.NewMarkup()
//var existingButton *tele.InlineButton
resp.Inline(resp.Row{
resp.Text(btnUnique, "Title"),
resp.URL("https://google.com"),
), resp.Row(
resp.Query("inline query", "Switch to"),
resp.Login(login, "Title"),
), resp.Row(
existingButton.With("custom data"),
))
// OR
resp.Reply(resp.Row(
resp.Contact("Title"),
resp.Location("Get geolocation"),
resp.Poll("Start poll"),
))The aforementioned changes are neither breaking nor something that can't be done within a single straightforward patch, but they will greatly simplify creating keyboard layouts where it's currently painful.
Cheers,
Ian